-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Accounts ProxyDb has authoritative/secondary DB (#3975)
# Motivation The `ProxyDb` acts as an intermediary during a migration, keeping data in the main database up to date until a second database is ready. The implementation is however currently partial and does not store the main and secondary db. # Changes - This PR fills out the contents of the ProxyDB struct so that we now actually have these two databases. # Tests - Existing CI should suffice # Todos - [ ] Add entry to changelog (if necessary).
- Loading branch information
Showing
2 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
rs/backend/src/accounts_store/schema/proxy/enum_boilerplate.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Boilerplate for implementing traits for the AccountsDb enum. | ||
//! | ||
//! Each function is implemented by calling the same function on the applicable variant. There is probably a macro for this. | ||
use super::*; | ||
|
||
impl AccountsDbBTreeMapTrait for AccountsDb { | ||
fn as_map(&self) -> &BTreeMap<Vec<u8>, Account> { | ||
match self { | ||
AccountsDb::Map(map_db) => map_db.as_map(), | ||
} | ||
} | ||
fn from_map(map: BTreeMap<Vec<u8>, Account>) -> Self { | ||
AccountsDb::Map(AccountsDbAsMap::from_map(map)) | ||
} | ||
} | ||
|
||
// TODO: This is boilerplate. can it be eliminated with a macro? | ||
impl AccountsDbTrait for AccountsDb { | ||
fn schema_label(&self) -> SchemaLabel { | ||
match &self { | ||
AccountsDb::Map(map_db) => map_db.schema_label(), | ||
} | ||
} | ||
fn db_insert_account(&mut self, account_key: &[u8], account: Account) { | ||
match self { | ||
AccountsDb::Map(map_db) => map_db.db_insert_account(account_key, account), | ||
} | ||
} | ||
fn db_contains_account(&self, account_key: &[u8]) -> bool { | ||
match self { | ||
AccountsDb::Map(map_db) => map_db.db_contains_account(account_key), | ||
} | ||
} | ||
fn db_get_account(&self, account_key: &[u8]) -> Option<Account> { | ||
match self { | ||
AccountsDb::Map(map_db) => map_db.db_get_account(account_key), | ||
} | ||
} | ||
fn db_remove_account(&mut self, account_key: &[u8]) { | ||
match self { | ||
AccountsDb::Map(map_db) => map_db.db_remove_account(account_key), | ||
} | ||
} | ||
fn db_accounts_len(&self) -> u64 { | ||
match self { | ||
AccountsDb::Map(map_db) => map_db.db_accounts_len(), | ||
} | ||
} | ||
fn iter(&self) -> Box<dyn Iterator<Item = (Vec<u8>, Account)> + '_> { | ||
match self { | ||
AccountsDb::Map(map_db) => map_db.iter(), | ||
} | ||
} | ||
} |