fixing merge & put signatures
MODIFY
light_node/src/configuration.rs
light_node/src/configuration.rs
@@ -484,6 +484,11 @@ pub fn tezos_app() -> App<'static, 'static> {
.multiple(true)
.value_name("STRING")
.help("Activate recording of context storage actions"))
+ .arg(Arg::with_name("kv-store-backend")
+ .long("kv-store-backend")
+ .takes_value(true)
+ .value_name("STRING")
+ .help("Choose the merkle storege backend - supported backends: 'rocksdb', 'sled', 'inmem', 'btree'"))
.arg(Arg::with_name("compute-context-action-tree-hashes")
.long("compute-context-action-tree-hashes")
.takes_value(true)

MODIFY
storage/src/backend/btree_map.rs
storage/src/backend/btree_map.rs
@@ -36,8 +36,8 @@ impl KVStoreTrait for KVStore<EntryHash, ContextValue> {
}
/// put kv in map if key doesn't exist. If it does then return false.
- fn put(&mut self, key: EntryHash, value: ContextValue) -> Result<bool, KVStoreError> {
- match self.kv_map.entry(key) {
+ fn put(&mut self, key: &EntryHash, value: ContextValue) -> Result<bool, KVStoreError> {
+ match self.kv_map.entry(key.clone()) {
Entry::Vacant(entry) => {
entry.insert(value);
Ok(true)
@@ -46,8 +46,8 @@ impl KVStoreTrait for KVStore<EntryHash, ContextValue> {
}
}
- fn merge(&mut self, key: EntryHash, value: ContextValue) -> Result<(), KVStoreError> {
- self.kv_map.insert(key, value);
+ fn merge(&mut self, key: &EntryHash, value: ContextValue) -> Result<(), KVStoreError> {
+ self.kv_map.insert(key.clone(), value);
Ok(())
}

MODIFY
storage/src/backend/in_memory_backend.rs
storage/src/backend/in_memory_backend.rs
@@ -28,8 +28,8 @@ impl StorageBackend for InMemoryBackend {
false
}
- fn put(&mut self, key: EntryHash, value: ContextValue) -> Result<bool, StorageBackendError> {
- let measurement = StorageBackendStats::from((&key, &value));
+ fn put(&mut self, key: &EntryHash, value: ContextValue) -> Result<bool, StorageBackendError> {
+ let measurement = StorageBackendStats::from((key, &value));
let mut w = self
.inner
.write()
@@ -37,7 +37,7 @@ impl StorageBackend for InMemoryBackend {
error: format!("{}", e),
})?;
- let was_added = w.insert(key, value).is_none();
+ let was_added = w.insert(key.clone(), value).is_none();
if was_added {
self.stats += measurement;
@@ -46,7 +46,7 @@ impl StorageBackend for InMemoryBackend {
Ok(was_added)
}
- fn merge(&mut self, key: EntryHash, value: ContextValue) -> Result<(), StorageBackendError> {
+ fn merge(&mut self, key: &EntryHash, value: ContextValue) -> Result<(), StorageBackendError> {
let mut w = self
.inner
.write()
@@ -54,7 +54,7 @@ impl StorageBackend for InMemoryBackend {
error: format!("{}", e),
})?;
- w.insert(key, value);
+ w.insert(key.clone(), value);
Ok(())
}

MODIFY
storage/src/backend/rocksdb_backend.rs
storage/src/backend/rocksdb_backend.rs
@@ -45,7 +45,7 @@ impl StorageBackend for RocksDBBackend {
true
}
- fn put(&mut self, key: EntryHash, value: ContextValue) -> Result<bool, StorageBackendError> {
+ fn put(&mut self, key: &EntryHash, value: ContextValue) -> Result<bool, StorageBackendError> {
let cf = self.inner.cf_handle(&self.column_name).ok_or(
StorageBackendError::MissingColumnFamily {
name: &self.column_name,
@@ -63,7 +63,7 @@ impl StorageBackend for RocksDBBackend {
.map(|_| true)
}
- fn merge(&mut self, key: EntryHash, value: ContextValue) -> Result<(), StorageBackendError> {
+ fn merge(&mut self, key: &EntryHash, value: ContextValue) -> Result<(), StorageBackendError> {
let cf = self.inner.cf_handle(&self.column_name).ok_or(
StorageBackendError::MissingColumnFamily {
name: &self.column_name,

MODIFY
storage/src/backend/sled_backend.rs
storage/src/backend/sled_backend.rs
@@ -20,14 +20,14 @@ impl StorageBackend for SledBackend {
true
}
- fn put(&mut self, key: EntryHash, value: ContextValue) -> Result<bool, StorageBackendError> {
+ fn put(&mut self, key: &EntryHash, value: ContextValue) -> Result<bool, StorageBackendError> {
Ok(self
.inner
.insert(&key.as_ref()[..], value)
.map(|v| v.is_none())?)
}
- fn merge(&mut self, key: EntryHash, value: ContextValue) -> Result<(), StorageBackendError> {
+ fn merge(&mut self, key: &EntryHash, value: ContextValue) -> Result<(), StorageBackendError> {
self.inner.insert(&key.as_ref()[..], value)?;
Ok(())
}

MODIFY
storage/src/merkle_storage.rs
storage/src/merkle_storage.rs
@@ -1164,7 +1164,7 @@ impl MerkleStorage {
// atomically write all entries in one batch to DB
for (k, v) in batch {
- self.db.put(k, v)?;
+ self.db.put(&k, v)?;
}
Ok(())

MODIFY
storage/src/persistent/mod.rs
storage/src/persistent/mod.rs
@@ -153,8 +153,6 @@ impl PersistentStorage {
clog: Arc<CommitLogs>,
merkle_backend: KeyValueStoreBackend,
) -> Self {
- let sled = sled::Config::new().path("/tmp/sled").open().unwrap();
-
let merkle = match merkle_backend {
KeyValueStoreBackend::RocksDB => MerkleStorage::new(Box::new(RocksDBBackend::new(
db_context.clone(),
@@ -162,6 +160,7 @@ impl PersistentStorage {
))),
KeyValueStoreBackend::InMem => MerkleStorage::new(Box::new(InMemoryBackend::new())),
KeyValueStoreBackend::Sled => {
+ let sled = sled::Config::new().temporary(true).open().unwrap();
MerkleStorage::new(Box::new(SledBackend::new(sled.deref().clone())))
}
KeyValueStoreBackend::BTreeMap => MerkleStorage::new(Box::new(BTreeMapBackend::new())),

MODIFY
storage/src/storage_backend.rs
storage/src/storage_backend.rs
@@ -69,8 +69,8 @@ impl slog::Value for StorageBackendError {
pub trait StorageBackend: Send + Sync {
fn is_persisted(&self) -> bool;
fn get(&self, key: &EntryHash) -> Result<Option<ContextValue>, StorageBackendError>;
- fn put(&mut self, key: EntryHash, value: ContextValue) -> Result<bool, StorageBackendError>;
- fn merge(&mut self, key: EntryHash, value: ContextValue) -> Result<(), StorageBackendError>;
+ fn put(&mut self, key: &EntryHash, value: ContextValue) -> Result<bool, StorageBackendError>;
+ fn merge(&mut self, key: &EntryHash, value: ContextValue) -> Result<(), StorageBackendError>;
fn delete(&mut self, key: &EntryHash) -> Result<Option<ContextValue>, StorageBackendError>;
fn contains(&self, key: &EntryHash) -> Result<bool, StorageBackendError>;
fn get_mem_use_stats(&self) -> Result<RocksDBStats, StorageBackendError>;

fixing merge & put signatures