Skip to content

Commit a7ac847

Browse files
committed
[fix] propagate embedded gtidCommand
1 parent e956bd8 commit a7ac847

5 files changed

Lines changed: 53 additions & 4 deletions

File tree

src/server.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,6 +3075,10 @@ void initServer(void) {
30753075
server.gtid_offset_at_multi = -1;
30763076
server.gtid_pending_multi_dbid = -1;
30773077
server.gtid_pending_multi_offset = -1;
3078+
server.gtid_embedded_uuid = NULL;
3079+
server.gtid_embedded_uuid_len = 0;
3080+
server.gtid_embedded_gno = 0;
3081+
server.gtid_embedded_dbid = -1;
30783082
server.busy_module_yield_flags = BUSY_MODULE_YIELD_NONE;
30793083
server.busy_module_yield_reply = NULL;
30803084
server.client_pause_in_transaction = 0;
@@ -3811,8 +3815,13 @@ static void gtidPreparePropagateState(int transaction) {
38113815
* multiple separated commands. Note that alsoPropagate() is not affected
38123816
* by CLIENT_PREVENT_PROP flag. */
38133817
static void propagatePendingCommands(void) {
3814-
if (server.also_propagate.numops == 0)
3818+
if (server.also_propagate.numops == 0) {
3819+
serverAssert(server.gtid_embedded_uuid == NULL);
3820+
serverAssert(server.gtid_embedded_uuid_len == 0);
3821+
serverAssert(server.gtid_embedded_gno == 0);
3822+
serverAssert(server.gtid_embedded_dbid == -1);
38153823
return;
3824+
}
38163825

38173826
int j;
38183827
redisOp *rop;
@@ -3866,6 +3875,7 @@ static void propagatePendingCommands(void) {
38663875
}
38673876

38683877
redisOpArrayFree(&server.also_propagate);
3878+
serverGtidEmbeddedClear();
38693879
}
38703880

38713881
/* Performs operations that should be performed after an execution unit ends.
@@ -4115,7 +4125,7 @@ void call(client *c, int flags) {
41154125
* Also, module commands take care of themselves */
41164126
if (flags & CMD_CALL_PROPAGATE &&
41174127
(c->flags & CLIENT_PREVENT_PROP) != CLIENT_PREVENT_PROP &&
4118-
c->cmd->proc != execCommand &&
4128+
c->cmd->proc != execCommand && c->cmd->proc != gtidCommand &&
41194129
!(c->cmd->flags & CMD_MODULE))
41204130
{
41214131
int propagate_flags = PROPAGATE_NONE;

src/server.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,14 @@ struct redisServer {
24122412
long long gtid_offset_at_multi;
24132413
int gtid_pending_multi_dbid;
24142414
long long gtid_pending_multi_offset;
2415+
/* Caller-supplied GTID identity for the current GTID-wrapped command.
2416+
* Set by gtidCommand(), consumed and cleared by propagatePendingCommands()
2417+
* so that propagateArgsPrepareToFeed() rewrites ops
2418+
* with the caller's uuid/gno instead of auto-allocating a new one. */
2419+
char *gtid_embedded_uuid;
2420+
size_t gtid_embedded_uuid_len;
2421+
gno_t gtid_embedded_gno; /* 0 means "not set" (gno starts from 1) */
2422+
int gtid_embedded_dbid;
24152423
gtidSeq *gtid_seq;
24162424
long long gtid_xsync_fullresync_indicator;
24172425
gtidInitialInfo gtid_initial[1];

tests/gtid/aof.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ test "aof" {
155155
{gtid * 9 PEXPIREAT k2 *}
156156
{gtid * 9 SET k3 y PXAT *}
157157
{gtid * 9 set k4 y}
158-
{gtid * 9 expire k4 *}
158+
{gtid A:1 9 PEXPIREAT k4 *}
159159
{gtid * 9 set k5 y}
160160
}
161161
}

tests/modules/propagate.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,27 @@ int propagateTestSimpleCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in
235235
return REDISMODULE_OK;
236236
}
237237

238+
int propagateTestSingleCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
239+
{
240+
REDISMODULE_NOT_USED(argv);
241+
REDISMODULE_NOT_USED(argc);
242+
243+
/* Replicate a single command - no MULTI/EXEC wrapping. */
244+
RedisModule_Replicate(ctx,"INCR","c","single-counter");
245+
RedisModule_ReplyWithSimpleString(ctx,"OK");
246+
return REDISMODULE_OK;
247+
}
248+
249+
int propagateTestNoreplicateCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
250+
{
251+
REDISMODULE_NOT_USED(argv);
252+
REDISMODULE_NOT_USED(argc);
253+
254+
/* Do not call RM_Replicate - no propagation expected. */
255+
RedisModule_ReplyWithSimpleString(ctx,"OK");
256+
return REDISMODULE_OK;
257+
}
258+
238259
int propagateTestMixedCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
239260
{
240261
REDISMODULE_NOT_USED(argv);
@@ -370,6 +391,16 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
370391
"",1,1,1) == REDISMODULE_ERR)
371392
return REDISMODULE_ERR;
372393

394+
if (RedisModule_CreateCommand(ctx,"propagate-test.single",
395+
propagateTestSingleCommand,
396+
"",1,1,1) == REDISMODULE_ERR)
397+
return REDISMODULE_ERR;
398+
399+
if (RedisModule_CreateCommand(ctx,"propagate-test.noreplicate",
400+
propagateTestNoreplicateCommand,
401+
"",1,1,1) == REDISMODULE_ERR)
402+
return REDISMODULE_ERR;
403+
373404
if (RedisModule_CreateCommand(ctx,"propagate-test.mixed",
374405
propagateTestMixedCommand,
375406
"write",1,1,1) == REDISMODULE_ERR)

0 commit comments

Comments
 (0)