fix aof and digest code to work with dual set encoding

This commit is contained in:
Pieter Noordhuis 2010-07-02 20:42:20 +02:00
parent 96ffb2fe97
commit 2767f1c0c6
2 changed files with 28 additions and 21 deletions

View File

@ -461,20 +461,30 @@ int rewriteAppendOnlyFile(char *filename) {
redisPanic("Unknown list encoding"); redisPanic("Unknown list encoding");
} }
} else if (o->type == REDIS_SET) { } else if (o->type == REDIS_SET) {
char cmd[]="*3\r\n$4\r\nSADD\r\n";
/* Emit the SADDs needed to rebuild the set */ /* Emit the SADDs needed to rebuild the set */
dict *set = o->ptr; if (o->encoding == REDIS_ENCODING_INTSET) {
dictIterator *di = dictGetIterator(set); int ii = 0;
dictEntry *de; long long llval;
while(intsetGet(o->ptr,ii++,&llval)) {
while((de = dictNext(di)) != NULL) { if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
char cmd[]="*3\r\n$4\r\nSADD\r\n"; if (fwriteBulkObject(fp,&key) == 0) goto werr;
robj *eleobj = dictGetEntryKey(de); if (fwriteBulkLongLong(fp,llval) == 0) goto werr;
}
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr; } else if (o->encoding == REDIS_ENCODING_HT) {
if (fwriteBulkObject(fp,&key) == 0) goto werr; dictIterator *di = dictGetIterator(o->ptr);
if (fwriteBulkObject(fp,eleobj) == 0) goto werr; dictEntry *de;
while((de = dictNext(di)) != NULL) {
robj *eleobj = dictGetEntryKey(de);
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwriteBulkObject(fp,&key) == 0) goto werr;
if (fwriteBulkObject(fp,eleobj) == 0) goto werr;
}
dictReleaseIterator(di);
} else {
redisPanic("Unknown set encoding");
} }
dictReleaseIterator(di);
} else if (o->type == REDIS_ZSET) { } else if (o->type == REDIS_ZSET) {
/* Emit the ZADDs needed to rebuild the sorted set */ /* Emit the ZADDs needed to rebuild the sorted set */
zset *zs = o->ptr; zset *zs = o->ptr;

View File

@ -119,16 +119,13 @@ void computeDatasetDigest(unsigned char *final) {
} }
listTypeReleaseIterator(li); listTypeReleaseIterator(li);
} else if (o->type == REDIS_SET) { } else if (o->type == REDIS_SET) {
dict *set = o->ptr; setIterator *si = setTypeInitIterator(o);
dictIterator *di = dictGetIterator(set); robj *ele;
dictEntry *de; while((ele = setTypeNext(si)) != NULL) {
xorObjectDigest(digest,ele);
while((de = dictNext(di)) != NULL) { decrRefCount(ele);
robj *eleobj = dictGetEntryKey(de);
xorObjectDigest(digest,eleobj);
} }
dictReleaseIterator(di); setTypeReleaseIterator(si);
} else if (o->type == REDIS_ZSET) { } else if (o->type == REDIS_ZSET) {
zset *zs = o->ptr; zset *zs = o->ptr;
dictIterator *di = dictGetIterator(zs->dict); dictIterator *di = dictGetIterator(zs->dict);