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

This is a followup fix for #11817
This commit is contained in:
Oran Agra 2023-05-30 10:43:25 +03:00 committed by GitHub
parent 0dfb0250e6
commit c2f1815bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -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) {
/* 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) {

View File

@ -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;

View File

@ -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);