Unverified Commit 372ea218 authored by Binbin's avatar Binbin Committed by GitHub
Browse files

Update comment around propagateDeletion (#12687)



Fix some outdated comments and add comment for moduleNotifyKeyspaceEvent
we added in #11084 since it seems a bit implicit.

---------
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
parent 3fac869f
...@@ -7558,6 +7558,9 @@ unsigned int delKeysInSlot(unsigned int hashslot) { ...@@ -7558,6 +7558,9 @@ unsigned int delKeysInSlot(unsigned int hashslot) {
dbDelete(&server.db[0], key); dbDelete(&server.db[0], key);
propagateDeletion(&server.db[0], key, server.lazyfree_lazy_server_del); propagateDeletion(&server.db[0], key, server.lazyfree_lazy_server_del);
signalModifiedKey(NULL, &server.db[0], key); signalModifiedKey(NULL, &server.db[0], key);
/* The keys are not actually logically deleted from the database, just moved to another node.
* The modules needs to know that these keys are no longer available locally, so just send the
* keyspace notification to the modules, but not to clients. */
moduleNotifyKeyspaceEvent(NOTIFY_GENERIC, "del", key, server.db[0].id); moduleNotifyKeyspaceEvent(NOTIFY_GENERIC, "del", key, server.db[0].id);
postExecutionUnitOperations(); postExecutionUnitOperations();
decrRefCount(key); decrRefCount(key);
......
...@@ -2012,23 +2012,24 @@ void deleteExpiredKeyAndPropagate(redisDb *db, robj *keyobj) { ...@@ -2012,23 +2012,24 @@ void deleteExpiredKeyAndPropagate(redisDb *db, robj *keyobj) {
server.stat_expiredkeys++; server.stat_expiredkeys++;
} }
/* Propagate expires into slaves and the AOF file. /* Propagate an implicit key deletion into replicas and the AOF file.
* When a key expires in the master, a DEL operation for this key is sent * When a key was deleted in the master by eviction, expiration or a similar
* to all the slaves and the AOF file if enabled. * mechanism a DEL/UNLINK operation for this key is sent
* * to all the replicas and the AOF file if enabled.
* This way the key expiry is centralized in one place, and since both *
* AOF and the master->slave link guarantee operation ordering, everything * This way the key deletion is centralized in one place, and since both
* will be consistent even if we allow write operations against expiring * AOF and the replication link guarantee operation ordering, everything
* will be consistent even if we allow write operations against deleted
* keys. * keys.
* *
* This function may be called from: * This function may be called from:
* 1. Within call(): Example: Lazy-expire on key access. * 1. Within call(): Example: Lazy-expire on key access.
* In this case the caller doesn't have to do anything * In this case the caller doesn't have to do anything
* because call() handles server.also_propagate(); or * because call() handles server.also_propagate(); or
* 2. Outside of call(): Example: Active-expire, eviction. * 2. Outside of call(): Example: Active-expire, eviction, slot ownership changed.
* In this the caller must remember to call * In this the caller must remember to call
* postExecutionUnitOperations, preferably just after a * postExecutionUnitOperations, preferably just after a
* single deletion batch, so that DELs will NOT be wrapped * single deletion batch, so that DEL/UNLINK will NOT be wrapped
* in MULTI/EXEC */ * in MULTI/EXEC */
void propagateDeletion(redisDb *db, robj *key, int lazy) { void propagateDeletion(redisDb *db, robj *key, int lazy) {
robj *argv[2]; robj *argv[2];
...@@ -2038,7 +2039,7 @@ void propagateDeletion(redisDb *db, robj *key, int lazy) { ...@@ -2038,7 +2039,7 @@ void propagateDeletion(redisDb *db, robj *key, int lazy) {
incrRefCount(argv[0]); incrRefCount(argv[0]);
incrRefCount(argv[1]); incrRefCount(argv[1]);
/* If the master decided to expire a key we must propagate it to replicas no matter what.. /* If the master decided to delete a key we must propagate it to replicas no matter what.
* Even if module executed a command without asking for propagation. */ * Even if module executed a command without asking for propagation. */
int prev_replication_allowed = server.replication_allowed; int prev_replication_allowed = server.replication_allowed;
server.replication_allowed = 1; server.replication_allowed = 1;
......
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