Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose memtable flush #72

Merged
merged 3 commits into from
Oct 29, 2024
Merged

expose memtable flush #72

merged 3 commits into from
Oct 29, 2024

Conversation

arnetheduck
Copy link
Member

This can be used to avoid log replays on startup, for example

This can be used to avoid log replays on startup, for example
@arnetheduck arnetheduck requested a review from bhartnett October 27, 2024 15:54
@@ -465,6 +465,22 @@ proc releaseSnapshot*(db: RocksDbRef, snapshot: SnapshotRef) =
rocksdb_release_snapshot(db.cPtr, snapshot.cPtr)
snapshot.setClosed()

proc flush*(db: RocksDbRef, cfs: openArray[ColFamilyHandleRef]): RocksDBResult[void] =
withLock(db.lock):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The c rocksdb type is thread safe so we shouldn't need to lock here as we don't update any fields in the RocksDbRef.

@@ -465,6 +465,22 @@ proc releaseSnapshot*(db: RocksDbRef, snapshot: SnapshotRef) =
rocksdb_release_snapshot(db.cPtr, snapshot.cPtr)
snapshot.setClosed()

proc flush*(db: RocksDbRef, cfs: openArray[ColFamilyHandleRef]): RocksDBResult[void] =
withLock(db.lock):
if not db.isClosed():
Copy link
Contributor

@bhartnett bhartnett Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this isClosed check an assertion because we should never try flushing a closed database. It would be a bug/developer error if so.

if not db.isClosed():
var cfs = cfs.mapIt(it.cPtr)
var errors: cstring
var opts = rocksdb_flushoptions_create()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often do we plan to call flush? If it gets called frequently then perhaps we should create the flush options when starting the database and hold a pointer to it and we can free when closing the database to reduce the number of allocations for performance reasons.

@@ -465,6 +465,22 @@ proc releaseSnapshot*(db: RocksDbRef, snapshot: SnapshotRef) =
rocksdb_release_snapshot(db.cPtr, snapshot.cPtr)
snapshot.setClosed()

proc flush*(db: RocksDbRef, cfs: openArray[ColFamilyHandleRef]): RocksDBResult[void] =
Copy link
Contributor

@bhartnett bhartnett Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnetheduck Is the goal simply to flush all the opened column families? If so, I'll remove the cfs parameter and just flush all the column familes in ColFamilyTableRef

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason, rocksdb exposes it like this - I think we should strive for "rough api equivalence", ie since rocksdb offers the option for specific columns, we should just follow along. this applies to everything in the library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Java library has 3 alternatives: https://javadoc.io/doc/org.rocksdb/rocksdbjni/9.6.1/org/rocksdb/RocksDB.html#flush-org.rocksdb.FlushOptions-

I can do something similar if we want to have more options. One of the functions has no cf parameter which implies flushing all opened column families.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the functions has no cf parameter which implies flushing all opened column families.

I'd verify this, ie I think it flushes just the default CF and none of the custom ones.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes actually, you are correct. That one is using the default CF, my mistake. I'll follow the pattern and implement as you suggested

@bhartnett
Copy link
Contributor

@arnetheduck I've pushed an update to the PR. Ready for your review.

@@ -111,6 +111,9 @@ proc defaultDbOptions*(autoClose = false): DbOptionsRef =
# Enable creating column families if they do not exist
dbOpts.createMissingColumnFamilies = true

# Make sure flush is atomic accross column families
dbOpts.atomicFlush = true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not something we want to enable by default, ie it carries greater (performance) implications than is obvious

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, will remove

@bhartnett bhartnett merged commit 17eb247 into master Oct 29, 2024
10 checks passed
@bhartnett bhartnett deleted the flush branch October 29, 2024 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants