Update value correctry #136
-
Hi! 👋 Thank you so much for your, lib! I have a question regarding updating a value in Fjall. Specifically, I want to achieve the following behaviour:
Here's the code I have so far: fn main() -> fjall::Result<()> {
let keyspace = Config::new("db")
.open_transactional()
.expect("Failed to connect to keyspace");
let partition = keyspace
.open_partition("settings", PartitionCreateOptions::default())
.expect("Failed to connect to partition");
let mut write_tx = keyspace.write_tx();
let key = "a";
let Some(item) = write_tx.get(&partition, key)? else {
return Ok(());
};
write_tx.insert(&partition, key, "another value");
write_tx.commit()?;
keyspace.persist(fjall::PersistMode::SyncAll)?;
Ok(())
} My question is: Do I need to execute both |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Both are logically correct - when you use SyncAll, you make sure the data arrives on disk before continuing, but it will be (much) slower. By default, the data will "only" be flushed to the OS, so it can be written to disk on application crash, but not on power loss or kernel panic. You can also shorten it to: let mut write_tx = keyspace.write_tx().durability(Some(fjall::PersistMode::SyncAll));
let key = "a";
let Some(item) = write_tx.get(&partition, key)? else {
return Ok(());
};
write_tx.insert(&partition, key, "another value");
write_tx.commit()?; or use |
Beta Was this translation helpful? Give feedback.
Both are logically correct - when you use SyncAll, you make sure the data arrives on disk before continuing, but it will be (much) slower.
By default, the data will "only" be flushed to the OS, so it can be written to disk on application crash, but not on power loss or kernel panic.
You can also shorten it to:
or use
WriteTx::fetch_update
.