diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-01-24 04:31:48 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-01-24 04:31:48 +0100 |
| commit | b2e88a8beabf04adc28947cf82996e8692a68b71 (patch) | |
| tree | 23d66c8672b69cce7835ffabae4092669062ada8 /database/src/backends/rocksdb.rs | |
| parent | 774f64c0789529884dd7a5232f190e347ad29532 (diff) | |
| download | jellything-b2e88a8beabf04adc28947cf82996e8692a68b71.tar jellything-b2e88a8beabf04adc28947cf82996e8692a68b71.tar.bz2 jellything-b2e88a8beabf04adc28947cf82996e8692a68b71.tar.zst | |
move things around; kv crate
Diffstat (limited to 'database/src/backends/rocksdb.rs')
| -rw-r--r-- | database/src/backends/rocksdb.rs | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/database/src/backends/rocksdb.rs b/database/src/backends/rocksdb.rs deleted file mode 100644 index 056af9e..0000000 --- a/database/src/backends/rocksdb.rs +++ /dev/null @@ -1,78 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2026 metamuffin <metamuffin.org> -*/ - -use crate::backends::{Database, ReadTransaction, WriteTransaction}; -use anyhow::Result; -use rocksdb::{Direction, ErrorKind, IteratorMode, OptimisticTransactionDB}; -use std::path::Path; - -pub fn new(path: &Path) -> Result<OptimisticTransactionDB> { - Ok(OptimisticTransactionDB::open_default(path)?) -} - -impl Database for OptimisticTransactionDB { - fn write_transaction( - &self, - f: &mut dyn FnMut(&mut dyn WriteTransaction) -> Result<()>, - ) -> Result<()> { - loop { - let mut txn = self.transaction(); - f(&mut txn)?; - match txn.commit() { - Ok(()) => break Ok(()), - Err(e) if e.kind() == ErrorKind::Busy => continue, - Err(e) => return Err(e.into()), - } - } - } - fn read_transaction( - &self, - f: &mut dyn FnMut(&dyn ReadTransaction) -> Result<()>, - ) -> Result<()> { - loop { - let txn = self.transaction(); - f(&txn)?; - match txn.commit() { - Ok(()) => break Ok(()), - Err(e) if e.kind() == ErrorKind::Busy => continue, - Err(e) => return Err(e.into()), - } - } - } -} -impl WriteTransaction for rocksdb::Transaction<'_, OptimisticTransactionDB> { - fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()> { - Ok(self.put(key, value)?) - } - - fn del(&mut self, key: &[u8]) -> Result<()> { - Ok(self.delete(key)?) - } -} -impl ReadTransaction for rocksdb::Transaction<'_, OptimisticTransactionDB> { - fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> { - Ok(self.get(key)?) - } - - fn iter<'a>( - &'a self, - key: &[u8], - reverse: bool, - ) -> Result<Box<dyn Iterator<Item = Result<Vec<u8>>> + 'a>> { - let mut iter = self.iterator(IteratorMode::Start); - iter.set_mode(IteratorMode::From( - key, - if reverse { - Direction::Reverse - } else { - Direction::Forward - }, - )); - Ok(Box::new(iter.map(|e| { - e.map(|(k, _)| k.into_vec()).map_err(|e| e.into()) - }))) - } -} |