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 |
Answered by
marvin-j97
Feb 23, 2025
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 |
0 replies
Answer selected by
MarkAntipin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to 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:
or use
WriteTx::fetch_update.