Skip to content

Stats storages and crash in Aggregate mode#421

Open
tuancoltech wants to merge 1 commit into
mainfrom
bug/pdf_preview_generator_crash
Open

Stats storages and crash in Aggregate mode#421
tuancoltech wants to merge 1 commit into
mainfrom
bug/pdf_preview_generator_crash

Conversation

@tuancoltech

Copy link
Copy Markdown
Contributor

🚀 Summary

Fix crash in Android Navigator, Aggregation mode.
Issue: #412

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission
android:requiredFeature="@string/ark_file_picker_pick"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for fixing a side effect when files access permission toggle was disabled, caused by this commit: c7d14c1

@tuancoltech tuancoltech changed the title WIP: [bug] Fix crash in Android Navigator Aggregate mode. [bug] Fix crash in Android Navigator Aggregate mode. Dec 14, 2023
hieuwu
hieuwu previously approved these changes Dec 14, 2023
@kirillt

kirillt commented Dec 15, 2023

Copy link
Copy Markdown
Member

ARK-Builders/arklib-android#125 merged

@kirillt

kirillt commented Dec 19, 2023

Copy link
Copy Markdown
Member

@tuancoltech am I right that we only need to bump arklib-android version before merging?

@tuancoltech

Copy link
Copy Markdown
Contributor Author

@tuancoltech am I right that we only need to bump arklib-android version before merging?

@kirillt This PR doesn't depend on any change in arklib-android, so please feel free to merge it :)

@kirillt

kirillt commented Dec 20, 2023

Copy link
Copy Markdown
Member

@tuancoltech there are some unresolved references in the last build.

@tuancoltech tuancoltech force-pushed the bug/pdf_preview_generator_crash branch from bb848c7 to 4064abb Compare December 20, 2023 16:38
@sonarqubecloud

Copy link
Copy Markdown

kirillt
kirillt previously approved these changes Dec 20, 2023
@kirillt kirillt dismissed their stale review December 20, 2023 19:31

Incomplete fix

storage.inputStream()
)
tagLabeledAmount.putAll(json.data)
} catch (exception: Exception) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that just logging the exception can be harmful for the storage. We can have 2 kinds of exception here:

  1. Exception during decoding the storage, i.e. reading from disk.
  2. An unlikely problem during putAll.

In either case, the tagLabeledAmount mapping is incorrect. When new stats appear, the will be written to the disk, but only part of the original storage will be written. E.g. if we have 5 entries in the storage, we read 2 of them and then we have an exception. We continue execution with 2/5 entries. Then new entry is coming, so we write 3/6 to the disk. This means we lose some entries in case of the exception.

Stats storage is not that important comparing to tags or scores, but it enhances UX by sorting tags in last-used order. We should avoid losing this data if possible.

@kirillt

kirillt commented Dec 20, 2023

Copy link
Copy Markdown
Member

Another concern is that the fix is applied to TagLabeledNStorage, but there are also 3 other similar storages: TagLabeledTSStorage.kt, TagQueriedTSStorage, TagQueriedNStorage. These storages have the same bug, they should be fixed, too.

@kirillt

kirillt commented Dec 20, 2023

Copy link
Copy Markdown
Member

But the best approach would be to re-design stats storages... They were implemented during autumn 2022. At summer 2023, we've refactored storages completely and separated reusable primitives. See FileStorage and FolderStorage from arklib-android.

In fact, the data stored in stats storages is very simple key-value mapping. I think, it's possible to implement them similarly to ScoreStorage. Scores storage is id-to-integer mapping, and stats storages are either tag-to-integer or tag-to-timestamp. But in any case, the code will be very similar to scores storage.

@kirillt kirillt dismissed hieuwu’s stale review December 20, 2023 19:50

Better design possible

@kirillt kirillt changed the title [bug] Fix crash in Android Navigator Aggregate mode. Stats storages and crash in Aggregate mode Dec 21, 2023
@mdrlzy

mdrlzy commented Dec 27, 2023

Copy link
Copy Markdown
Contributor

I think, it's possible to implement them similarly to ScoreStorage

They are not quite like ScoreStorage. They can often receive new events (once per second), which will provoke overwriting of large file (there is only one for the entire root). Here we need to implement a new storage, which will have a debounce flush to disk for new entries.

I think there is no point in fixing them here; it’s better to move and refactor in arklib-android.

@kirillt

kirillt commented Dec 28, 2023

Copy link
Copy Markdown
Member

@mdrlzy good note about debouncing. We can implement such a parameter in our base storage classes. Then stats storage should be similar to score storage, just debounce parameter would differ.

@kirillt

kirillt commented Jan 22, 2024

Copy link
Copy Markdown
Member

@tuancoltech let me know if you need help with implementing StatsStorage

@tuancoltech

Copy link
Copy Markdown
Contributor Author

@tuancoltech let me know if you need help with implementing StatsStorage

@kirillt Sure, I'll ask here in the case.

@kirillt

kirillt commented Jan 24, 2024

Copy link
Copy Markdown
Member

@tuancoltech We might need small refactoring in arklib-android because BaseStorage hard-codes ResourceId as the type acceptable as keys of a storage. In case of tag stats, keys belong to the String type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants