Commit d6c61d71 authored by Vitaly Arbuzov's avatar Vitaly Arbuzov
Browse files

Resize dict in debug populate command

parent cbdedf86
......@@ -1775,6 +1775,20 @@ int expireIfNeeded(redisDb *db, robj *key, int flags) {
return 1;
}
/* Increases size of the main db to match desired number. In cluster mode resizes all individual dictionaries for slots that
* this node owns. */
void expandDb(const redisDb *db, uint64_t db_size) {
if (server.cluster_enabled) {
clusterNode *myself = server.cluster->myself;
for (int i = 0; i < db->dict_count; i++) {
/* We don't exact number of keys that would fall into each slot, but we can approximate it, assuming even distribution. */
if (clusterNodeGetSlotBit(myself, i)) dictExpand(db->dict[i], (db_size / myself->numslots));
}
} else {
dictExpand(db->dict[0], db_size);
}
}
/* -----------------------------------------------------------------------------
* API to get key arguments from commands
* ---------------------------------------------------------------------------*/
......
......@@ -716,7 +716,7 @@ NULL
if (getPositiveLongFromObjectOrReply(c, c->argv[2], &keys, NULL) != C_OK)
return;
// dictExpand(c->db->dict,keys); FIXME (vitarb) find right dicts to expand https://sim.amazon.com/issues/ELMO-63796
expandDb(c->db, keys);
long valsize = 0;
if ( c->argc == 5 && getPositiveLongFromObjectOrReply(c, c->argv[4], &valsize, NULL) != C_OK )
return;
......
......@@ -63,6 +63,9 @@ void rdbCheckSetError(const char *fmt, ...);
#ifdef __GNUC__
void rdbReportError(int corruption_error, int linenum, char *reason, ...) __attribute__ ((format (printf, 3, 4)));
void expandDb(const redisDb *db, uint64_t db_size);
#endif
void rdbReportError(int corruption_error, int linenum, char *reason, ...) {
va_list ap;
......@@ -3066,15 +3069,7 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin
goto eoferr;
if ((expires_size = rdbLoadLen(rdb,NULL)) == RDB_LENERR)
goto eoferr;
if (server.cluster_enabled) {
clusterNode *myself = server.cluster->myself;
for (int i = 0; i < db->dict_count; i++) {
/* We don't exact number of keys that would fall into each slot, but we can approximate it, assuming even distribution. */
if (clusterNodeGetSlotBit(myself, i)) dictExpand(db->dict[i], (db_size / myself->numslots));
}
} else {
dictExpand(db->dict[0], db_size);
}
expandDb(db, db_size);
dictExpand(db->expires,expires_size);
continue; /* Read next opcode. */
} else if (type == RDB_OPCODE_AUX) {
......
......@@ -3007,6 +3007,7 @@ unsigned long long int dbSize(const redisDb *db);
dict *getDict(redisDb *db, sds key);
dict *getRandomDict(redisDb *db, int shouldBeRehashing);
unsigned long dbSlots(const redisDb *db);
void expandDb(const redisDb *db, uint64_t db_size);
/* Set data type */
robj *setTypeCreate(sds 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