diff --git a/src/object.c b/src/object.c index 7ea0d157..74f6ed75 100644 --- a/src/object.c +++ b/src/object.c @@ -465,6 +465,7 @@ unsigned long estimateObjectIdleTime(robj *o) { robj *objectCommandLookup(redisClient *c, robj *key) { dictEntry *de; + if (server.vm_enabled) lookupKeyRead(c->db,key); if ((de = dictFind(c->db->dict,key->ptr)) == NULL) return NULL; return (robj*) dictGetEntryVal(de); } diff --git a/src/rdb.c b/src/rdb.c index 1117250e..2ddbafa4 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -376,6 +376,20 @@ off_t rdbSavedObjectPages(robj *o) { return (bytes+(server.vm_page_size-1))/server.vm_page_size; } +int getObjectSaveType(robj *o) { + /* Fix the type id for specially encoded data types */ + if (o->type == REDIS_HASH && o->encoding == REDIS_ENCODING_ZIPMAP) + return REDIS_HASH_ZIPMAP; + else if (o->type == REDIS_LIST && o->encoding == REDIS_ENCODING_ZIPLIST) + return REDIS_LIST_ZIPLIST; + else if (o->type == REDIS_SET && o->encoding == REDIS_ENCODING_INTSET) + return REDIS_SET_INTSET; + else if (o->type == REDIS_ZSET && o->encoding == REDIS_ENCODING_ZIPLIST) + return REDIS_ZSET_ZIPLIST; + else + return o->type; +} + /* Save the DB on disk. Return REDIS_ERR on error, REDIS_OK on success */ int rdbSave(char *filename) { dictIterator *di = NULL; @@ -432,17 +446,8 @@ int rdbSave(char *filename) { * handling if the value is swapped out. */ if (!server.vm_enabled || o->storage == REDIS_VM_MEMORY || o->storage == REDIS_VM_SWAPPING) { - int otype = o->type; + int otype = getObjectSaveType(o); - /* Fix the type id for specially encoded data types */ - if (otype == REDIS_HASH && o->encoding == REDIS_ENCODING_ZIPMAP) - otype = REDIS_HASH_ZIPMAP; - else if (otype == REDIS_LIST && - o->encoding == REDIS_ENCODING_ZIPLIST) - otype = REDIS_LIST_ZIPLIST; - else if (otype == REDIS_SET && - o->encoding == REDIS_ENCODING_INTSET) - otype = REDIS_SET_INTSET; /* Save type, key, value */ if (rdbSaveType(fp,otype) == -1) goto werr; if (rdbSaveStringObject(fp,&key) == -1) goto werr; @@ -453,7 +458,8 @@ int rdbSave(char *filename) { /* Get a preview of the object in memory */ po = vmPreviewObject(o); /* Save type, key, value */ - if (rdbSaveType(fp,po->type) == -1) goto werr; + if (rdbSaveType(fp,getObjectSaveType(po)) == -1) + goto werr; if (rdbSaveStringObject(fp,&key) == -1) goto werr; if (rdbSaveObject(fp,po) == -1) goto werr; /* Remove the loaded object from memory */ diff --git a/src/redis.h b/src/redis.h index 6e87d08c..6773ea44 100644 --- a/src/redis.h +++ b/src/redis.h @@ -770,6 +770,7 @@ off_t rdbSavedObjectLen(robj *o); off_t rdbSavedObjectPages(robj *o); robj *rdbLoadObject(int type, FILE *fp); void backgroundSaveDoneHandler(int statloc); +int getObjectSaveType(robj *o); /* AOF persistence */ void flushAppendOnlyFile(void); diff --git a/src/vm.c b/src/vm.c index 8e7667d5..a46fed7d 100644 --- a/src/vm.c +++ b/src/vm.c @@ -30,12 +30,12 @@ /* Create a VM pointer object. This kind of objects are used in place of * values in the key -> value hash table, for swapped out objects. */ -vmpointer *createVmPointer(int vtype) { +vmpointer *createVmPointer(robj *o) { vmpointer *vp = zmalloc(sizeof(vmpointer)); vp->type = REDIS_VMPOINTER; vp->storage = REDIS_VM_SWAPPED; - vp->vtype = vtype; + vp->vtype = getObjectSaveType(o); return vp; } @@ -272,7 +272,7 @@ vmpointer *vmSwapObjectBlocking(robj *val) { if (vmFindContiguousPages(&page,pages) == REDIS_ERR) return NULL; if (vmWriteObjectOnSwap(val,page) == REDIS_ERR) return NULL; - vp = createVmPointer(val->type); + vp = createVmPointer(val); vp->page = page; vp->usedpages = pages; decrRefCount(val); /* Deallocate the object from memory. */ @@ -663,7 +663,7 @@ void vmThreadedIOCompletedJob(aeEventLoop *el, int fd, void *privdata, printf("val->ptr: %s\n",(char*)j->val->ptr); } redisAssert(j->val->storage == REDIS_VM_SWAPPING); - vp = createVmPointer(j->val->type); + vp = createVmPointer(j->val); vp->page = j->page; vp->usedpages = j->pages; dictGetEntryVal(de) = vp;