fjall-rs / fjall

🗻 LSM-based embeddable key-value storage engine written in safe Rust
https://fjall-rs.github.io/
Apache License 2.0
574 stars 24 forks source link

How to flush manually #51

Closed i18nsite closed 5 months ago

i18nsite commented 5 months ago

How to flush manually ?

the config not has method flush

will the config auto flush when drop?

marvin-j97 commented 5 months ago

From the README:

After writing data (be it, insert, remove or committing a write batch), you can choose to call Keyspace::persist which takes a FlushMode parameter. By default every 1000ms data is fsynced asynchronously. Also when dropped, the keyspace will try to persist the journal synchronously.

Example

use fjall::{Config, FlushMode};

pub fn main() -> fjall::Result<()> {
  let folder = std::path::Path::new("mydata");

  let keyspace = Config::new(folder).open()?;
  let items = keyspace.open_partition("items", Default::default())?;

  // Write some data
  items.insert("a", "hello")?;
  items.insert("b", "world")?;

  // Choose the FlushMode based on required durability guarantees
  keyspace.persist(FlushMode::SyncAll)?;

  Ok(())
}