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

Function createDumpPayload

src/cluster.cpp:5125–5156  ·  view source on GitHub ↗

Generates a DUMP-format representation of the object 'o', adding it to the * io stream pointed by 'rio'. This function can't fail. */

Source from the content-addressed store, hash-verified

5123/* Generates a DUMP-format representation of the object 'o', adding it to the
5124 * io stream pointed by 'rio'. This function can't fail. */
5125void createDumpPayload(rio *payload, robj_roptr o, robj *key) {
5126 unsigned char buf[2];
5127 uint64_t crc;
5128
5129 /* Serialize the object in an RDB-like format. It consist of an object type
5130 * byte followed by the serialized object. This is understood by RESTORE. */
5131 rioInitWithBuffer(payload,sdsempty());
5132 serverAssert(rdbSaveObjectType(payload,o));
5133 serverAssert(rdbSaveObject(payload,o,key));
5134 char szT[32];
5135 uint64_t mvcc = mvccFromObj(o);
5136 snprintf(szT, sizeof(szT), "%" PRIu64, mvcc);
5137 serverAssert(rdbSaveAuxFieldStrStr(payload,"mvcc-tstamp", szT) != -1);
5138
5139 /* Write the footer, this is how it looks like:
5140 * ----------------+---------------------+---------------+
5141 * ... RDB payload | 2 bytes RDB version | 8 bytes CRC64 |
5142 * ----------------+---------------------+---------------+
5143 * RDB version and CRC are both in little endian.
5144 */
5145
5146 /* RDB version */
5147 buf[0] = RDB_VERSION & 0xff;
5148 buf[1] = (RDB_VERSION >> 8) & 0xff;
5149 payload->io.buffer.ptr = sdscatlen(payload->io.buffer.ptr,buf,2);
5150
5151 /* CRC64 */
5152 crc = crc64(0,(unsigned char*)payload->io.buffer.ptr,
5153 sdslen(payload->io.buffer.ptr));
5154 memrev64ifbe(&crc);
5155 payload->io.buffer.ptr = sdscatlen(payload->io.buffer.ptr,&crc,8);
5156}
5157
5158/* Verify that the RDB version of the dump payload matches the one of this Redis
5159 * instance and that the checksum is ok.

Callers 4

dumpCommandFunction · 0.85
migrateCommandFunction · 0.85
serializeStoredObjectFunction · 0.85

Calls 9

rioInitWithBufferFunction · 0.85
sdsemptyFunction · 0.85
rdbSaveObjectTypeFunction · 0.85
rdbSaveObjectFunction · 0.85
mvccFromObjFunction · 0.85
rdbSaveAuxFieldStrStrFunction · 0.85
sdscatlenFunction · 0.85
crc64Function · 0.85
sdslenFunction · 0.85

Tested by

no test coverage detected