Diskless-load emptyDb-related fixes
1. Call emptyDb even in case of diskless-load: We want modules to get the same FLUSHDB event as disk-based replication. 2. Do not fire any module events when flushing the backups array. 3. Delete redundant call to signalFlushedDb (Called from emptyDb). Former-commit-id: aa8a3077a2d20e66e34f72f2860d0cc3daad496e
This commit is contained in:
parent
945f40c76a
commit
234e6e7b09
55
src/db.cpp
55
src/db.cpp
@ -443,7 +443,10 @@ robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o) {
|
|||||||
* DB number if we want to flush only a single Redis database number.
|
* DB number if we want to flush only a single Redis database number.
|
||||||
*
|
*
|
||||||
* Flags are be EMPTYDB_NO_FLAGS if no special flags are specified or
|
* Flags are be EMPTYDB_NO_FLAGS if no special flags are specified or
|
||||||
* EMPTYDB_ASYNC if we want the memory to be freed in a different thread
|
* 1. EMPTYDB_ASYNC if we want the memory to be freed in a different thread.
|
||||||
|
* 2. EMPTYDB_BACKUP if we want to empty the backup dictionaries created by
|
||||||
|
* disklessLoadMakeBackups. In that case we only free memory and avoid
|
||||||
|
* firing module events.
|
||||||
* and the function to return ASAP.
|
* and the function to return ASAP.
|
||||||
*
|
*
|
||||||
* On success the fuction returns the number of keys removed from the
|
* On success the fuction returns the number of keys removed from the
|
||||||
@ -451,6 +454,8 @@ robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o) {
|
|||||||
* DB number is out of range, and errno is set to EINVAL. */
|
* DB number is out of range, and errno is set to EINVAL. */
|
||||||
long long emptyDbGeneric(redisDb *dbarray, int dbnum, int flags, void(callback)(void*)) {
|
long long emptyDbGeneric(redisDb *dbarray, int dbnum, int flags, void(callback)(void*)) {
|
||||||
int async = (flags & EMPTYDB_ASYNC);
|
int async = (flags & EMPTYDB_ASYNC);
|
||||||
|
int backup = (flags & EMPTYDB_BACKUP); /* Just free the memory, nothing else */
|
||||||
|
RedisModuleFlushInfoV1 fi = {REDISMODULE_FLUSHINFO_VERSION,!async,dbnum};
|
||||||
long long removed = 0;
|
long long removed = 0;
|
||||||
|
|
||||||
if (dbnum < -1 || dbnum >= cserver.dbnum) {
|
if (dbnum < -1 || dbnum >= cserver.dbnum) {
|
||||||
@ -458,16 +463,18 @@ long long emptyDbGeneric(redisDb *dbarray, int dbnum, int flags, void(callback)(
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fire the flushdb modules event. */
|
/* Pre-flush actions */
|
||||||
RedisModuleFlushInfoV1 fi = {REDISMODULE_FLUSHINFO_VERSION,!async,dbnum};
|
if (!backup) {
|
||||||
moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
|
/* Fire the flushdb modules event. */
|
||||||
REDISMODULE_SUBEVENT_FLUSHDB_START,
|
moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
|
||||||
&fi);
|
REDISMODULE_SUBEVENT_FLUSHDB_START,
|
||||||
|
&fi);
|
||||||
|
|
||||||
/* Make sure the WATCHed keys are affected by the FLUSH* commands.
|
/* Make sure the WATCHed keys are affected by the FLUSH* commands.
|
||||||
* Note that we need to call the function while the keys are still
|
* Note that we need to call the function while the keys are still
|
||||||
* there. */
|
* there. */
|
||||||
signalFlushedDb(dbnum);
|
signalFlushedDb(dbnum);
|
||||||
|
}
|
||||||
|
|
||||||
int startdb, enddb;
|
int startdb, enddb;
|
||||||
if (dbnum == -1) {
|
if (dbnum == -1) {
|
||||||
@ -486,20 +493,24 @@ long long emptyDbGeneric(redisDb *dbarray, int dbnum, int flags, void(callback)(
|
|||||||
dbarray[j].setexpire->clear();
|
dbarray[j].setexpire->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (g_pserver->cluster_enabled) {
|
|
||||||
if (async) {
|
/* Post-flush actions */
|
||||||
slotToKeyFlushAsync();
|
if (!backup) {
|
||||||
} else {
|
if (g_pserver->cluster_enabled) {
|
||||||
slotToKeyFlush();
|
if (async) {
|
||||||
|
slotToKeyFlushAsync();
|
||||||
|
} else {
|
||||||
|
slotToKeyFlush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (dbnum == -1) flushSlaveKeysWithExpireList();
|
||||||
if (dbnum == -1) flushSlaveKeysWithExpireList();
|
|
||||||
|
|
||||||
/* Also fire the end event. Note that this event will fire almost
|
/* Also fire the end event. Note that this event will fire almost
|
||||||
* immediately after the start event if the flush is asynchronous. */
|
* immediately after the start event if the flush is asynchronous. */
|
||||||
moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
|
moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
|
||||||
REDISMODULE_SUBEVENT_FLUSHDB_END,
|
REDISMODULE_SUBEVENT_FLUSHDB_END,
|
||||||
&fi);
|
&fi);
|
||||||
|
}
|
||||||
|
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
@ -1663,8 +1663,8 @@ void disklessLoadRestoreBackups(redisDb *backup, int restore, int empty_db_flags
|
|||||||
g_pserver->db[i] = backup[i];
|
g_pserver->db[i] = backup[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Delete. */
|
/* Delete (Pass EMPTYDB_BACKUP in order to avoid firing module events) . */
|
||||||
emptyDbGeneric(backup,-1,empty_db_flags,replicationEmptyDbCallback);
|
emptyDbGeneric(backup,-1,empty_db_flags|EMPTYDB_BACKUP,replicationEmptyDbCallback);
|
||||||
for (int i=0; i<cserver.dbnum; i++) {
|
for (int i=0; i<cserver.dbnum; i++) {
|
||||||
dictRelease(backup[i].pdict);
|
dictRelease(backup[i].pdict);
|
||||||
delete backup[i].setexpire;
|
delete backup[i].setexpire;
|
||||||
@ -1855,7 +1855,6 @@ void readSyncBulkPayload(connection *conn) {
|
|||||||
/* We need to stop any AOF rewriting child before flusing and parsing
|
/* We need to stop any AOF rewriting child before flusing and parsing
|
||||||
* the RDB, otherwise we'll create a copy-on-write disaster. */
|
* the RDB, otherwise we'll create a copy-on-write disaster. */
|
||||||
if (g_pserver->aof_state != AOF_OFF) stopAppendOnly();
|
if (g_pserver->aof_state != AOF_OFF) stopAppendOnly();
|
||||||
signalFlushedDb(-1);
|
|
||||||
|
|
||||||
/* When diskless RDB loading is used by replicas, it may be configured
|
/* When diskless RDB loading is used by replicas, it may be configured
|
||||||
* in order to save the current DB instead of throwing it away,
|
* in order to save the current DB instead of throwing it away,
|
||||||
@ -1863,10 +1862,15 @@ void readSyncBulkPayload(connection *conn) {
|
|||||||
if (use_diskless_load &&
|
if (use_diskless_load &&
|
||||||
g_pserver->repl_diskless_load == REPL_DISKLESS_LOAD_SWAPDB)
|
g_pserver->repl_diskless_load == REPL_DISKLESS_LOAD_SWAPDB)
|
||||||
{
|
{
|
||||||
|
/* Create a backup of server.db[] and initialize to empty
|
||||||
|
* dictionaries */
|
||||||
diskless_load_backup = disklessLoadMakeBackups();
|
diskless_load_backup = disklessLoadMakeBackups();
|
||||||
} else {
|
|
||||||
emptyDb(-1,empty_db_flags,replicationEmptyDbCallback);
|
|
||||||
}
|
}
|
||||||
|
/* We call to emptyDb even in case of REPL_DISKLESS_LOAD_SWAPDB
|
||||||
|
* (Where disklessLoadMakeBackups left server.db empty) because we
|
||||||
|
* want to execute all the auxiliary logic of emptyDb (Namely,
|
||||||
|
* fire module events) */
|
||||||
|
emptyDb(-1,empty_db_flags,replicationEmptyDbCallback);
|
||||||
|
|
||||||
/* Before loading the DB into memory we need to delete the readable
|
/* Before loading the DB into memory we need to delete the readable
|
||||||
* handler, otherwise it will get called recursively since
|
* handler, otherwise it will get called recursively since
|
||||||
|
@ -2627,6 +2627,7 @@ robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o);
|
|||||||
|
|
||||||
#define EMPTYDB_NO_FLAGS 0 /* No flags. */
|
#define EMPTYDB_NO_FLAGS 0 /* No flags. */
|
||||||
#define EMPTYDB_ASYNC (1<<0) /* Reclaim memory in another thread. */
|
#define EMPTYDB_ASYNC (1<<0) /* Reclaim memory in another thread. */
|
||||||
|
#define EMPTYDB_BACKUP (1<<2) /* DB array is a backup for REPL_DISKLESS_LOAD_SWAPDB. */
|
||||||
long long emptyDb(int dbnum, int flags, void(callback)(void*));
|
long long emptyDb(int dbnum, int flags, void(callback)(void*));
|
||||||
long long emptyDbGeneric(redisDb *dbarray, int dbnum, int flags, void(callback)(void*));
|
long long emptyDbGeneric(redisDb *dbarray, int dbnum, int flags, void(callback)(void*));
|
||||||
void flushAllDataAndResetRDB(int flags);
|
void flushAllDataAndResetRDB(int flags);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user