Add logical size tracking for SET and HASH hashtable encoding#5
Draft
Add logical size tracking for SET and HASH hashtable encoding#5
Conversation
76e6af1 to
6814655
Compare
Signed-off-by: Lior Sventitzky <liorsve@amazon.com>
6814655 to
402214e
Compare
Signed-off-by: Lior Sventitzky <liorsve@amazon.com>
402214e to
51d834e
Compare
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
Adds incremental logical size tracking for hashtable-encoded SET and HASH data types. The hashtable struct maintains a
tracked_data_bytesfield that is automatically updated on every insert/remove, giving O(1) access to the total logical entry size without walking the table.Hashtable changes (
hashtable.c/hashtable.h)entryGetSizecallback tohashtableType— returns logical size of an entrytracked_data_bytesfield tostruct hashtable, maintained automatically oninsert(),hashtableInsertAtPosition(),hashtablePop(),hashtableTwoPhasePopDelete(),hashtableEmpty()hashtableTrackedDataBytes()accessor andhashtableAdjustTrackedDataBytes()for in-place entry mutationsSET tracking (
server.c)sdsEntryGetSizecallback:sdsHdrSize(type) + sdslen(s) + 1— pure arithmetic, no zmalloc callssetHashtableTypet_set.cHASH tracking (
entry.c,server.c,t_hash.c)entryGetLogicalSize()inentry.ccovering all 4 entry types (TYPE_5 embedded, TYPE_8 embedded, separate SDS value, stringRef) — no zmalloc callshashEntryGetSizecallback intohashHashtableTypeandhashWithVolatileItemsHashtableTypet_hash.cneed manual delta tracking viahashtableAdjustTrackedDataBytes():entryUpdateinhashTypeSet(value change)entryUpdateAsStringRefinhashTypeUpdateAsStringRef(stringRef path)entrySetExpiryinhashTypeSetExpireandhashTypePersist(expiry toggle)Design
zmalloc_sizetracked_data_bytes= sum of entry logical sizes. Metadata =hashtableMemUsage()(struct + buckets), computed O(1) from existing fieldsTests
test_set_tracking.cpp— 22 tests covering all mutation paths + 2 non-deterministic fuzzerstest_hash_tracking.cpp— 17 tests covering all mutation paths including expiry toggle, stringRef, conversion, and a non-deterministic fuzzer