Skip to content

Commit

Permalink
Update code comment
Browse files Browse the repository at this point in the history
Signed-off-by: Harkrishn Patro <[email protected]>
  • Loading branch information
hpatro committed Jul 1, 2024
1 parent 11400e2 commit 4ca43ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,7 @@ robj *lookupKeyWriteOrReply(client *c, robj *key, robj *reply) {

/* Add the key to the DB.
*
* The kvstore handles `key` based on `dictType` during initialization:
* - If `dictType.embedded-entry` is 1, it clones the `key`.
* - Otherwise, it assumes ownership of the `key`.
* In this case a copy of `key` is made in kvstore, the caller must ensure the `key` is properly freed.
* In this case a copy of `key` is copied in kvstore, the caller must ensure the `key` is properly freed.
*
* It's up to the caller to increment the reference
* counter of the value if needed.
Expand Down Expand Up @@ -255,10 +252,7 @@ int getKeySlot(sds key) {
*
* The function returns 1 if the key was added to the database, otherwise 0 is returned.
*
* The kvstore handles `key` based on `dictType` during initialization:
* - If `dictType.embedded-entry` is 1, it clones the `key`.
* - Otherwise, it assumes ownership of the `key`.
* In this case a copy of `key` is made in kvstore, the caller must ensure the `key` is properly freed.
* In this case a copy of `key` is copied in kvstore, the caller must ensure the `key` is properly freed.
*/
int dbAddRDBLoad(serverDb *db, sds key, robj *val) {
int slot = getKeySlot(key);
Expand Down
18 changes: 17 additions & 1 deletion src/kvstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,12 @@ static size_t kvstoreDictMetadataSize(dict *d) {

/* Create an array of dictionaries
* num_dicts_bits is the log2 of the amount of dictionaries needed (e.g. 0 for 1 dict,
* 3 for 8 dicts, etc.) */
* 3 for 8 dicts, etc.)
*
* The kvstore handles `key` based on `dictType` during initialization:
* - If `dictType.embedded-entry` is 1, it clones the `key`.
* - Otherwise, it assumes ownership of the `key`.
*/
kvstore *kvstoreCreate(dictType *type, int num_dicts_bits, int flags) {
/* We can't support more than 2^16 dicts because we want to save 48 bits
* for the dict cursor, see kvstoreScan */
Expand Down Expand Up @@ -770,6 +775,17 @@ dictEntry *kvstoreDictFind(kvstore *kvs, int didx, void *key) {
return dictFind(d, key);
}

/*
* The kvstore handles `key` based on `dictType` during initialization:
* - If `dictType.embedded-entry` is 1, it clones the `key`.
* - Otherwise, it assumes ownership of the `key`.
* The caller must ensure the `key` is properly freed.
*
* kvstore current usage:
*
* 1. keyspace (db.keys) kvstore - creates a copy of the key.
* 2. expiry (db.expires), pubsub_channels and pubsubshard_channels kvstore - takes ownership of the key.
*/
dictEntry *kvstoreDictAddRaw(kvstore *kvs, int didx, void *key, dictEntry **existing) {
dict *d = createDictIfNeeded(kvs, didx);
dictEntry *ret = dictAddRaw(d, key, existing);
Expand Down
6 changes: 0 additions & 6 deletions src/kvstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ typedef dict *(kvstoreDictLUTDefragFunction)(dict *d);
void kvstoreDictLUTDefrag(kvstore *kvs, kvstoreDictLUTDefragFunction *defragfn);
void *kvstoreDictFetchValue(kvstore *kvs, int didx, const void *key);
dictEntry *kvstoreDictFind(kvstore *kvs, int didx, void *key);
/*
* The kvstore handles `key` based on `dictType` during initialization:
* - If `dictType.embedded-entry` is 1, it clones the `key`.
* - Otherwise, it assumes ownership of the `key`.
* The caller must ensure the `key` is properly freed.
*/
dictEntry *kvstoreDictAddRaw(kvstore *kvs, int didx, void *key, dictEntry **existing);
void kvstoreDictSetKey(kvstore *kvs, int didx, dictEntry *de, void *key);
void kvstoreDictSetVal(kvstore *kvs, int didx, dictEntry *de, void *val);
Expand Down

0 comments on commit 4ca43ce

Please sign in to comment.