Skip to content

Commit f7df8fb

Browse files
chemearkpar
andauthored
Parity-db Change missing implementation. (paritytech#11049)
* support for release as in kvdb (only if no rc). * Start impl * minimal implementation for paritydb rc * Update client/db/src/parity_db.rs Co-authored-by: Arkadiy Paronyan <[email protected]> * Update client/db/src/parity_db.rs Co-authored-by: Arkadiy Paronyan <[email protected]> * Update client/db/src/parity_db.rs Co-authored-by: Arkadiy Paronyan <[email protected]> * Commit not panicking in DbAdapter * errors from string * update parity db version Co-authored-by: Arkadiy Paronyan <[email protected]>
1 parent a056753 commit f7df8fb

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/db/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kvdb-memorydb = "0.11.0"
2222
kvdb-rocksdb = { version = "0.15.2", optional = true }
2323
linked-hash-map = "0.5.4"
2424
log = "0.4.16"
25-
parity-db = { version = "0.3.12", optional = true }
25+
parity-db = { version = "0.3.13", optional = true }
2626
parking_lot = "0.12.0"
2727
sc-client-api = { version = "4.0.0-dev", path = "../api" }
2828
sc-state-db = { version = "0.10.0-dev", path = "../state-db" }

client/db/src/parity_db.rs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,57 @@ pub fn open<H: Clone + AsRef<[u8]>>(
8686
Ok(std::sync::Arc::new(DbAdapter(db)))
8787
}
8888

89+
fn ref_counted_column(col: u32) -> bool {
90+
col == columns::TRANSACTION || col == columns::STATE
91+
}
92+
8993
impl<H: Clone + AsRef<[u8]>> Database<H> for DbAdapter {
9094
fn commit(&self, transaction: Transaction<H>) -> Result<(), DatabaseError> {
91-
handle_err(self.0.commit(transaction.0.into_iter().map(|change| match change {
92-
Change::Set(col, key, value) => (col as u8, key, Some(value)),
93-
Change::Remove(col, key) => (col as u8, key, None),
94-
_ => unimplemented!(),
95-
})));
95+
let mut not_ref_counted_column = Vec::new();
96+
let result = self.0.commit(transaction.0.into_iter().filter_map(|change| {
97+
Some(match change {
98+
Change::Set(col, key, value) => (col as u8, key, Some(value)),
99+
Change::Remove(col, key) => (col as u8, key, None),
100+
Change::Store(col, key, value) =>
101+
if ref_counted_column(col) {
102+
(col as u8, key.as_ref().to_vec(), Some(value))
103+
} else {
104+
if !not_ref_counted_column.contains(&col) {
105+
not_ref_counted_column.push(col);
106+
}
107+
return None
108+
},
109+
Change::Reference(col, key) =>
110+
if ref_counted_column(col) {
111+
// FIXME accessing value is not strictly needed, optimize this in parity-db.
112+
let value = <Self as Database<H>>::get(self, col, key.as_ref());
113+
(col as u8, key.as_ref().to_vec(), value)
114+
} else {
115+
if !not_ref_counted_column.contains(&col) {
116+
not_ref_counted_column.push(col);
117+
}
118+
return None
119+
},
120+
Change::Release(col, key) =>
121+
if ref_counted_column(col) {
122+
(col as u8, key.as_ref().to_vec(), None)
123+
} else {
124+
if !not_ref_counted_column.contains(&col) {
125+
not_ref_counted_column.push(col);
126+
}
127+
return None
128+
},
129+
})
130+
}));
131+
132+
if not_ref_counted_column.len() > 0 {
133+
return Err(DatabaseError(Box::new(parity_db::Error::InvalidInput(format!(
134+
"Ref counted operation on non ref counted columns {:?}",
135+
not_ref_counted_column
136+
)))))
137+
}
96138

97-
Ok(())
139+
result.map_err(|e| DatabaseError(Box::new(e)))
98140
}
99141

100142
fn get(&self, col: ColumnId, key: &[u8]) -> Option<Vec<u8>> {

0 commit comments

Comments
 (0)