You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was reading through the rocksdb code base to figure out how to do range deletions with TransactionDB, and it look like there's a slightly "risky" way to do it with native writes within a transaction. I was digging through this library, and I'm not seeing support for TransactionDBWriteOptimizations or requisite support with the write() methods.
My use case is Raft log truncation with a TransactionDB. I have a range of Raft logs that I need to truncate, and since I can't use TransactionDB::DeleteRange(), I have to get creative. Theoretically I can just use a (prefix) iterator with min/max bounds, but that feels pretty inefficient. Personally, I'd rather just use a lock to ensure the transaction is isolated, then make the "risky" write with TransactionDBWriteOptimizations. Could support for this be added? How much effort would that be?
This is what I'm doing now, and it feels very inefficient:
fntruncate(&mutself,meta_log_id:&MetaLogId) -> std::result::Result<(),StorageError>{let(log_id, cf_handle) = self.metalog_unwinder(&meta_log_id)?;// from where we're told to the end.let start = log_id.index.to_le_bytes();let from = u64::MAX.to_le_bytes();let read_opts = ReadOptions::default();
read_opts.fill_cache(false);
read_opts.set_iterate_range(start..from);let tx = self.db.transaction();letmut tx_iter = tx.iterator_cf_opt(&cf_handle, read_opts,IteratorMode::Start);for log in tx_iter {let(key, val) = log.unwrap();match tx.delete_cf(&cf_handle, key){Ok(_) => {},Err(e) => {let shard_id = meta_log_id.shard_id;match tx.rollback(){Ok(_) => returnErr(MetaRaftLogStorageError(FailedTruncation(&shard_id,"tx rolled back successfully"))),// todo (sienna): this feels hacky with `format!`, maybe fix laterErr(ve) => returnErr(MetaRaftLogStorageError(FailedTruncation(&shard_id,format!("tx failed to rollback, this replica is likely fucked, {}", ve.to_string()).as_str())))}}};}match tx.commit(){Ok(_) => Ok(()),Err(e) => MetaRaftLogStorageError(FailedTruncation(meta_log_id.shard_id,"failed to commit successful truncation tx"))}}
Theoretically I can do the work, but I'm new to rust and rocksdb, and I've not yet needed to directly use the FFI in rust. I do have some experience with cgo, so I can likely figure it out with some effort and questions.
Edit: added existing reference
The text was updated successfully, but these errors were encountered:
I was reading through the rocksdb code base to figure out how to do range deletions with
TransactionDB
, and it look like there's a slightly "risky" way to do it with native writes within a transaction. I was digging through this library, and I'm not seeing support forTransactionDBWriteOptimizations
or requisite support with thewrite()
methods.My use case is Raft log truncation with a
TransactionDB
. I have a range of Raft logs that I need to truncate, and since I can't useTransactionDB::DeleteRange()
, I have to get creative. Theoretically I can just use a (prefix) iterator with min/max bounds, but that feels pretty inefficient. Personally, I'd rather just use a lock to ensure the transaction is isolated, then make the "risky" write withTransactionDBWriteOptimizations
. Could support for this be added? How much effort would that be?This is what I'm doing now, and it feels very inefficient:
Theoretically I can do the work, but I'm new to rust and rocksdb, and I've not yet needed to directly use the FFI in rust. I do have some experience with cgo, so I can likely figure it out with some effort and questions.
Edit: added existing reference
The text was updated successfully, but these errors were encountered: