thinking through: persistence if keyspace is dropped before opened partitions #44
-
I'm noticing if I call keyspace.open_partition, it's possible to keep the partition around, and drop the keyspace. e.g. something like: pub struct Store {
partition: PartitionHandle,
}
impl Store {
pub fn new(path: &str) -> Store {
let config = Config::new(path);
let keyspace = config.open().unwrap();
let partition = keyspace
.open_partition("main", PartitionCreateOptions::default())
.unwrap();
Store {
partition,
}
}
pub fn put(&mut self) -> Frame {
let frame = Frame {
id: scru128::new(),
};
let encoded: Vec<u8> = bincode::serialize(&frame).unwrap();
self.partition.insert(frame.id.to_bytes(), encoded).unwrap();
frame
}
}
let store = Store::new("./store")
store.put(); This caught me off guard, as I was expecting a fsync when the process ended. But fsync only occurs automatically when keyspace is dropped (in this experiment I'm not keeping the process around for a complete second). I've updated to keep the keyspace on the Store too, and that works as expected. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I'm not sure what the right thing to do is. Perhaps just document: "you'll want to keep a reference to your keyspace, while you still have an open partition", or make it not allowed to keep a reference to a partition, after the keyspace has been dropped? |
Beta Was this translation helpful? Give feedback.
-
Yeah I am not sure how to handle it nicely. I don't think giving
It should definitely be documented that the keyspace should ideally be kept around for the entire duration of the program, or at least as long as partitions are open... |
Beta Was this translation helpful? Give feedback.
-
I just noticed I can probably move the Update: A bit harder than expected, partitions reference the flush manager, but the flush manager may contain tasks that reference the partitions, preventing the journal from being dropped. |
Beta Was this translation helpful? Give feedback.
-
This should be resolved in a future version. I took a look at cyclic Arcs and checking everything drops correctly. See #57 |
Beta Was this translation helpful? Give feedback.
This should be resolved in a future version. I took a look at cyclic Arcs and checking everything drops correctly. See #57