Skip to content

Latest commit

History

28 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Rockbound

This package is a low-level wrapper transforming RocksDB from a byte-oriented key value store into a type-oriented store. It's adapted from a similar package in Aptos-Core.

The most important concept exposed by Rockbound is a Schema, which maps a column-family name codec's for the key and value.

pubtraitSchema{/// The column family name associated with this struct./// Note: all schemas within the same DB must have distinct column family names.constCOLUMN_FAMILY_NAME:&'staticstr;/// Type of the key.typeKey:KeyCodec<Self>;/// Type of the value.typeValue:ValueCodec<Self>;}

Using this schema, we can write generic functions for storing and fetching typed data, and ensure that it's always encoded/decoded in the way we expect.

implSchemaDB{pubfnput<S:Schema>(&self,key:&implKeyCodec<S>,value:&implValueCodec<S>) -> Result<()>{let key_bytes = key.encode_key()?;let value_bytes = value.encode_value()?;self.rocks_db_handle.put(S::COLUMN_FAMILY_NAME, key_bytes, value_bytes)}}

To actually store and retrieve data, all we need to do is to implement a Schema:

pubstructAccountBalanceSchema;implSchemaforAccountBalanceSchema{constCOLUMN_FAMILY_NAME:&str = "account_balances";typeKey = Account;typeValue = u64;}implKeyCodec<AccountBalanceSchema>forAccount{fnencode_key(&self) -> Vec<u8>{
bincode::to_vec(self)}fndecode_key(key:Vec<u8>) -> Self{// elided}}implValueCode<AccountBlanceSchema>foru64{// elided}

About

Type-safe schema APIs for RocksDB in Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages