Unverified Commit c2f1815b authored by Oran Agra's avatar Oran Agra Committed by GitHub
Browse files

Avoid trying to trim string loaded from RDB file. (#12241)

This is a followup fix for #11817
parent 0dfb0250
...@@ -629,7 +629,7 @@ void trimStringObjectIfNeeded(robj *o, int trim_small_values) { ...@@ -629,7 +629,7 @@ void trimStringObjectIfNeeded(robj *o, int trim_small_values) {
} }
/* Try to encode a string object in order to save space */ /* Try to encode a string object in order to save space */
robj *tryObjectEncoding(robj *o) { robj *tryObjectEncodingEx(robj *o, int try_trim) {
long value; long value;
sds s = o->ptr; sds s = o->ptr;
size_t len; size_t len;
...@@ -694,12 +694,17 @@ robj *tryObjectEncoding(robj *o) { ...@@ -694,12 +694,17 @@ robj *tryObjectEncoding(robj *o) {
/* We can't encode the object... /* We can't encode the object...
* Do the last try, and at least optimize the SDS string inside */ * Do the last try, and at least optimize the SDS string inside */
trimStringObjectIfNeeded(o, 0); if (try_trim)
trimStringObjectIfNeeded(o, 0);
/* Return the original object. */ /* Return the original object. */
return o; return o;
} }
robj *tryObjectEncoding(robj *o) {
return tryObjectEncodingEx(o, 1);
}
/* Get a decoded version of an encoded object (returned as a new object). /* Get a decoded version of an encoded object (returned as a new object).
* If the object is already raw-encoded just increment the ref count. */ * If the object is already raw-encoded just increment the ref count. */
robj *getDecodedObject(robj *o) { robj *getDecodedObject(robj *o) {
......
...@@ -1844,7 +1844,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { ...@@ -1844,7 +1844,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) {
if (rdbtype == RDB_TYPE_STRING) { if (rdbtype == RDB_TYPE_STRING) {
/* Read string value */ /* Read string value */
if ((o = rdbLoadEncodedStringObject(rdb)) == NULL) return NULL; if ((o = rdbLoadEncodedStringObject(rdb)) == NULL) return NULL;
o = tryObjectEncoding(o); o = tryObjectEncodingEx(o, 0);
} else if (rdbtype == RDB_TYPE_LIST) { } else if (rdbtype == RDB_TYPE_LIST) {
/* Read list value */ /* Read list value */
if ((len = rdbLoadLen(rdb,NULL)) == RDB_LENERR) return NULL; if ((len = rdbLoadLen(rdb,NULL)) == RDB_LENERR) return NULL;
......
...@@ -2738,6 +2738,7 @@ robj *dupStringObject(const robj *o); ...@@ -2738,6 +2738,7 @@ robj *dupStringObject(const robj *o);
int isSdsRepresentableAsLongLong(sds s, long long *llval); int isSdsRepresentableAsLongLong(sds s, long long *llval);
int isObjectRepresentableAsLongLong(robj *o, long long *llongval); int isObjectRepresentableAsLongLong(robj *o, long long *llongval);
robj *tryObjectEncoding(robj *o); robj *tryObjectEncoding(robj *o);
robj *tryObjectEncodingEx(robj *o, int try_trim);
robj *getDecodedObject(robj *o); robj *getDecodedObject(robj *o);
size_t stringObjectLen(robj *o); size_t stringObjectLen(robj *o);
robj *createStringObjectFromLongLong(long long value); robj *createStringObjectFromLongLong(long long value);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment