summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2019-10-24 11:11:24 +0300
committerOran Agra <oran@redislabs.com>2019-12-12 08:38:09 +0200
commitb5f3247ca55424d57d77efe51bedd1fb3861c8c0 (patch)
tree5a7a98c35a46d3ef6d50cbe2c267fb99a21b6658
parent4092a75d850ab5f9ec4bc8941f6d5c28f44422e7 (diff)
downloadredis-b5f3247ca55424d57d77efe51bedd1fb3861c8c0.tar.gz
Add module API for AvoidReplicaTraffic
This is useful to tell redis and modules to try to avoid doing things that may increment the replication offset, and should be used when draining a master and waiting for replicas to be in perfect sync before a failover.
-rw-r--r--src/module.c9
-rw-r--r--src/redismodule.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c
index be64af368..bf40255e0 100644
--- a/src/module.c
+++ b/src/module.c
@@ -1880,6 +1880,14 @@ int RM_GetContextFlags(RedisModuleCtx *ctx) {
return flags;
}
+/* Returns true when the module should avoid actions that cause traffic to replicas.
+ * This is required during manual failover when waiting for the replica
+ * to be in perfect sync with the master. Modules doing background operations
+ * which are not a result of user traffic should check this flag periodically. */
+int RM_AvoidReplicaTraffic() {
+ return clientsArePaused();
+}
+
/* Change the currently selected DB. Returns an error if the id
* is out of range.
*
@@ -7392,6 +7400,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API(KeyAtPos);
REGISTER_API(GetClientId);
REGISTER_API(GetContextFlags);
+ REGISTER_API(AvoidReplicaTraffic);
REGISTER_API(PoolAlloc);
REGISTER_API(CreateDataType);
REGISTER_API(ModuleTypeSetValue);
diff --git a/src/redismodule.h b/src/redismodule.h
index 6214af7e6..7f33fc7c9 100644
--- a/src/redismodule.h
+++ b/src/redismodule.h
@@ -522,6 +522,7 @@ unsigned long long REDISMODULE_API_FUNC(RedisModule_GetClientId)(RedisModuleCtx
int REDISMODULE_API_FUNC(RedisModule_GetClientInfoById)(void *ci, uint64_t id);
int REDISMODULE_API_FUNC(RedisModule_PublishMessage)(RedisModuleCtx *ctx, RedisModuleString *channel, RedisModuleString *message);
int REDISMODULE_API_FUNC(RedisModule_GetContextFlags)(RedisModuleCtx *ctx);
+int REDISMODULE_API_FUNC(RedisModule_AvoidReplicaTraffic)();
void *REDISMODULE_API_FUNC(RedisModule_PoolAlloc)(RedisModuleCtx *ctx, size_t bytes);
RedisModuleType *REDISMODULE_API_FUNC(RedisModule_CreateDataType)(RedisModuleCtx *ctx, const char *name, int encver, RedisModuleTypeMethods *typemethods);
int REDISMODULE_API_FUNC(RedisModule_ModuleTypeSetValue)(RedisModuleKey *key, RedisModuleType *mt, void *value);
@@ -753,6 +754,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(KeyAtPos);
REDISMODULE_GET_API(GetClientId);
REDISMODULE_GET_API(GetContextFlags);
+ REDISMODULE_GET_API(AvoidReplicaTraffic);
REDISMODULE_GET_API(PoolAlloc);
REDISMODULE_GET_API(CreateDataType);
REDISMODULE_GET_API(ModuleTypeSetValue);