MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / rdbGenericLoadStringObject

Function rdbGenericLoadStringObject

src/rdb.cpp:517–569  ·  view source on GitHub ↗

Load a string object from an RDB file according to flags: * * RDB_LOAD_NONE (no flags): load an RDB object, unencoded. * RDB_LOAD_ENC: If the returned type is a Redis object, try to * encode it in a special way to be more memory * efficient. When this flag is passed the function * no longer guarantees that ptrFromObj(obj) is an SDS string. * RDB_LOA

Source from the content-addressed store, hash-verified

515 * On I/O error NULL is returned.
516 */
517void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
518 int encode = flags & RDB_LOAD_ENC;
519 int plain = flags & RDB_LOAD_PLAIN;
520 int sds = flags & RDB_LOAD_SDS;
521 int isencoded;
522 unsigned long long len;
523
524 len = rdbLoadLen(rdb,&isencoded);
525 if (len == RDB_LENERR) return NULL;
526
527 if (isencoded) {
528 switch(len) {
529 case RDB_ENC_INT8:
530 case RDB_ENC_INT16:
531 case RDB_ENC_INT32:
532 return rdbLoadIntegerObject(rdb,len,flags,lenptr);
533 case RDB_ENC_LZF:
534 return rdbLoadLzfStringObject(rdb,flags,lenptr);
535 default:
536 rdbReportCorruptRDB("Unknown RDB string encoding type %llu",len);
537 return NULL;
538 }
539 }
540
541 if (plain || sds) {
542 void *buf = plain ? ztrymalloc(len) : sdstrynewlen(SDS_NOINIT,len);
543 if (!buf) {
544 serverLog(g_pserver->loading? LL_WARNING: LL_VERBOSE, "rdbGenericLoadStringObject failed allocating %llu bytes", len);
545 return NULL;
546 }
547 if (lenptr) *lenptr = len;
548 if (len && rioRead(rdb,buf,len) == 0) {
549 if (plain)
550 zfree(buf);
551 else
552 sdsfree((char*)buf);
553 return NULL;
554 }
555 return buf;
556 } else {
557 robj *o = encode ? tryCreateStringObject(SDS_NOINIT,len) :
558 tryCreateRawStringObject(SDS_NOINIT,len);
559 if (!o) {
560 serverLog(g_pserver->loading? LL_WARNING: LL_VERBOSE, "rdbGenericLoadStringObject failed allocating %llu bytes", len);
561 return NULL;
562 }
563 if (len && rioRead(rdb,ptrFromObj(o),len) == 0) {
564 decrRefCount(o);
565 return NULL;
566 }
567 return o;
568 }
569}
570
571sdsstring rdbLoadString(rio *rdb){
572 sds str = (sds)rdbGenericLoadStringObject(rdb,RDB_LOAD_SDS,NULL);

Callers 7

rdbLoadStringFunction · 0.85
rdbLoadStringObjectFunction · 0.85
rdbLoadCheckModuleValueFunction · 0.85
rdbLoadObjectFunction · 0.85
rdbLoadRioFunction · 0.85
moduleLoadStringFunction · 0.85

Calls 13

rdbLoadLenFunction · 0.85
rdbLoadIntegerObjectFunction · 0.85
rdbLoadLzfStringObjectFunction · 0.85
ztrymallocFunction · 0.85
sdstrynewlenFunction · 0.85
serverLogFunction · 0.85
rioReadFunction · 0.85
zfreeFunction · 0.85
sdsfreeFunction · 0.85
tryCreateStringObjectFunction · 0.85
tryCreateRawStringObjectFunction · 0.85
ptrFromObjFunction · 0.85

Tested by

no test coverage detected