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

IndexedDB-based Fedimint Database Implementation #31

Open
elsirion opened this issue Sep 12, 2023 · 2 comments
Open

IndexedDB-based Fedimint Database Implementation #31

elsirion opened this issue Sep 12, 2023 · 2 comments

Comments

@elsirion
Copy link
Owner

elsirion commented Sep 12, 2023

Unfortunately IndexedDB's transaction abstraction is absolutely unusable for our purposes. The core problem is that IndexedDB transactions cannot span across await points. We can atomically write multiple values, but these writes cannot be intertwined with e.g. network requests, which Fedimint often does. This means, if we want an efficient DB for the web runtime we need to implement a transaction overlay.

Fedimint requires snapshot isolation with optimistic transactions, one possible design I wrote about elsewhere:

I think a possible way of implementing our level of isolation (I think it was snapshot isolation that we expect?) by:

  • Saving each value together with its "generation". The global DB generation is defined as the max of all value generations.
  • Having an index of all ongoing transactions and their start DB generation
  • On commit of transactions with writes written KV pairs are updated and their generation set to DB generation + 1. If there are other transactions active the old KV pairs are written to a generation cache (together with their original generation).
  • Whenever a transaction finishes (commit/abort) the generation cache is cleaned of all entries older than the minimum generation of all ongoing transactions
  • When reading from a key in a transaction:
    1. Check the local transaction log for writes to the key
    2. Check the generation cache
    3. Read directly from the IndexedDB
  • Commits are conflict-free if:
    • All reads before the last write read values with a generation at commit time <= the transaction generation
    • All writes write to values with a generation at commit time <= the transaction generation (deleted item generations have to be kept I guess to notice conflicts)
  • Commits can use IndexedDB transactions for atomicity since the reads/writes all happen without other tasks in between.
@elsirion
Copy link
Owner Author

elsirion commented Nov 11, 2023

Closed by #33. It's not the same, but good enough for now.

@elsirion
Copy link
Owner Author

Re-opening since MemDatabase is quite broken fedimint/fedimint#3988

@elsirion elsirion reopened this Dec 22, 2023
@elsirion elsirion changed the title IndexedDB-based database implementation IndexedDB-based Fedimint Database Implementation Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant