Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,16 @@ robj *lookupKeyWriteOrReply(client *c, robj *key, robj *reply) {
*
* The program is aborted if the key already exists. */
void dbAdd(redisDb *db, robj *key, robj *val) {
sds copy;
sds copy = NULL;
if (server.keys_on_pmem)
copy = sdsdupPM(key->ptr);
else
copy = sdsdup(key->ptr);
int retval = dictAdd(db->dict, copy, val);
int retval = 0;
if (server.dictionary_entries_on_pmem)
retval = dictAddPM(db->dict, copy, val);
else
retval = dictAdd(db->dict, copy, val);

serverAssertWithInfo(NULL,key,retval == DICT_OK);
if (val->type == OBJ_LIST ||
Expand Down Expand Up @@ -1167,7 +1171,7 @@ void setExpire(client *c, redisDb *db, robj *key, long long when) {
/* Reuse the sds from the main dict in the expire dict */
kde = dictFind(db->dict,key->ptr);
serverAssertWithInfo(NULL,key,kde != NULL);
de = dictAddOrFind(db->expires,dictGetKey(kde));
de = dictAddOrFind(db->expires,dictGetKey(kde),server.dictionary_entries_on_pmem);
dictSetSignedIntegerVal(de,when);

int writable_slave = server.masterhost && server.repl_slave_ro == 0;
Expand Down
24 changes: 18 additions & 6 deletions src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,16 @@ static void _dictRehashStep(dict *d) {
/* Add an element to the target hash table */
int dictAdd(dict *d, void *key, void *val)
{
dictEntry *entry = dictAddRaw(d,key,NULL);
dictEntry *entry = dictAddRaw(d,key,NULL,DICT_ENTRIES_ON_DRAM);

if (!entry) return DICT_ERR;
dictSetVal(d, entry, val);
return DICT_OK;
}

int dictAddPM(dict *d, void *key, void *val)
{
dictEntry *entry = dictAddRaw(d,key,NULL,DICT_ENTRIES_ON_PMEM);

if (!entry) return DICT_ERR;
dictSetVal(d, entry, val);
Expand All @@ -289,7 +298,7 @@ int dictAdd(dict *d, void *key, void *val)
*
* If key was added, the hash entry is returned to be manipulated by the caller.
*/
dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing, int dictionaryEntriesOnPmem)
{
long index;
dictEntry *entry;
Expand All @@ -307,7 +316,10 @@ dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
* system it is more likely that recently added entries are accessed
* more frequently. */
ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];
entry = zmalloc(sizeof(*entry));
if (dictionaryEntriesOnPmem)
entry = zmalloc_pmem(sizeof(*entry));
else
entry = zmalloc(sizeof(*entry));
entry->next = ht->table[index];
ht->table[index] = entry;
ht->used++;
Expand All @@ -328,7 +340,7 @@ int dictReplace(dict *d, void *key, void *val)

/* Try to add the element. If the key
* does not exists dictAdd will succeed. */
entry = dictAddRaw(d,key,&existing);
entry = dictAddRaw(d,key,&existing,DICT_ENTRIES_ON_DRAM);
if (entry) {
dictSetVal(d, entry, val);
return 1;
Expand All @@ -352,9 +364,9 @@ int dictReplace(dict *d, void *key, void *val)
* existing key is returned.)
*
* See dictAddRaw() for more information. */
dictEntry *dictAddOrFind(dict *d, void *key) {
dictEntry *dictAddOrFind(dict *d, void *key, int dictionaryEntriesOnPmem) {
dictEntry *entry, *existing;
entry = dictAddRaw(d,key,&existing);
entry = dictAddRaw(d,key,&existing,dictionaryEntriesOnPmem);
return entry ? entry : existing;
}

Expand Down
7 changes: 5 additions & 2 deletions src/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

#define DICT_OK 0
#define DICT_ERR 1
#define DICT_ENTRIES_ON_DRAM 0
#define DICT_ENTRIES_ON_PMEM 1

/* Unused arguments generate annoying warnings... */
#define DICT_NOTUSED(V) ((void) V)
Expand Down Expand Up @@ -151,8 +153,9 @@ typedef void (dictScanBucketFunction)(void *privdata, dictEntry **bucketref);
dict *dictCreate(dictType *type, void *privDataPtr);
int dictExpand(dict *d, unsigned long size);
int dictAdd(dict *d, void *key, void *val);
dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing);
dictEntry *dictAddOrFind(dict *d, void *key);
int dictAddPM(dict *d, void *key, void *val);
dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing, int dictionaryEntriesOnPmem);
dictEntry *dictAddOrFind(dict *d, void *key, int dictionaryEntriesOnPmem);
int dictReplace(dict *d, void *key, void *val);
int dictDelete(dict *d, const void *key);
dictEntry *dictUnlink(dict *ht, const void *key);
Expand Down
2 changes: 1 addition & 1 deletion src/expire.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void rememberSlaveKeyWithExpire(redisDb *db, robj *key) {
}
if (db->id > 63) return;

dictEntry *de = dictAddOrFind(slaveKeysWithExpire,key->ptr);
dictEntry *de = dictAddOrFind(slaveKeysWithExpire,key->ptr,DICT_ENTRIES_ON_DRAM);
/* If the entry was just created, set it to a copy of the SDS string
* representing the key: we don't want to need to take those keys
* in sync with the main DB. The keys will be removed by expireSlaveKeys()
Expand Down
2 changes: 1 addition & 1 deletion src/sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3853,7 +3853,7 @@ int sentinelLeaderIncr(dict *counters, char *runid) {
dictEntry *existing, *de;
uint64_t oldval;

de = dictAddRaw(counters,runid,&existing);
de = dictAddRaw(counters,runid,&existing,DICT_ENTRIES_ON_DRAM);
if (existing) {
oldval = dictGetUnsignedIntegerVal(existing);
dictSetUnsignedIntegerVal(existing,oldval+1);
Expand Down
2 changes: 1 addition & 1 deletion src/t_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int setTypeAdd(robj *subject, sds value) {
long long llval;
if (subject->encoding == OBJ_ENCODING_HT) {
dict *ht = subject->ptr;
dictEntry *de = dictAddRaw(ht,value,NULL);
dictEntry *de = dictAddRaw(ht,value,NULL,DICT_ENTRIES_ON_DRAM);
if (de) {
dictSetKey(ht,de,sdsdup(value));
dictSetVal(ht,de,NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/t_zset.c
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
if (isnan(score)) score = 0;

/* Search for this element in the accumulating dictionary. */
de = dictAddRaw(accumulator,zuiSdsFromValue(&zval),&existing);
de = dictAddRaw(accumulator,zuiSdsFromValue(&zval),&existing,DICT_ENTRIES_ON_DRAM);
/* If we don't have it, we need to create a new entry. */
if (!existing) {
tmp = zuiNewSdsFromValue(&zval);
Expand Down