Skip to content

Commit

Permalink
Making a simpler KV store.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitkulshreshtha committed Dec 5, 2024
1 parent 7cf695c commit 00f5bd6
Show file tree
Hide file tree
Showing 7 changed files with 611 additions and 633 deletions.
23 changes: 0 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion datastores/gossip_kv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"
publish = false

[dependencies]
affinity = "0.1.2"
# affinity = "0.1.2"
clap = { version = "4.5.4", features = ["derive", "env"] }
config = "0.14.0"
governor = "0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion datastores/gossip_kv/kv/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub enum ClientRequest {
/// A request to get the value of a key.
Get { key: Key },
/// A request to set the value of a key.
Set { key: Key, value: String },
Set { key: u64, value: String },
/// A request to delete the value of a key.
Delete { key: Key },
}
Expand Down
37 changes: 18 additions & 19 deletions datastores/gossip_kv/kv/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub type TableMap<V> = MapUnionHashMap<TableName, Table<V>>;

pub type NamespaceMap<V> = MapUnionHashMap<Namespace, TableMap<V>>;

pub type Namespaces<C> = NamespaceMap<RowValue<C>>;
pub type Namespaces<C> = MapUnionHashMap<u64, DomPair<C, SetUnionHashSet<String>>>;

/// Timestamps used in the model.
// TODO: This will be updated to use a more sophisticated clock type with https://github.com/hydro-project/hydroflow/issues/1207.
Expand All @@ -42,15 +42,14 @@ pub type Clock = Max<u64>;
/// - `val`: Row value.
pub fn upsert_row<C>(
row_ts: C,
ns: Namespace,
table_name: TableName,
key: RowKey,
key: u64,
val: String,
) -> Namespaces<C> {
let value: RowValue<C> = RowValue::new_from(row_ts, SetUnionHashSet::new_from([val]));
let row: Table<RowValue<C>> = Table::new_from([(key, value)]);
let table: TableMap<RowValue<C>> = TableMap::new_from([(table_name, row)]);
Namespaces::new_from([(ns, table)])
// let value: RowValue<C> = RowValue::new_from(row_ts, SetUnionHashSet::new_from([val]));
// let row: Table<RowValue<C>> = Table::new_from([(key, value)]);
// let table: TableMap<RowValue<C>> = TableMap::new_from([(table_name, row)]);
// Namespaces::new_from([(ns, table)])
Namespaces::new_from([(key, DomPair::new(row_ts, SetUnionHashSet::new_from([val])))])
}

/// TableMap element to delete a row from an existing TableMap.
Expand All @@ -61,17 +60,17 @@ pub fn upsert_row<C>(
/// - `row_ts`: New timestamp of the row being deleted.
/// - `table_name`: Name of the table.
/// - `key`: Primary key of the row.
pub fn delete_row<C>(
row_ts: C,
ns: Namespace,
table_name: TableName,
key: RowKey,
) -> Namespaces<C> {
let value: RowValue<C> = RowValue::new_from(row_ts, SetUnionHashSet::new_from([]));
let row: Table<RowValue<C>> = Table::new_from([(key, value)]);
let table = TableMap::new_from([(table_name, row)]);
Namespaces::new_from([(ns, table)])
}
// pub fn delete_row<C>(
// row_ts: C,
// ns: Namespace,
// table_name: TableName,
// key: RowKey,
// ) -> Namespaces<C> {
// let value: RowValue<C> = RowValue::new_from(row_ts, SetUnionHashSet::new_from([]));
// let row: Table<RowValue<C>> = Table::new_from([(key, value)]);
// let table = TableMap::new_from([(table_name, row)]);
// Namespaces::new_from([(ns, table)])
// }

#[cfg(test)]
mod tests {
Expand Down
Loading

0 comments on commit 00f5bd6

Please sign in to comment.