mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
Lazyfree: Hash converted to use plain SDS WIP 5.
This commit is contained in:
parent
36be34bb87
commit
97ba4e3886
56
src/rdb.c
56
src/rdb.c
@ -651,16 +651,17 @@ ssize_t rdbSaveObject(rio *rdb, robj *o) {
|
|||||||
nwritten += n;
|
nwritten += n;
|
||||||
|
|
||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
robj *key = dictGetKey(de);
|
sds field = dictGetKey(de);
|
||||||
robj *val = dictGetVal(de);
|
sds value = dictGetVal(de);
|
||||||
|
|
||||||
if ((n = rdbSaveStringObject(rdb,key)) == -1) return -1;
|
if ((n = rdbSaveRawString(rdb,(unsigned char*)field,
|
||||||
|
sdslen(field))) == -1) return -1;
|
||||||
nwritten += n;
|
nwritten += n;
|
||||||
if ((n = rdbSaveStringObject(rdb,val)) == -1) return -1;
|
if ((n = rdbSaveRawString(rdb,(unsigned char*)value,
|
||||||
|
sdslen(value))) == -1) return -1;
|
||||||
nwritten += n;
|
nwritten += n;
|
||||||
}
|
}
|
||||||
dictReleaseIterator(di);
|
dictReleaseIterator(di);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
serverPanic("Unknown hash encoding");
|
serverPanic("Unknown hash encoding");
|
||||||
}
|
}
|
||||||
@ -1044,6 +1045,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
|
|||||||
} else if (rdbtype == RDB_TYPE_HASH) {
|
} else if (rdbtype == RDB_TYPE_HASH) {
|
||||||
size_t len;
|
size_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
sds field, value;
|
||||||
|
|
||||||
len = rdbLoadLen(rdb, NULL);
|
len = rdbLoadLen(rdb, NULL);
|
||||||
if (len == RDB_LENERR) return NULL;
|
if (len == RDB_LENERR) return NULL;
|
||||||
@ -1056,46 +1058,40 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
|
|||||||
|
|
||||||
/* Load every field and value into the ziplist */
|
/* Load every field and value into the ziplist */
|
||||||
while (o->encoding == OBJ_ENCODING_ZIPLIST && len > 0) {
|
while (o->encoding == OBJ_ENCODING_ZIPLIST && len > 0) {
|
||||||
robj *field, *value;
|
|
||||||
|
|
||||||
len--;
|
len--;
|
||||||
/* Load raw strings */
|
/* Load raw strings */
|
||||||
field = rdbLoadStringObject(rdb);
|
if ((field = rdbGenericLoadStringObject(rdb,RDB_LOAD_SDS)) == NULL)
|
||||||
if (field == NULL) return NULL;
|
return NULL;
|
||||||
serverAssert(sdsEncodedObject(field));
|
if ((value = rdbGenericLoadStringObject(rdb,RDB_LOAD_SDS)) == NULL)
|
||||||
value = rdbLoadStringObject(rdb);
|
return NULL;
|
||||||
if (value == NULL) return NULL;
|
|
||||||
serverAssert(sdsEncodedObject(value));
|
|
||||||
|
|
||||||
/* Add pair to ziplist */
|
/* Add pair to ziplist */
|
||||||
o->ptr = ziplistPush(o->ptr, field->ptr, sdslen(field->ptr), ZIPLIST_TAIL);
|
o->ptr = ziplistPush(o->ptr, (unsigned char*)field,
|
||||||
o->ptr = ziplistPush(o->ptr, value->ptr, sdslen(value->ptr), ZIPLIST_TAIL);
|
sdslen(field), ZIPLIST_TAIL);
|
||||||
|
o->ptr = ziplistPush(o->ptr, (unsigned char*)value,
|
||||||
|
sdslen(value), ZIPLIST_TAIL);
|
||||||
|
|
||||||
/* Convert to hash table if size threshold is exceeded */
|
/* Convert to hash table if size threshold is exceeded */
|
||||||
if (sdslen(field->ptr) > server.hash_max_ziplist_value ||
|
if (sdslen(field) > server.hash_max_ziplist_value ||
|
||||||
sdslen(value->ptr) > server.hash_max_ziplist_value)
|
sdslen(value) > server.hash_max_ziplist_value)
|
||||||
{
|
{
|
||||||
decrRefCount(field);
|
sdsfree(field);
|
||||||
decrRefCount(value);
|
sdsfree(value);
|
||||||
hashTypeConvert(o, OBJ_ENCODING_HT);
|
hashTypeConvert(o, OBJ_ENCODING_HT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
decrRefCount(field);
|
sdsfree(field);
|
||||||
decrRefCount(value);
|
sdsfree(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load remaining fields and values into the hash table */
|
/* Load remaining fields and values into the hash table */
|
||||||
while (o->encoding == OBJ_ENCODING_HT && len > 0) {
|
while (o->encoding == OBJ_ENCODING_HT && len > 0) {
|
||||||
robj *field, *value;
|
|
||||||
|
|
||||||
len--;
|
len--;
|
||||||
/* Load encoded strings */
|
/* Load encoded strings */
|
||||||
field = rdbLoadEncodedStringObject(rdb);
|
if ((field = rdbGenericLoadStringObject(rdb,RDB_LOAD_SDS)) == NULL)
|
||||||
if (field == NULL) return NULL;
|
return NULL;
|
||||||
value = rdbLoadEncodedStringObject(rdb);
|
if ((value = rdbGenericLoadStringObject(rdb,RDB_LOAD_SDS)) == NULL)
|
||||||
if (value == NULL) return NULL;
|
return NULL;
|
||||||
|
|
||||||
field = tryObjectEncoding(field);
|
|
||||||
value = tryObjectEncoding(value);
|
|
||||||
|
|
||||||
/* Add pair to hash table */
|
/* Add pair to hash table */
|
||||||
ret = dictAdd((dict*)o->ptr, field, value);
|
ret = dictAdd((dict*)o->ptr, field, value);
|
||||||
|
@ -567,7 +567,7 @@ void hincrbyfloatCommand(client *c) {
|
|||||||
if (hashTypeGetValue(o,c->argv[2]->ptr,&vstr,&vlen,&ll) == C_OK) {
|
if (hashTypeGetValue(o,c->argv[2]->ptr,&vstr,&vlen,&ll) == C_OK) {
|
||||||
if (vstr) {
|
if (vstr) {
|
||||||
if (string2d((char*)vstr,vlen,&value) == 0) {
|
if (string2d((char*)vstr,vlen,&value) == 0) {
|
||||||
addReplyError(c,"hash value is not an integer");
|
addReplyError(c,"hash value is not a float");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -521,12 +521,12 @@ int ld2string(char *buf, size_t len, long double value, int humanfriendly) {
|
|||||||
if (l+1 > len) return 0; /* No room. */
|
if (l+1 > len) return 0; /* No room. */
|
||||||
/* Now remove trailing zeroes after the '.' */
|
/* Now remove trailing zeroes after the '.' */
|
||||||
if (strchr(buf,'.') != NULL) {
|
if (strchr(buf,'.') != NULL) {
|
||||||
char *p = buf+len-1;
|
char *p = buf+l-1;
|
||||||
while(*p == '0') {
|
while(*p == '0') {
|
||||||
p--;
|
p--;
|
||||||
len--;
|
l--;
|
||||||
}
|
}
|
||||||
if (*p == '.') len--;
|
if (*p == '.') l--;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
l = snprintf(buf,len,"%.17Lg", value);
|
l = snprintf(buf,len,"%.17Lg", value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user