Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats storages and crash in Aggregate mode #421

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tuancoltech
Copy link
Collaborator

🚀 Summary

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

@@ -7,7 +7,6 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission
android:requiredFeature="@string/ark_file_picker_pick"
Copy link
Collaborator 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
Copy link
Member

kirillt commented Dec 15, 2023

ARK-Builders/arklib-android#125 merged

@kirillt
Copy link
Member

kirillt commented Dec 19, 2023

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

@tuancoltech
Copy link
Collaborator 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
Copy link
Member

kirillt commented Dec 20, 2023

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

Copy link

sonarcloud bot commented Dec 20, 2023

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
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
Copy link
Member

kirillt commented Dec 20, 2023

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
Copy link
Member

kirillt commented Dec 20, 2023

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
Copy link
Member

mdrlzy commented Dec 27, 2023

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
Copy link
Member

kirillt commented Dec 28, 2023

@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
Copy link
Member

kirillt commented Jan 22, 2024

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

@tuancoltech
Copy link
Collaborator Author

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

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

@kirillt
Copy link
Member

kirillt commented Jan 24, 2024

@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