HarperFast / HarperFast/rocksdb-js
Added `flushed` property
- Dominant language
- C++
- Stars
- 21
- Forks
- 2
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 36
Description
lmdb-js has a flushed property which is a promise that resolves when the database is flushed to disk. RocksDB also does not flush data to disk on commit. RocksDB provides an event API that we can use to listen for when data is flushed.
Note: We can also listen for OnFlushBegin, but not sure if that’s useful. Additionally, we can listen for OnCompactionBegin and OnCompactionCompleted.
In the RocksDB, we wire up the listeners using the rocksdb::Options object. Rocksdb-js uses this in the DBRegistry::open() method.
Here’s an example of how to implement this:
```cpp
class MyEventListener : public rocksdb::EventListener {
public:
void OnFlushCompleted(DB* db, const FlushJobInfo& flush_job_info) override {
// Called when a memtable flush to SST file completes
std::cout << "Flush completed for column family: "
<< flush_job_info.cf_name << std::endl;
}
void OnCompactionCompleted(DB* db, const CompactionJobInfo& compaction_job_info) override {
// Called when compaction completes (merges/rewrites SST files)
}
};
// Register the listener
Options options;
options.listeners.emplace_back(std::make_shared());
```
The flushed property is a PromiseLike type where it’s an object with a then() method. If there are no pending transactions, then the flushed property resolves immediately. If there is a pending transaction, then the flushed property awaits it a promise, then calls the resolve/reject callbacks. When a transaction completes, the promise is nulled.
Contributor guide
Assessment
This issue has not been assessed yet.