syndtr / goleveldb

LevelDB key/value database in Go.
BSD 2-Clause "Simplified" License
6.12k stars 968 forks source link

Add a Sync barrier method #311

Open Stebalien opened 4 years ago

Stebalien commented 4 years ago

Proposal

Add a Sync method to sync all records written before Sync was called to disk.

Motivation

Currently, it's possible to synchronously write individual records. However, synchronously writing a record doesn't guarantee that previously written (non-sync) records will be synced (they could be in a different journal).

When writing collections of objects, it's useful to be able to:

Importantly, the index shouldn't be updated until the objects have been synced.

goleveldb currently provides batches and transactions but neither seem to serve this purpose. The best external solution I can think of is to write a wrapper with an in-memory write buffer. However, I'd prefer to just write to disk and let the OS decide when to sync and/or when the buffer is full.

Implementation

Unfortunately, my understanding of leveldb and goleveldb is limited. My first attempt was #310 but I didn't realize journals were rotated. Given that journals are rotated, the only solution I can think of is:

Does this sound like it'll work?

Stebalien commented 4 years ago

Note: This is a very low priority feature request. I'm not going to have time to implement it any time soon and I don't really expect anyone else to get to it. I'm just leaving this here in case anyone is interested.

Feel free to close this as out of scope and/or "not worth the effort".