ARK-Builders/ark-core

`fs-storage`: Implement storages in Rust

Opened this issue · 4 comments

Right now, we have storages implemented in Kotlin. It would be great to move them from arklib-android repo to arklib and implement them in Rust. Then, we'll replace Kotlin code with JNI bindings to Rust code.

The original storages implementation is here. Any storage is just a KV-table. Usually, from with ResourceId as type for keys.

The original implementation contains also "sync with disk" functionality. We should carefully plan this feature. Probably, it should be separated from storages into merge strategy for atomic files

  • Skip the Monoid abstraction for this moment.
  • Skip AggregatedStorage class for this moment.
  • FileStorage for keeping the table in a single file
  • FolderStorage for keeping the values in separate files
  • ChunkedStorage as hybrid between the two, multiple files where each file contains several entries from the table
  • What exactly should we version using atomic files? Each value, each chunk or the whole table only?

@twitu as soon as the simplest FileStorage abstraction is ready, we can start using it in particular implementations like TagStorage and ScoreStorage and build Tauri components on top of them.

Added FileStorage struct with same functionality as Kotlin implementation in #2

  • Read data from file into a mapping from ResourceId to value
  • Write data mapping from ResourceId to value to file
  • Verify file version
  • Delete file when dropped

The next step is to implement specific implementations for TagStorage and ScoreStorage. After looking at the implementations for tags and score it's clear that they are aliases for Int and String or Sets of String. These can be written to a file by the generic FileStorage implementation.

However, the android implementation assumes that the keys are resource ids. The FileStorage can write any key that can be converted to a string. So for the specialized implementation where will the keys come from?

We have the FolderStorage left to implement, ChunkedStorage will be done sometime in the future.