aboutsummaryrefslogtreecommitdiff
path: root/src/db/sqlite_adapter.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2024-09-14 15:57:27 +0000
committerAlex <alex@adnab.me>2024-09-14 15:57:27 +0000
commit6da135354135d8d8a5d2476bfbcd4aab91abfc3c (patch)
tree5028687340c272ba522de8084167034e8f2eaad0 /src/db/sqlite_adapter.rs
parent586957b4b7261b43e7820d7193516153201b4954 (diff)
parentbd71728874e7f03c547246cb0076804f62db102f (diff)
downloadgarage-6da135354135d8d8a5d2476bfbcd4aab91abfc3c.tar.gz
garage-6da135354135d8d8a5d2476bfbcd4aab91abfc3c.zip
Merge pull request 'Don't fetch old values in cross-partition transactional inserts' (#877) from withings/garage:perf/kv/insert-no-return-cross-partition into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/877
Diffstat (limited to 'src/db/sqlite_adapter.rs')
-rw-r--r--src/db/sqlite_adapter.rs32
1 files changed, 9 insertions, 23 deletions
diff --git a/src/db/sqlite_adapter.rs b/src/db/sqlite_adapter.rs
index 5a142117..9c9a668d 100644
--- a/src/db/sqlite_adapter.rs
+++ b/src/db/sqlite_adapter.rs
@@ -192,7 +192,7 @@ impl IDb for SqliteDb {
let db = self.db.get()?;
let lock = self.write_lock.lock();
- let n = db.execute(&format!("DELETE FROM {} WHERE k = ?1", tree), params![key])?;
+ db.execute(&format!("DELETE FROM {} WHERE k = ?1", tree), params![key])?;
drop(lock);
Ok(())
@@ -336,31 +336,17 @@ impl<'a> ITx for SqliteTx<'a> {
}
}
- fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> TxOpResult<Option<Value>> {
+ fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> TxOpResult<()> {
let tree = self.get_tree(tree)?;
- let old_val = self.internal_get(tree, key)?;
-
- let sql = match &old_val {
- Some(_) => format!("UPDATE {} SET v = ?2 WHERE k = ?1", tree),
- None => format!("INSERT INTO {} (k, v) VALUES (?1, ?2)", tree),
- };
- let n = self.tx.execute(&sql, params![key, value])?;
- assert_eq!(n, 1);
-
- Ok(old_val)
+ let sql = format!("INSERT OR REPLACE INTO {} (k, v) VALUES (?1, ?2)", tree);
+ self.tx.execute(&sql, params![key, value])?;
+ Ok(())
}
- fn remove(&mut self, tree: usize, key: &[u8]) -> TxOpResult<Option<Value>> {
+ fn remove(&mut self, tree: usize, key: &[u8]) -> TxOpResult<()> {
let tree = self.get_tree(tree)?;
- let old_val = self.internal_get(tree, key)?;
-
- if old_val.is_some() {
- let n = self
- .tx
- .execute(&format!("DELETE FROM {} WHERE k = ?1", tree), params![key])?;
- assert_eq!(n, 1);
- }
-
- Ok(old_val)
+ self.tx
+ .execute(&format!("DELETE FROM {} WHERE k = ?1", tree), params![key])?;
+ Ok(())
}
fn clear(&mut self, tree: usize) -> TxOpResult<()> {
let tree = self.get_tree(tree)?;