Add DB::KeyExists() public API to skip blob file reads for existence checks#14644
Open
m-nagarajan wants to merge 1 commit into
Open
Add DB::KeyExists() public API to skip blob file reads for existence checks#14644m-nagarajan wants to merge 1 commit into
m-nagarajan wants to merge 1 commit into
Conversation
…checks Summary: Add a new virtual method DB::KeyExists() that checks key existence without reading blob file values. For BlobDB stores, the existing keyExists() JNI method internally calls Get() which resolves blob indexes and reads the full blob value only to discard it. The new API uses GetImpl with a non-null is_blob_index pointer, causing Version::Get to report blob indexes back without resolving them — skipping blob file I/O entirely. Changes: - Add DB::KeyExists() with io_activity validation and blob-skip via is_blob_index - Add StackableDB::KeyExists() override to prevent UB on TransactionDB/DBWithTTL - Propagate is_blob_index in DBImplReadOnly::GetImpl and DBImplSecondary::GetImpl - Simplify JNI key_exists_helper to call DB::KeyExists with KeyMayExist pre-check - Add C++ tests (blob-skip, basic, column family, merge, io_activity, read-only DB) - Add Java BlobDB tests with PerfContext blob-read verification
Merged
16 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Java
keyExists()was added as a JNI convenience that callsKeyMayExist+Get. For BlobDB stores, theGetstep resolves blob indexes and reads potentially large (10KB–1MB+) blob values that are immediately discarded. This PR eliminates that waste by introducing a C++DB::KeyExists()that both C++ and Java callers benefit from.Details
Add a new
DB::KeyExists()virtual method that checks key existence without resolving blob indexes. The existing JavakeyExists()JNI method internally callsGet()which reads the full blob value only to discard it. The new API usesGetImplwith a non-nullis_blob_indexpointer, causingVersion::Getto skip blob file I/O entirely.DB::KeyExists(ReadOptions, ColumnFamilyHandle*, Slice)returningStatus::OK()orStatus::NotFound()io_activityvalidation matchingDB::Get()patternStackableDB::KeyExists()override to prevent undefined behavior onTransactionDB/DBWithTTLis_blob_indexinDBImplReadOnly::GetImplandDBImplSecondary::GetImpl(allmem->Get,imm->Get, andVersion::Getcall sites)key_exists_helperto delegate toDB::KeyExists()with aKeyMayExistbloom filter pre-check for fast rejection of absent keysBLOB_DB_BLOB_FILE_BYTES_READstatistics, basic existence, column families, merge operands, invalidio_activity, read-only DBPerfContext, column families,ReadOptionsvariant, memtable path,DirectByteBufferRelated: #12921 reports
keyExistsfalse negatives fromKeyMayExist. The C++DB::KeyExists()avoids this by callingGetImpldirectly withoutKeyMayExist. The JNI layer retainsKeyMayExistas a fast-path (accepted trade-off for backward compatibility).Testing
db_blob_basic_test: 6 newKeyExists*test casesKeyExistsBlobTest.java: 6 new Java test cases includingPerfContext-based blob-read verificationkeyExistsproduces zero blob reads whileget()on the same key produces non-zero blob reads (control)