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

Function rdbSaveInfoAuxFields

src/rdb.cpp:1203–1238  ·  view source on GitHub ↗

Save a few default AUX fields with information about the RDB generated. */

Source from the content-addressed store, hash-verified

1201
1202/* Save a few default AUX fields with information about the RDB generated. */
1203int rdbSaveInfoAuxFields(rio *rdb, int rdbflags, rdbSaveInfo *rsi) {
1204 int redis_bits = (sizeof(void*) == 8) ? 64 : 32;
1205 int aof_preamble = (rdbflags & RDBFLAGS_AOF_PREAMBLE) != 0;
1206
1207 /* Add a few fields about the state when the RDB was created. */
1208 if (rdbSaveAuxFieldStrStr(rdb,"redis-ver",KEYDB_REAL_VERSION) == -1) return -1;
1209 if (rdbSaveAuxFieldStrInt(rdb,"redis-bits",redis_bits) == -1) return -1;
1210 if (rdbSaveAuxFieldStrInt(rdb,"ctime",time(NULL)) == -1) return -1;
1211 if (rdbSaveAuxFieldStrInt(rdb,"used-mem",zmalloc_used_memory()) == -1) return -1;
1212
1213 /* Handle saving options that generate aux fields. */
1214 if (rsi) {
1215 if (rdbSaveAuxFieldStrInt(rdb,"repl-stream-db",rsi->repl_stream_db)
1216 == -1) return -1;
1217 if (rdbSaveAuxFieldStrStr(rdb,"repl-id",rsi->repl_id)
1218 == -1) return -1;
1219 if (rdbSaveAuxFieldStrInt(rdb,"repl-offset",rsi->master_repl_offset)
1220 == -1) return -1;
1221 if (g_pserver->fActiveReplica) {
1222 sdsstring val = sdsstring(sdsempty());
1223
1224 for (auto &msi : rsi->vecmastersaveinfo) {
1225 if (msi.masterhost == nullptr)
1226 continue;
1227 val = val.catfmt("%s:%I:%s:%i:%i;", msi.master_replid,
1228 msi.master_initial_offset,
1229 msi.masterhost.get(),
1230 msi.masterport,
1231 msi.selected_db);
1232 }
1233 if (rdbSaveAuxFieldStrStr(rdb, "repl-masters",val.get()) == -1) return -1;
1234 }
1235 }
1236 if (rdbSaveAuxFieldStrInt(rdb,"aof-preamble",aof_preamble) == -1) return -1;
1237 return 1;
1238}
1239
1240int saveKey(rio *rdb, int flags, size_t *processed, const char *keystr, robj_roptr o)
1241{

Callers 1

rdbSaveRioFunction · 0.85

Calls 7

rdbSaveAuxFieldStrStrFunction · 0.85
rdbSaveAuxFieldStrIntFunction · 0.85
zmalloc_used_memoryFunction · 0.85
sdsstringClass · 0.85
sdsemptyFunction · 0.85
catfmtMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected