Repository navigation
MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS - #2160
Conversation
When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it.
| // LABELS greedily consumes every token after it as a label/value pair, so it must | ||
| // stay the last clause; insert TIMESTAMP before it instead of after, or a create-on- | ||
| // write TS.INCRBY/TS.DECRBY with LABELS would replicate a bogus "TIMESTAMP" label. | ||
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv, argc); | ||
| if (labelsLoc == -1) { | ||
| const size_t replArgc = argc - 1; | ||
| RedisModule_Replicate( | ||
| ctx, replCmd, "vcl", argv + 1, replArgc, "TIMESTAMP", currentUpdatedTime); | ||
| } else { | ||
| const size_t preArgc = labelsLoc - 1; | ||
| const size_t postArgc = argc - labelsLoc; | ||
| RedisModule_Replicate(ctx, | ||
| replCmd, | ||
| "vclv", | ||
| argv + 1, // start after the command name | ||
| preArgc, | ||
| "TIMESTAMP", | ||
| currentUpdatedTime, | ||
| argv + labelsLoc, // the LABELS clause, unchanged | ||
| postArgc); | ||
| } |
There was a problem hiding this comment.
A key literally named labels makes the replicated command lose its key name.
RMUtil_ArgIndex (deps/RedisModulesSDK/rmutil/util.c:35) scans from offset = 0 and compares case-insensitively, so it happily matches the key name at argv[1]. For TS.INCRBY labels 1:
labelsLoc == 1→preArgc == 0,postArgc == argc - 1- replicated command is
TS.INCRBY TIMESTAMP <ts> labels 1
The replica/AOF then parses argv[1] = TIMESTAMP as the key name, argv[2] = <ts> as the increment (a valid double, so no error), and RMUtil_ArgIndex("TIMESTAMP", ...) finds index 1 so <ts> is also taken as the timestamp. Result: a bogus key named TIMESTAMP holding ~1.75e12, and the real labels key never exists on the replica at all. parseLabelsFromArgs truncates the odd trailing token ((argc - first)/2), so nothing errors — it fails silently. The old append form got this key name right.
Rather than special-casing LABELS, insert TIMESTAMP <ts> at the fixed position right after <value>. That is correct for any trailing clause (present or future), needs no argv scan, and collapses both branches into one call — argc >= 3 is already guaranteed by the arity check above:
| // LABELS greedily consumes every token after it as a label/value pair, so it must | |
| // stay the last clause; insert TIMESTAMP before it instead of after, or a create-on- | |
| // write TS.INCRBY/TS.DECRBY with LABELS would replicate a bogus "TIMESTAMP" label. | |
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv, argc); | |
| if (labelsLoc == -1) { | |
| const size_t replArgc = argc - 1; | |
| RedisModule_Replicate( | |
| ctx, replCmd, "vcl", argv + 1, replArgc, "TIMESTAMP", currentUpdatedTime); | |
| } else { | |
| const size_t preArgc = labelsLoc - 1; | |
| const size_t postArgc = argc - labelsLoc; | |
| RedisModule_Replicate(ctx, | |
| replCmd, | |
| "vclv", | |
| argv + 1, // start after the command name | |
| preArgc, | |
| "TIMESTAMP", | |
| currentUpdatedTime, | |
| argv + labelsLoc, // the LABELS clause, unchanged | |
| postArgc); | |
| } | |
| // TIMESTAMP must go *before* a trailing LABELS clause: LABELS greedily consumes | |
| // every token after it, so appending would replicate a bogus "TIMESTAMP <ts>" | |
| // label pair. Index 3 is always just past <key> <value>, so every optional | |
| // clause (LABELS included) keeps its original order, and this stays correct for | |
| // any future greedy trailing clause. | |
| const size_t preArgc = 2; // key + value | |
| const size_t postArgc = argc - 3; // every optional clause, unchanged | |
| RedisModule_Replicate(ctx, | |
| replCmd, | |
| "vclv", | |
| argv + 1, // key, value | |
| preArgc, | |
| "TIMESTAMP", | |
| currentUpdatedTime, | |
| argv + 3, // remaining clauses, unchanged | |
| postArgc); |
| argv + labelsLoc, // the LABELS clause, unchanged | ||
| postArgc); | ||
| } | ||
| } else { |
There was a problem hiding this comment.
The fix is incomplete: the same divergence survives in this branch when TIMESTAMP * is written after LABELS.
TS.INCRBY key 1 LABELS a b TIMESTAMP * (argc=8) takes this else branch, not the fixed one:
- master:
parseLabelsFromArgsgreedily reads 2 pairs → labels{a: b, TIMESTAMP: *}(*passes thestrpbrk(v, "(),")value check) - replication:
preArgc = 6→key 1 LABELS a b TIMESTAMP, then the resolved ms,postArgc = 0→TS.INCRBY key 1 LABELS a b TIMESTAMP 1757... - replica: labels
{a: b, TIMESTAMP: 1757...}
So master and replica end up with a different value for the same label — a permanent, silent metadata divergence that survives RDB/AOF. The greedy-LABELS root cause the PR describes is not confined to the timestampLoc == -1 path; consider rejecting a TIMESTAMP token that falls inside the LABELS tail (i.e. timestampLoc > labelsLoc) instead of resolving it, so both branches are safe.
| @@ -1533,9 +1533,27 @@ int TSDB_incrby(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { | |||
| if (useLocalTimestamp) { | |||
| const char *replCmd = isIncr ? "TS.INCRBY" : "TS.DECRBY"; | |||
| if (timestampLoc == -1) { | |||
There was a problem hiding this comment.
Pre-existing heap over-read that this block depends on: timestampLoc is used without ever bounds-checking timestampLoc + 1.
At src/module.c:1493:
const bool useLocalTimestamp =
timestampLoc == -1 || RMUtil_StringEqualsC(argv[timestampLoc + 1], "*");TS.INCRBY k 1 TIMESTAMP passes the only arity guard (argc < 3) with argc == 4, so timestampLoc == 3 and this reads argv[4] — one past the end of the client's argv allocation — then dereferences it in RedisModule_StringPtrLen. Same for any form where TIMESTAMP is the last token (TS.INCRBY k 1 RETENTION 5 TIMESTAMP). The command is registered via __rmutil_register_cmd, which passes no arity to RedisModule_CreateCommand, so nothing upstream rejects it. Worth adding timestampLoc + 1 >= argc → WrongArity here while this code is being touched (sibling parsers like parseEncodingArgs/parseIgnoreArgs already do exactly that check).
| @@ -1533,9 +1533,27 @@ int TSDB_incrby(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { | |||
| if (useLocalTimestamp) { | |||
There was a problem hiding this comment.
A rejected write is still replicated. rv from internalAdd (line 1531) is captured but never consulted before this replication block runs.
internalAdd returns REDISMODULE_ERR for "Timestamp is older than retention", for a DUPLICATE_POLICY BLOCK upsert failure, and when filter_close_samples (the IGNORE path) drops the sample. In all of those the master replies with an error / the old timestamp and stores nothing, yet the rewritten TS.INCRBY ... TIMESTAMP <ts> is still propagated to replicas and the AOF. Guarding the whole block with if (rv == REDISMODULE_OK) — the way TSDB_add does (if (result == REDISMODULE_OK), line 1170) — would make the two commands consistent.
| // LABELS greedily consumes every token after it as a label/value pair, so it must | ||
| // stay the last clause; insert TIMESTAMP before it instead of after, or a create-on- | ||
| // write TS.INCRBY/TS.DECRBY with LABELS would replicate a bogus "TIMESTAMP" label. | ||
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv, argc); |
There was a problem hiding this comment.
Duplicated knowledge / redundant scan. On this create-on-write path parseCreateArgs has already run (line 1578) and parseLabelsFromArgs (src/query_language.c:46) already computed pos = RMUtil_ArgIndex("LABELS", argv, argc) for this exact argv. This is a second full argv scan, and it puts a second copy of the "LABELS greedily consumes everything after it" invariant in a different file from the parser that actually implements it — so the two can drift.
If the fixed-position rewrite isn't adopted, consider surfacing the position from the parser (e.g. a labelsLoc out-param on parseLabelsFromArgs/CreateCtx) so the invariant lives next to the code that enforces it. Note also that every other keyword lookup in this codebase guards with > 0 rather than != -1, precisely to skip argv[0].
| else: | ||
| raise Exception('replica never caught up with warmup key') | ||
| with env.getConnection() as master: | ||
| master_ts = master.execute_command('ts.incrby', key, 1, 'LABELS', 'region', 'us') |
There was a problem hiding this comment.
The AOF half of the claimed bug is never exercised, and TS.DECRBY is untested.
The test body is gated on Env().useSlaves, so the plain AOF leg skips entirely, and the AOF+slaves leg only ever checks the live replication stream — nothing here triggers an AOF rewrite or reload, so the propagated buffer is never replayed. Since the PR description names AOF-replay as an affected path, an env.dumpAndReload() (or BGREWRITEAOF + restart) assertion on the master would be the direct check, and it would also cover the non-slaves legs.
Also worth a line: ts.decrby goes through this same handler with a different replCmd, and neither the LABELS rewrite nor the replCmd selection is covered for it. A parametrized for cmd in ('ts.incrby', 'ts.decrby') would cost nothing here.
| # When TIMESTAMP is omitted, replication rewrites the command by | ||
| # appending "TIMESTAMP <ts>" (see | ||
| # test_incrby_no_timestamp_replicates_diverging_timestamp). If the | ||
| # create-on-write command also carries a trailing LABELS clause, | ||
| # appending TIMESTAMP after it gets swallowed as a bogus label/value | ||
| # pair on replicas and AOF-replay, since LABELS greedily consumes every | ||
| # token that follows it. |
There was a problem hiding this comment.
This comment documents the pre-fix behavior in the present tense, so after this PR it describes a contract the code no longer has. A reader landing here will believe replication still appends TIMESTAMP <ts> and that the bogus label is current behavior.
| # When TIMESTAMP is omitted, replication rewrites the command by | |
| # appending "TIMESTAMP <ts>" (see | |
| # test_incrby_no_timestamp_replicates_diverging_timestamp). If the | |
| # create-on-write command also carries a trailing LABELS clause, | |
| # appending TIMESTAMP after it gets swallowed as a bogus label/value | |
| # pair on replicas and AOF-replay, since LABELS greedily consumes every | |
| # token that follows it. | |
| # When TIMESTAMP is omitted, replication rewrites the command with a | |
| # resolved "TIMESTAMP <ts>" (see | |
| # test_incrby_no_timestamp_replicates_diverging_timestamp). Because LABELS | |
| # greedily consumes every token that follows it, TIMESTAMP has to be | |
| # inserted *before* a trailing LABELS clause - appending it would be | |
| # swallowed as a bogus label/value pair on replicas and in AOF replay. |
| info = _get_ts_info(slave, key) | ||
| slave_sample = slave.execute_command('ts.get', key) | ||
| env.assertEqual(info.labels, {b'region': b'us'}) | ||
| env.assertEqual(master_ts, slave_sample[0]) |
There was a problem hiding this comment.
Redundant with the next line: master_sample is [master_ts, value] by construction, so assertEqual(master_sample, slave_sample) on line 215 already covers this comparison. Dropping line 214 (and master_ts) loses no coverage.
Unrelated nit while you're here: the file still ends without a trailing newline (\ No newline at end of file).
…ABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard.
| // TIMESTAMP must go right after <key> <value> (index 3): a trailing LABELS | ||
| // clause greedily consumes every token after it, so appending TIMESTAMP at | ||
| // the end would replicate a bogus "TIMESTAMP <ts>" label pair instead. Index | ||
| // 3 is always just past <key> <value>, so every optional clause (LABELS | ||
| // included) keeps its original order, and this stays correct for any future | ||
| // greedy trailing clause. | ||
| const size_t preArgc = 2; // key + value | ||
| const size_t postArgc = argc - 3; // every optional clause, unchanged | ||
| RedisModule_Replicate(ctx, | ||
| replCmd, | ||
| "vclv", | ||
| argv + 1, // key, value | ||
| preArgc, | ||
| "TIMESTAMP", | ||
| currentUpdatedTime, | ||
| argv + 3, // remaining clauses, unchanged | ||
| postArgc); |
There was a problem hiding this comment.
Regression from my earlier suggestion — sorry, the fixed-position insert is not safe. A key named IGNORE now fails to replicate at all.
Inserting at index 3 shifts every token from index 3 onward, and the other clause parsers also scan argv from index 0 — so any keyword that collides with the key name and takes two operands has its second operand land exactly on the shifted slot. IGNORE is that case.
TS.INCRBY IGNORE 1 5 (create-on-write, key literally named IGNORE, case-insensitive):
| command | parseIgnoreArgs |
|
|---|---|---|
| master | TS.INCRBY IGNORE 1 5 |
idx=1, reads argv[2]="1", argv[3]="5" → OK, key created |
| replica / AOF | TS.INCRBY IGNORE 1 TIMESTAMP <ts> 5 |
idx=1, reads argv[2]="1", argv[3]="TIMESTAMP" → StringToDouble fails |
parseIgnoreArgs (src/query_language.c:171) guards only with if (idx > 0), so it matches the key at index 1; idx + 2 >= argc is false, so it goes on to RMUtil_ParseArgs(argv, argc, idx + 1, "ld", ...). The replica returns TSDB: Couldn't parse IGNORE, parseCreateArgs fails, and the key is never created on the replica — and after an AOF reload the master loses it too, since that broken command is what got persisted. On 6edcd34d the append-at-end form propagated TS.INCRBY IGNORE 1 5 TIMESTAMP <ts>, where argv[3] is still "5", so both sides parsed identically.
The minimal safe form is the previous labels-aware split, but gated on labelsLoc > 2 (a real LABELS clause can only start at index 3) instead of labelsLoc != -1. That keeps the key name intact for a key named labels, leaves every non-LABELS clause's operands where they were, and still inserts before a genuine LABELS tail:
| // TIMESTAMP must go right after <key> <value> (index 3): a trailing LABELS | |
| // clause greedily consumes every token after it, so appending TIMESTAMP at | |
| // the end would replicate a bogus "TIMESTAMP <ts>" label pair instead. Index | |
| // 3 is always just past <key> <value>, so every optional clause (LABELS | |
| // included) keeps its original order, and this stays correct for any future | |
| // greedy trailing clause. | |
| const size_t preArgc = 2; // key + value | |
| const size_t postArgc = argc - 3; // every optional clause, unchanged | |
| RedisModule_Replicate(ctx, | |
| replCmd, | |
| "vclv", | |
| argv + 1, // key, value | |
| preArgc, | |
| "TIMESTAMP", | |
| currentUpdatedTime, | |
| argv + 3, // remaining clauses, unchanged | |
| postArgc); | |
| // A real LABELS clause can only start at index 3 (past <key> <value>), and it | |
| // greedily consumes every token after it, so the resolved TIMESTAMP has to be | |
| // inserted before it. With no LABELS clause, keep appending at the end: | |
| // inserting at index 3 would shift the operands of any other clause whose | |
| // keyword collides with the key name (e.g. a key named IGNORE, whose second | |
| // operand sits at index 3), and the replica would then fail to parse it. | |
| if (labelsLoc > 2) { | |
| const size_t preArgc = labelsLoc - 1; | |
| const size_t postArgc = argc - labelsLoc; | |
| RedisModule_Replicate(ctx, | |
| replCmd, | |
| "vclv", | |
| argv + 1, // args before the LABELS clause | |
| preArgc, | |
| "TIMESTAMP", | |
| currentUpdatedTime, | |
| argv + labelsLoc, // the LABELS clause, unchanged | |
| postArgc); | |
| } else { | |
| const size_t replArgc = argc - 1; | |
| RedisModule_Replicate( | |
| ctx, replCmd, "vcl", argv + 1, replArgc, "TIMESTAMP", currentUpdatedTime); | |
| } |
I checked this shape against TS.INCRBY k 1 LABELS a b, ... RETENTION 100 LABELS a b, ... IGNORE 1 5 LABELS a b, TS.INCRBY IGNORE 1 5, TS.INCRBY LABELS 1, and TS.INCRBY k 1 LABELS a b TIMESTAMP * — all round-trip identically on the replica.
The root cause is that every keyword lookup here scans from argv[0] and so can match the key name. Fixing RMUtil_ArgIndex callers to start at index 3 in parseCreateArgs/parseIgnoreArgs/parseLabelsFromArgs would kill this whole bug class at once, but that is shared with TS.ADD/TS.CREATE/TS.ALTER and probably wants its own PR.
| with env.getConnection() as master: | ||
| master.execute_command('ts.incrby', key, 1) | ||
| master_sample = master.execute_command('ts.get', key) |
There was a problem hiding this comment.
Both new replication tests are vacuous: the key reaches the replica in the full-sync RDB, not via the rewritten command. They pass with the entire src/module.c hunk reverted.
tests/flow/tests.sh does not pass --env-reuse, so RLTest's takeEnvDown() (RLTest/main.py:593-616) takes the needShutdown path — flush() + stop() — after every test. Each test function therefore gets a brand-new master+replica. startEnv() (RLTest/redis_std.py:360-403) only waits for PING (waitForRedisToStart), never for master_link_status:up, and Redis's default repl-diskless-sync-delay 5 means the master doesn't fork the replica's snapshot for ~5s. During that window the replica is in SLAVE_STATE_WAIT_BGSAVE_START and replicationFeedSlaves skips it.
So master.execute_command('ts.incrby', 'LABELS', 1) runs milliseconds after Env(), the rewritten TS.INCRBY LABELS 1 TIMESTAMP <ts> is never parsed by the replica, and ~5s later the replica just materializes the finished series out of the RDB payload. The exists poll then succeeds and assertEqual(master_sample, slave_sample) compares two copies of the same RDB-loaded series — it holds no matter what the propagation code does.
test_incrby_create_with_labels_replicates_correctly gets this right with its warmup_key handshake, and this is the same 5s throttle documented at tests/flow/test_rdbs.py:122. Both new tests need that handshake before the create-on-write write:
| with env.getConnection() as master: | |
| master.execute_command('ts.incrby', key, 1) | |
| master_sample = master.execute_command('ts.get', key) | |
| env = Env() | |
| key = 'LABELS' | |
| warmup_key = 'incrby_key_named_labels_warmup' | |
| with env.getConnection() as master: | |
| master.execute_command('ts.create', warmup_key) | |
| # Make sure the replica has finished its initial full sync and is applying | |
| # live-propagated commands before we issue the create-on-write TS.INCRBY - | |
| # otherwise the key arrives inside the full-sync RDB and the rewritten | |
| # command is never parsed by the replica (see repl-diskless-sync-delay). | |
| for _ in range(100): | |
| with env.getSlaveConnection() as slave: | |
| if slave.execute_command('exists', warmup_key): | |
| break | |
| time.sleep(0.1) | |
| else: | |
| raise Exception('replica never caught up with warmup key') | |
| with env.getConnection() as master: | |
| master.execute_command('ts.incrby', key, 1) | |
| master_sample = master.execute_command('ts.get', key) |
The same applies verbatim to test_incrby_labels_key_named_timestamp_replicates_correctly (line 269).
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv, argc); | ||
| if (labelsLoc > 2 && timestampLoc > labelsLoc) { | ||
| // "TIMESTAMP" matched here is actually a label key/value inside the LABELS tail, not | ||
| // a real TIMESTAMP directive, since LABELS greedily consumes every token after it. | ||
| timestampLoc = -1; | ||
| } |
There was a problem hiding this comment.
The new > 2 guard is only applied to labelsLoc; timestampLoc needs the same treatment, and without it a key named timestamp is silently mis-parsed.
RMUtil_ArgIndex matches the key name at index 1, and a real TIMESTAMP keyword can only ever appear at index >= 3 — exactly the reasoning behind the labelsLoc > 2 you just added.
TS.INCRBY timestamp 5 (argc=3): timestampLoc = 1; labelsLoc = -1 so the new override doesn't fire; the arity check is 2 >= 3 = false so it doesn't fire either; argv[2] = "5" is not "*", so useLocalTimestamp is false and currentUpdatedTime = StringToLongLong("5") = 5. The sample is stored at timestamp 5 (Jan 1 1970) with value 5, instead of value 5 at RedisModule_Milliseconds() — and since useLocalTimestamp is false it goes out via ReplicateVerbatim, so master and replica are consistently wrong. Any key whose name is timestamp (case-insensitive) is effectively unusable.
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv, argc); | |
| if (labelsLoc > 2 && timestampLoc > labelsLoc) { | |
| // "TIMESTAMP" matched here is actually a label key/value inside the LABELS tail, not | |
| // a real TIMESTAMP directive, since LABELS greedily consumes every token after it. | |
| timestampLoc = -1; | |
| } | |
| int timestampLoc = RMUtil_ArgIndex("TIMESTAMP", argv, argc); | |
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv, argc); | |
| // Both keywords can only appear at index 3 or later (past <key> <value>); a match at | |
| // index 1 or 2 is the key name or the value, not a directive. | |
| if (timestampLoc <= 2) { | |
| timestampLoc = -1; | |
| } | |
| if (labelsLoc > 2 && timestampLoc > labelsLoc) { | |
| // "TIMESTAMP" matched here is actually a label key/value inside the LABELS tail, not | |
| // a real TIMESTAMP directive, since LABELS greedily consumes every token after it. | |
| timestampLoc = -1; | |
| } |
| raise Exception('replica never caught up with initial ts.incrby') | ||
| with env.getSlaveConnection() as slave: | ||
| slave_sample = slave.execute_command('ts.get', key) | ||
| env.assertEqual(master_sample, slave_sample) |
There was a problem hiding this comment.
This test can't detect the divergence it names. Even with the replica handshake added, ts.get equality is not enough — the key-named-LABELS case still diverges on labels, and only on labels.
Master TS.INCRBY LABELS 1 (argc=3): parseLabelsFromArgs matches the key at pos=1, first_label_pos=2, label_count = max(0, (3-2)/2) = 0 → no labels. The propagated TS.INCRBY LABELS 1 TIMESTAMP <ts> (argc=5) gives the replica pos=1, first=2, label_count = (5-2)/2 = 1 → label {"1": "TIMESTAMP"} (both tokens pass the non-empty / no-(), checks; the timestamp digits are the odd token that (argc - first)/2 silently truncates).
So TS.INFO LABELS returns no labels on the master and 1=TIMESTAMP on the replica, and TS.QUERYINDEX 1=TIMESTAMP / TS.MRANGE ... FILTER 1=TIMESTAMP match on the replica only. The samples are identical on both sides ([<ts>, 1]), which is exactly why the single assertEqual(master_sample, slave_sample) passes.
| env.assertEqual(master_sample, slave_sample) | |
| with env.getSlaveConnection() as slave: | |
| slave_info = _get_ts_info(slave, key) | |
| slave_sample = slave.execute_command('ts.get', key) | |
| with env.getConnection() as master: | |
| master_info = _get_ts_info(master, key) | |
| env.assertEqual(master_sample, slave_sample) | |
| env.assertEqual(master_info.labels, slave_info.labels) |
Heads-up: with the handshake in place this assertion will fail on the current code — the residual comes from parseLabelsFromArgs scanning from argv[0], not from the replication rewrite, so it may be worth splitting out rather than blocking this PR.
| if (timestampLoc != -1 && timestampLoc + 1 >= argc) { | ||
| return RedisModule_WrongArity(ctx); | ||
| } |
There was a problem hiding this comment.
While you're adding guards here: a negative explicit timestamp is still accepted and silently wraps, permanently bricking the key. TS.ADD guards this (src/module.c:1150, "TSDB: invalid timestamp, must be a nonnegative integer") but TS.INCRBY does not.
TS.INCRBY newkey 5 TIMESTAMP -1: StringToLongLong succeeds with -1 (line 1505). The sanity check at line 1523 misses it twice over — series->lastTimestamp is uint64_t, so the usual arithmetic conversions promote -1 to 18446744073709551615 and currentUpdatedTime < series->lastTimestamp is false, and for a fresh series lastTimestamp == 0 short-circuits it anyway. internalAdd's parameter is api_timestamp_t (uint64_t), so the sample lands at 2^64-1 and every later TS.ADD/TS.INCRBY on that key is rejected forever with "timestamp must be equal to or higher than the maximum existing timestamp". ReplicateVerbatim propagates it, so the replica is bricked identically.
| if (timestampLoc != -1 && timestampLoc + 1 >= argc) { | |
| return RedisModule_WrongArity(ctx); | |
| } | |
| if (timestampLoc != -1 && timestampLoc + 1 >= argc) { | |
| return RedisModule_WrongArity(ctx); | |
| } |
(and after the StringToLongLong below, mirror TS.ADD's check:
if (currentUpdatedTime < 0) return RTS_ReplyGeneralError(ctx, "TSDB: invalid timestamp, must be a nonnegative integer");)
| with env.getConnection() as master: | ||
| master_info = _get_ts_info(master, key) | ||
| master_sample = master.execute_command('ts.get', key) | ||
| with env.getSlaveConnection() as slave: | ||
| slave_info = _get_ts_info(slave, key) | ||
| slave_sample = slave.execute_command('ts.get', key) | ||
| env.assertEqual(master_info.labels, {b'region': b'us'}) | ||
| env.assertEqual(slave_info.labels, {b'region': b'us'}) | ||
| env.assertEqual(master_sample, slave_sample) |
There was a problem hiding this comment.
The post-restart block can't detect sample loss, so it doesn't verify what its comment claims ("the data survived intact").
master_sample captured at line 203 is overwritten at line 225 by a fresh post-restart read, so nothing is ever compared across the restart. If a reload kept the key and its metadata but dropped every sample, TS.GET replies with an empty array (src/reply.c: if (SeriesGetNumSamples(series) == 0) RedisModule_ReplyWithArray(ctx, 0);), so master_sample == slave_sample degenerates to [] == [] and passes; labels are key metadata and survive independently, so both label assertions pass too. Only a missing key would be caught, via _get_ts_info raising.
Renaming the pre-restart capture (e.g. pre_restart_sample[cmd]) and asserting against it — or asserting the concrete [ts, b'1'] / [ts, b'-1'] — would make the block meaningful.
Separately, per the other comment on this test: restartAndReload() calls BGREWRITEAOF before the restart and Defaults.use_rdb_preamble is True (RLTest/env.py:122), so the rewritten AOF is an RDB-preamble image. The restart therefore loads a binary snapshot and never re-parses the propagated TS.INCRBY ... TIMESTAMP <ts> LABELS ... text — in the non-AOF slaves leg it's a pure RDB round-trip. Real AOF-replay coverage needs Env(useAof=True, useRdbPreamble=False), or asserting on the AOF contents directly (tests/flow/aof_parser.py).
|
Re-reviewed at Two things I'd want fixed before this lands. 1. My earlier suggestion was wrong and caused a regression — apologies for that. (comment) Inserting at a fixed index 3 shifts every token after it, and the other clause parsers also scan argv from index 0. 2. Both new replication tests pass with the entire Cheap enough to fold in: the Fine as follow-ups from my side: the negative FWIW the three red legs look unrelated: macOS died at |
…NORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2bc3522. Configure here.
| # stream): restart master and replica and reload from AOF/RDB, then | ||
| # verify the data survived intact against what was captured before | ||
| # the restart. | ||
| env.restartAndReload() |
There was a problem hiding this comment.
Test calls missing reload helper
Medium Severity
test_incrby_create_with_labels_replicates_correctly calls env.restartAndReload(), which is not defined on Env in this suite or in includes.py (the existing persistency tests use dumpAndReload). The AOF-replay assertions raise AttributeError and never check that labels and samples survive reload.
Reviewed by Cursor Bugbot for commit 2bc3522. Configure here.
| int timestampLoc = RMUtil_ArgIndex("TIMESTAMP", argv, argc); | ||
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv, argc); | ||
| // Both keywords can only appear at index 3 or later (past <key> <value>); a match at | ||
| // index 1 or 2 is the key name or the value, not a directive. | ||
| if (timestampLoc <= 2) { | ||
| timestampLoc = -1; | ||
| } |
There was a problem hiding this comment.
This new guard introduces a fresh divergence — for a key literally named timestamp. I built both revisions and reproduced it on a live master/replica pair, plus a standalone AOF reload.
RMUtil_ArgIndex returns the first match and scans from argv[0], so for a key named timestamp the match is the key name at index 1 — and zeroing it also discards the real directive that the rewrite itself appended.
TS.INCRBY TIMESTAMP 5:
- master:
timestampLoc = 1→ zeroed to-1→useLocalTimestamp→ resolvesT1;labelsLoc = -1, so the append branch emitsTS.INCRBY TIMESTAMP 5 TIMESTAMP T1(confirmed byte-for-byte withMONITOR) - replica: re-parses it,
ArgIndexstill returns 1 (the key name, ahead of the real directive at index 3) → zeroed again →useLocalTimestamp→ resolves its ownT2
Measured: 2032 ms apart with a stalled replica; 1 ms on 2 of 20 samples on idle loopback (so it's nondeterministic, and a naive same-host test can pass by luck). Once diverged the replica's lastTimestamp is ahead of the master's, so later samples are silently accepted and the datasets keep drifting rather than erroring.
Two things that make it broader than I first thought:
- It doesn't need a replica. The same rewritten command goes to the master's AOF, so a standalone master loses the sample timestamp on every reload — measured
1788277600295→1788277605675acrossDEBUG LOADAOF, with a control key unchanged. Each hop also re-appends anotherTIMESTAMP <ts>pair, so the command grows on chained replicas. - It silently ignores explicit user input.
TS.INCRBY timestamp 5 TIMESTAMP 1000now returnsnow()instead of1000.
At 804965db this input kept timestampLoc = 1, so useLocalTimestamp was false, currentUpdatedTime = 5, and ReplicateVerbatim propagated the original — wrong semantics but identical on both sides. So this trades wrong-but-consistent for divergent.
The fix is to scan only past <key> <value> rather than zeroing a late match. argc >= 3 is already guaranteed by the arity check, so argc - 3 is never negative and argv + 3 is at worst a one-past-the-end pointer that is never dereferenced (the loop body doesn't run):
| int timestampLoc = RMUtil_ArgIndex("TIMESTAMP", argv, argc); | |
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv, argc); | |
| // Both keywords can only appear at index 3 or later (past <key> <value>); a match at | |
| // index 1 or 2 is the key name or the value, not a directive. | |
| if (timestampLoc <= 2) { | |
| timestampLoc = -1; | |
| } | |
| // Both keywords can only appear at index 3 or later (past <key> <value>), so scan only | |
| // from there. Zeroing a late match instead would also discard the real directive when the | |
| // key name is itself "TIMESTAMP" or "LABELS" - RMUtil_ArgIndex returns the FIRST match, | |
| // which for those key names is argv[1], not the directive. | |
| int timestampLoc = RMUtil_ArgIndex("TIMESTAMP", argv + 3, argc - 3); | |
| if (timestampLoc != -1) { | |
| timestampLoc += 3; | |
| } | |
| int labelsLoc = RMUtil_ArgIndex("LABELS", argv + 3, argc - 3); | |
| if (labelsLoc != -1) { | |
| labelsLoc += 3; | |
| } |
I built this variant and it holds master == replica with a 2 s replica stall, 20/20 identical samples, and the IGNORE / LABELS / TIMESTAMP * cases all still round-trip. (labelsLoc > 2 below is then equivalent to labelsLoc != -1, but it's harmless to leave as-is.)
Not covered by the current tests: test_incrby_no_timestamp_replicates_diverging_timestamp uses key 'incrby_repl_divergence', which never collides with the keyword. A test for this needs a key named timestamp and an injected stall (DEBUG SLEEP on the replica, as that test already does) — without the stall it passes by luck.
…t the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck.
…ehavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
|
gabsow
left a comment
There was a problem hiding this comment.
Approving.
The fix is correct and the review cycle converged well — thanks for the fast turnarounds, including on the two suggestions of mine that turned out to be wrong (the fixed-index-3 insert, which broke a key named IGNORE, and the timestampLoc <= 2 zeroing, which re-diverged a key named TIMESTAMP). The final argv + 3 scan is the right shape.
What I verified on 2fe7148a:
- 215k simulated plus ~4.6k live argv shapes across replication, AOF command replay and sub-replica hops — no master/replica divergence, no replica parse errors, no UB, and clean under ASAN at
argc == 3whereargv + 3is a one-past-the-end pointer. - Spot-checked round-trips on a live master/replica pair and across
DEBUG LOADAOFforLABELS,IGNORE,TIMESTAMP/timestampkey names,TIMESTAMP *,RETENTION ... LABELS ..., and theTS.DECRBYequivalents. - All flow legs green including all four sanitizer legs (x64 slaves 506/506), and the SonarCloud gate is green after the dedupe.
Worth noting for the changelog: this also fixes a remotely-triggerable crash. TS.INCRBY k 1 TIMESTAMP read argv[argc] and took the pre-fix server down with signal 11 — reproduced on the merge-base build. test_incrby_timestamp_missing_value_returns_error guards it.
Three things we agreed to leave for separate PRs:
- A negative explicit
TIMESTAMPstill wraps through the unsignedapi_timestamp_tand permanently bricks the key (TS.ADDguards this at src/module.c:1150,TS.INCRBYdoesn't). restartAndReload()is an RDB/AOF-preamble round-trip, so there is still no real AOF command-replay coverage — needsEnv(useAof=True, useRdbPreamble=False)or asserting on the AOF contents.parseLabelsFromArgs/parseIgnoreArgsstill scan fromargv[0], which is the root of the key-named-LABELSlabel residual you documented, and it affects TS.ADD/TS.CREATE/TS.ALTER too. Fixing those callers the same way would retire this whole bug class.
… with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
… with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
… with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
… with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
… with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
… with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
… with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
… with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
… with LABELS (#2161) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
…mestamp is local server clock (#2109) (#2153) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is lo… (#2109) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is local server clock * . * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS.
…mestamp is local server clock (#2109) (#2154) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is lo… (#2109) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is local server clock * . * fixup: remove test_ts_incrby_arg_validation_before_creation accidentally reintroduced by cherry-pick conflict resolution This test wasn't part of ca3375a and doesn't belong on 8.6 at this point; only test_incrby_no_timestamp_replicates_diverging_timestamp is the actual new test from that commit. * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS. * fixup: remove test_ts_incrby_arg_validation_before_creation reintroduced by MOD-16873 cherry-pick This branch's TS.INCRBY predates the MOD-8167 validate-before-create fix, so the test fails here (same reason it was already removed on this branch before, and got pulled back in by the wholesale test-file cherry-pick of the LABELS/TIMESTAMP fix).
…mestamp is local server clock (#2109) (#2155) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is lo… (#2109) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is local server clock * . * fixup: remove test_ts_incrby_NaN and test_ts_incrby_arg_validation_before_creation accidentally reintroduced by cherry-pick conflict resolution Neither test was part of ca3375a and neither belongs on 8.4 at this point; only test_incrby_no_timestamp_replicates_diverging_timestamp is the actual new test from that commit. * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS. * fixup: remove test_ts_incrby_NaN and test_ts_incrby_arg_validation_before_creation reintroduced by MOD-16873 cherry-pick This branch predates NaN support and the MOD-8167 validate-before-create fix, so both tests fail here (same reason they were already removed on this branch before, and got pulled back in by the wholesale test-file cherry-pick of the LABELS/TIMESTAMP fix).
…mestamp is local server clock (#2109) (#2156) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is lo… (#2109) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is local server clock * . * fixup: remove test_incrby_error_cases, test_ts_incrby_NaN, test_ts_incrby_arg_validation_before_creation accidentally reintroduced by cherry-pick conflict resolution None of these three tests were part of ca3375a and none belong on 8.2 at this point; only test_incrby_no_timestamp_replicates_diverging_timestamp is the actual new test from that commit. * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS. * fixup: remove test_incrby_error_cases, test_ts_incrby_NaN, test_ts_incrby_arg_validation_before_creation reintroduced by MOD-16873 cherry-pick This branch predates NaN support and the MOD-8167 validate-before-create fix, and its arg-count/value validation for TS.INCRBY behaves differently, so all three tests fail here (same reason they were already removed on this branch before, and got pulled back in by the wholesale test-file cherry-pick of the LABELS/TIMESTAMP fix).
…mestamp is local server clock (#2109) (#2157) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is lo… (#2109) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is local server clock * . * fixup: remove test_incrby_error_cases, test_ts_incrby_NaN, test_ts_incrby_arg_validation_before_creation accidentally reintroduced by cherry-pick conflict resolution None of these three tests were part of ca3375a and none belong on 1.12 at this point; only test_incrby_no_timestamp_replicates_diverging_timestamp is the actual new test from that commit. * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS. * fixup: remove test_incrby_error_cases, test_ts_incrby_NaN, test_ts_incrby_arg_validation_before_creation reintroduced by MOD-16873 cherry-pick This branch predates NaN support and the MOD-8167 validate-before-create fix, and its arg-count/value validation for TS.INCRBY behaves differently, so all three tests fail here (same reason they were already removed on this branch before, and got pulled back in by the wholesale test-file cherry-pick of the LABELS/TIMESTAMP fix).
…mestamp is local server clock (#2109) (#2158) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is lo… (#2109) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is local server clock * . * fixup: remove test_incrby_error_cases, test_ts_incrby_NaN, test_ts_incrby_arg_validation_before_creation accidentally reintroduced by cherry-pick conflict resolution None of these three tests were part of ca3375a and none belong on 1.10 at this point; only test_incrby_no_timestamp_replicates_diverging_timestamp is the actual new test from that commit. * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS. * fixup: remove test_incrby_error_cases, test_ts_incrby_NaN, test_ts_incrby_arg_validation_before_creation reintroduced by MOD-16873 cherry-pick This branch predates NaN support and the MOD-8167 validate-before-create fix, and its arg-count/value validation for TS.INCRBY behaves differently, so all three tests fail here (same reason they were already removed on this branch before, and got pulled back in by the wholesale test-file cherry-pick of the LABELS/TIMESTAMP fix).
…mestamp is local server clock (#2109) (#2159) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is lo… (#2109) * MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is local server clock * . * fixup: remove test_incrby_error_cases, test_ts_incrby_NaN, test_ts_incrby_arg_validation_before_creation accidentally reintroduced by cherry-pick conflict resolution None of these three tests were part of ca3375a and none belong on 1.8 at this point; only test_incrby_no_timestamp_replicates_diverging_timestamp is the actual new test from that commit. * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS (#2160) * Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS When TIMESTAMP is omitted, replication rewrites the command by appending "TIMESTAMP <ts>" at the very end. If the create-on-write command also carries a trailing LABELS clause, appending TIMESTAMP after it gets swallowed as a bogus label/value pair on replicas and AOF-replay, since LABELS greedily consumes every token that follows it. Insert TIMESTAMP before the LABELS clause instead of after it. * style: clang-format * test: also verify the replicated sample value/timestamp, not just labels * Address review: fixed-position TIMESTAMP insert, guard TIMESTAMP-in-LABELS-tail, bounds check, guard replication on write result - Insert TIMESTAMP right after <key> <value> (index 3) instead of scanning for LABELS: avoids matching a key literally named "LABELS" and removes the redundant argv scan. - Detect a "TIMESTAMP" match that falls inside a LABELS tail and treat it as a label, not a directive, so primary and replica agree on labels even when a label key is literally named "TIMESTAMP". - Bounds-check TIMESTAMP's value before dereferencing it (was a heap over-read when TIMESTAMP was the last token). - Only replicate when internalAdd() actually succeeded, matching TSDB_add. Tests: parametrize incrby/decrby, verify AOF-replay (not just live replication), and add regressions for the key-named-LABELS and label-named-TIMESTAMP cases plus the missing-value arity guard. * Address review: fixed-position insert was unsafe (breaks key named IGNORE), fix timestampLoc key-name collision, fix vacuous replica tests, fix restart-check overwrite bug - Revert the unconditional fixed-position insert: it shifts every other clause's operands when a keyword collides with the key name and takes multiple operands (e.g. a key named IGNORE), breaking replica/AOF parsing entirely. Back to inserting before LABELS only when a real LABELS clause exists (labelsLoc > 2); append at the end otherwise. - Apply the same "> 2" floor to timestampLoc itself: a key named "timestamp" was matching RMUtil_ArgIndex at index 1 and getting treated as an explicit TIMESTAMP directive. Tests: - test_incrby_create_with_key_named_labels_replicates_correctly and test_incrby_labels_key_named_timestamp_replicates_correctly were vacuous: with no warmup-key handshake, the key reaches the replica via the initial full-sync RDB before repl-diskless-sync-delay elapses, so the rewritten command is never actually parsed by the replica. Added the same handshake test_incrby_create_with_labels_replicates_correctly already used. - The post-restart block in test_incrby_create_with_labels_replicates_correctly reused master_sample, overwriting the pre-restart value, so nothing was ever compared across the restart. Now captured separately and compared. - Added test_incrby_create_with_key_named_ignore_replicates_correctly, a direct regression test for the IGNORE-key repro above. Not addressed here (flagged by review as out of scope / follow-up, not blocking this PR): the pre-existing parseLabelsFromArgs key-name collision for a key literally named LABELS, and TS.INCRBY accepting a negative explicit TIMESTAMP. * Address review: scan for TIMESTAMP/LABELS only past <key> <value>, not the whole argv Zeroing a late match (previous commit) still broke a key literally named "TIMESTAMP": RMUtil_ArgIndex returns the FIRST match, which for that key is the key name at argv[1], not the real directive appended by the rewrite. Zeroing it discarded the real one too, so master and replica each resolved their own timestamp - reproduced live with a stalled replica and a standalone AOF reload. Fix: scan starting at index 3, where a real TIMESTAMP or LABELS keyword is the earliest either can legally appear, so the key/value can never be mistaken for one. Add test_incrby_key_named_timestamp_replicates_correctly (key named "TIMESTAMP", stalled replica, mirrors test_incrby_no_timestamp_replicates_diverging_timestamp) - without the stall this would pass by luck. * Address review: dedupe replica-wait polling into shared helpers The "for _ in range(100): ... exists ... time.sleep(0.1) / else: raise" replica-wait loop was duplicated 10 times across the file, tripping SonarCloud's new-code duplication gate (6.1%, threshold 3%). Extracted _wait_for_replica_key() and _wait_for_replica_online() (the latter also performs the warmup-key handshake), and replaced all 10 call sites. No behavior change. * Address review: strengthen key-named-TIMESTAMP test to check actual behavior, not just consistency test_incrby_key_named_timestamp_replicates_correctly only asserted master_ts == slave_sample[0], which the pre-PR code also satisfied (wrong-but-consistent: both sides stored ts=5, the misread value slot, via ReplicateVerbatim). Add assertGreaterEqual(master_ts, before_ms) so the test actually catches a regression back to that behavior, not just a master/replica divergence. Also capture the stall thread's exception instead of swallowing it, so a broken DEBUG SLEEP can't silently turn this into a no-op that reports PASS. * fixup: test_ts_incrby.py needs an explicit Env import, and drop tests unsupported on this branch This branch's includes.py never re-exports RLTest's Env (unlike newer branches, whose includes.py defines its own Env() wrapper picked up by `from includes import *`), so every test in this file was failing with NameError: name 'Env' is not defined. Add the explicit import used by the other flow test files on this branch. Also remove test_incrby_error_cases, test_ts_incrby_NaN, and test_ts_incrby_arg_validation_before_creation: this branch predates NaN support and the MOD-8167 validate-before-create fix, and its arg-count/ value validation for TS.INCRBY behaves differently, so all three fail here (same reason they were already removed on this branch before, and got pulled back in by the wholesale test-file cherry-pick of the LABELS/TIMESTAMP fix). * fixup: add explicit pytest import to test_ts_incrby.py Same issue as the Env import: this branch's includes.py never brings pytest into scope via `from includes import *`, so pytest.raises() failed with NameError: name 'pytest' is not defined in every test that uses it. * fixup: add explicit redis import to test_ts_incrby.py Same issue as pytest/Env: this branch's includes.py never brings the redis module into scope via `from includes import *`, so redis.ResponseError failed with NameError: name 'redis' is not defined.
## Summary Updates the bundled RedisTimeSeries pin in `modules/modules.yaml` from **v8.10.0 to v8.11.90**, the **8.12 release candidate**. | Module | From | To | |---|---|---| | RedisTimeSeries | v8.10.0 | v8.11.90 | The upstream tag resolves to `ef84d314675a693998092db24b5adf8cc314d004`, the current `8.12` release-branch head. Its source version is `8.11.90`. RedisJSON and RedisBloom are handled separately by #15964 and #15966. ## Release notes — RedisTimeSeries 8.12 release candidate Based on the published [`v8.11.90` tag](https://github.com/RedisTimeSeries/RedisTimeSeries/tree/v8.11.90) at [`ef84d314`](RedisTimeSeries/RedisTimeSeries@ef84d31). These notes describe the actual changes since **8.10.0**, excluding features already backported into that release. ### Bug fixes and robustness - **Correct replication and AOF replay for increments with labels:** Fixed `TS.INCRBY` and `TS.DECRBY` inserting an automatically generated `TIMESTAMP` after the `LABELS` clause, where it could be interpreted as an extra label. Also corrected keyword detection when keys or labels contain `TIMESTAMP` or `LABELS`, and prevented failed sample updates from being replicated. ([#2160](RedisTimeSeries/RedisTimeSeries#2160)) - **Correct updates to large uncompressed chunks:** Fixed sample-count truncation when inserting or updating samples in uncompressed chunks containing more than 32,767 samples, including chunks loaded through `RESTORE`. ([#2172](RedisTimeSeries/RedisTimeSeries#2172)) - **Safer compressed-chunk decoding:** Added bounds checks and read-ahead padding to prevent heap over-reads when decoding malformed compressed chunks. Validation applies to both RDB loading and inter-shard deserialization. ([#2150](RedisTimeSeries/RedisTimeSeries#2150)) - **Stricter RDB consistency validation:** Reject serialized series with no chunks, duplicate chunk start timestamps, overflowing sample-count totals, or a total sample count that disagrees with the loaded chunks. ([#2189](RedisTimeSeries/RedisTimeSeries#2189)) - **Safe duplicate-policy parsing:** Fixed a potential stack overflow when an excessively long duplicate-policy string is supplied. Valid policy names retain their existing case-insensitive behavior. ([#2205](RedisTimeSeries/RedisTimeSeries#2205)) ### Cluster reliability - Improved cluster-type detection and inter-shard authentication handling for Redis Enterprise deployments using OSS cluster mode. ([#2149](RedisTimeSeries/RedisTimeSeries#2149), [LibMR #123](RedisGears/LibMR#123)) - Fixed an SSL-object memory leak when inter-shard TLS initialization fails. ([LibMR #124](RedisGears/LibMR#124)) - Changed distributed execution-ID initialization to avoid reusing IDs after a shard restarts. ([#2199](RedisTimeSeries/RedisTimeSeries#2199), [LibMR #126](RedisGears/LibMR#126)) ### Command metadata - Added the missing `TS.QUERYLABELS` entry to `commands.json` for client-generation and documentation tools. The command itself was already available in 8.10.0. ([#2135](RedisTimeSeries/RedisTimeSeries#2135)) - Corrected `TS.CREATERULE`’s advertised minimum argument count. ([#2136](RedisTimeSeries/RedisTimeSeries#2136)) - Updated `TS.INCRBY` and `TS.DECRBY` command specifications to describe their supported creation options accurately. ([#2160](RedisTimeSeries/RedisTimeSeries#2160)) ### Testing and build maintenance - Expanded replication-integrity, failover, topology-convergence, TLS-failure, and corrupted-RDB regression coverage. - Improved cluster-test startup and timeout handling, updated RLTest to 0.7.31, and removed Debian Bullseye CI jobs. - **Updated the Homebrew OpenSSL dependency to OpenSSL 4 for macOS builds.** ([#2213](RedisTimeSeries/RedisTimeSeries#2213), [8.12 backport #2215](RedisTimeSeries/RedisTimeSeries#2215)) - Added release-tag/version validation and improved artifact naming for nightly and manual builds. - Reduced the TLS migration-test fixture to improve CI reliability; this change does not alter production query timeouts. ([#2212](RedisTimeSeries/RedisTimeSeries#2212)) - Set the release-candidate version to **8.11.90**. ([#2214](RedisTimeSeries/RedisTimeSeries#2214)) [Full comparison: v8.10.0 → v8.11.90](RedisTimeSeries/RedisTimeSeries@v8.10.0...v8.11.90) ## Validation - [x] Verified the published tag points to the intended 8.12 release commit and matches `src/version.h`. - [x] Verified the manifest parser resolves RedisTimeSeries to `v8.11.90` as a tag. - [x] Verified the diff changes only the RedisTimeSeries pin; `git diff --check` passes. - [ ] Upstream [tag build/test/package workflow](https://github.com/RedisTimeSeries/RedisTimeSeries/actions/runs/38559907930) completes (running when this PR was opened; tag-version validation passed). - [ ] Redis core CI validates the bundled module. A full local module build/test was not run for this manifest-only change. <details> <summary>Upstream commit history for audit</summary> This is the commit-history range, not a list of newly introduced features: some master commits have equivalent backports in 8.10.0. The release notes above were checked against the net source diff. - Use dedicated redis_ref field in ramp.yml for CI git ref ([#2059](RedisTimeSeries/RedisTimeSeries#2059)) ([ccdcd46e](RedisTimeSeries/RedisTimeSeries@ccdcd46)) - pass VG=1 flag to the build as well ([#2060](RedisTimeSeries/RedisTimeSeries#2060)) ([062f3691](RedisTimeSeries/RedisTimeSeries@062f369)) - MOD-16160 - wake parked TS.BGET clients on key deletion ([#2062](RedisTimeSeries/RedisTimeSeries#2062)) ([b1c4085d](RedisTimeSeries/RedisTimeSeries@b1c4085)) - ci: bump GitHub Actions to Node24-compatible versions ([#2035](RedisTimeSeries/RedisTimeSeries#2035)) ([04cb2fce](RedisTimeSeries/RedisTimeSeries@04cb2fc)) - MOD-15749 Short-form CLUSTERSET: RAMP capability + LibMR error-return ([#2065](RedisTimeSeries/RedisTimeSeries#2065)) ([8f2a3a6b](RedisTimeSeries/RedisTimeSeries@8f2a3a6)) - ci: speed up Event CI (lean PR gate) and shard slow nightly jobs ([#2068](RedisTimeSeries/RedisTimeSeries#2068)) ([cfcd4e73](RedisTimeSeries/RedisTimeSeries@cfcd4e7)) - MOD-6409 - TS.INFO memoryUsage (and MEMORY USAGE, via the mem_usage callback) ([#2067](RedisTimeSeries/RedisTimeSeries#2067)) ([00c646b4](RedisTimeSeries/RedisTimeSeries@00c646b)) - MOD-16266 - fix ci hang ([#2066](RedisTimeSeries/RedisTimeSeries#2066)) ([a0f71da6](RedisTimeSeries/RedisTimeSeries@a0f71da)) - MOD-15565 - mrange aggregation execution in inner shards ([#2074](RedisTimeSeries/RedisTimeSeries#2074)) ([badcf8ac](RedisTimeSeries/RedisTimeSeries@badcf8a)) - MOD-16505 - change TS.BGET command to TS.READ ([#2081](RedisTimeSeries/RedisTimeSeries#2081)) ([22c471ef](RedisTimeSeries/RedisTimeSeries@22c471e)) - MOD-14615: run valgrind test suite serially to avoid CPU oversubscription ([#2083](RedisTimeSeries/RedisTimeSeries#2083)) ([a48abf37](RedisTimeSeries/RedisTimeSeries@a48abf3)) - MOD-14615: skip test_asm migration-query test on macos-15-intel ([#2084](RedisTimeSeries/RedisTimeSeries#2084)) ([c94501f2](RedisTimeSeries/RedisTimeSeries@c94501f)) - MOD-16299 - NRANGE support multiple aggregations ([#2079](RedisTimeSeries/RedisTimeSeries#2079)) ([7d16dbd6](RedisTimeSeries/RedisTimeSeries@7d16dbd)) - MOD-16514 - fix bootstrap & build for all os ([#2082](RedisTimeSeries/RedisTimeSeries#2082)) ([049d00dc](RedisTimeSeries/RedisTimeSeries@049d00d)) - MOD-16653 Prevent more heap overflow + other rdb load asserions ([#2086](RedisTimeSeries/RedisTimeSeries#2086)) ([b54cdcef](RedisTimeSeries/RedisTimeSeries@b54cdce)) - MOD-16172 - support exclude empty in mrange commands ([#2072](RedisTimeSeries/RedisTimeSeries#2072)) ([0d46cacd](RedisTimeSeries/RedisTimeSeries@0d46cac)) - ci: add code coverage to CI — PR + nightly (lcov -> Codecov) ([#2070](RedisTimeSeries/RedisTimeSeries#2070)) ([dbb7ce4f](RedisTimeSeries/RedisTimeSeries@dbb7ce4)) - fix(alpine): use distro python3 for the test venv (avoid uv musl clang standalone) ([#2089](RedisTimeSeries/RedisTimeSeries#2089)) ([0576b6ed](RedisTimeSeries/RedisTimeSeries@0576b6e)) - MOD-16370 Introduce `TS.QUERYLABELS`: Get a list of labels and label-… ([#2090](RedisTimeSeries/RedisTimeSeries#2090)) ([77b634dd](RedisTimeSeries/RedisTimeSeries@77b634d)) - MOD-16873 `TS.INCRBY` replicate master timestamp when timestamp is lo… ([#2109](RedisTimeSeries/RedisTimeSeries#2109)) ([ca3375a9](RedisTimeSeries/RedisTimeSeries@ca3375a)) - MOD-16306 - use registry for pulling / pushing docker images ([#2098](RedisTimeSeries/RedisTimeSeries#2098)) ([8c2f591b](RedisTimeSeries/RedisTimeSeries@8c2f591)) - MOD-16364 - update requirements deps ([#2108](RedisTimeSeries/RedisTimeSeries#2108)) ([93ccac0e](RedisTimeSeries/RedisTimeSeries@93ccac0)) - fix ubuntu hangs ([#2115](RedisTimeSeries/RedisTimeSeries#2115)) ([b8ff52e5](RedisTimeSeries/RedisTimeSeries@b8ff52e)) - MOD-16382 Handle topology-change notifications ([#2104](RedisTimeSeries/RedisTimeSeries#2104)) ([ce8be8aa](RedisTimeSeries/RedisTimeSeries@ce8be8a)) - MOD-16382 Add topology-change flow tests (consolidated) ([#2116](RedisTimeSeries/RedisTimeSeries#2116)) ([01d59afb](RedisTimeSeries/RedisTimeSeries@01d59af)) - MOD-16265 - retry the dumpAndReload() for max 2 sec so no "Background save already in progress to give enough time to existing rdb save to finish ([#2124](RedisTimeSeries/RedisTimeSeries#2124)) ([d74df641](RedisTimeSeries/RedisTimeSeries@d74df64)) - Merge pull request #2125 from RedisTimeSeries/claude/redistimeseries-pr-2116-tests-0wmm4d ([7ddf2ae8](RedisTimeSeries/RedisTimeSeries@7ddf2ae)) - MOD-17016 Disable topology events handling in ts under RE (for now) ([#2130](RedisTimeSeries/RedisTimeSeries#2130)) ([40748fdb](RedisTimeSeries/RedisTimeSeries@40748fd)) - MOD-17095 Add tls cluster tests leg ([#2126](RedisTimeSeries/RedisTimeSeries#2126)) ([3fbfae15](RedisTimeSeries/RedisTimeSeries@3fbfae1)) - MOD-16382 Add flow tests for topology events ([#2121](RedisTimeSeries/RedisTimeSeries#2121)) ([fae002e8](RedisTimeSeries/RedisTimeSeries@fae002e)) - MOD-16382 Test CLUSTERSET after topology events ([#2131](RedisTimeSeries/RedisTimeSeries#2131)) ([a50d901a](RedisTimeSeries/RedisTimeSeries@a50d901)) - squash ([#2128](RedisTimeSeries/RedisTimeSeries#2128)) ([5944c928](RedisTimeSeries/RedisTimeSeries@5944c92)) - MOD-16399 Bump LibMR: skip rebuilds for unchanged CLUSTERSET topologies ([#2088](RedisTimeSeries/RedisTimeSeries#2088)) ([008f5a9b](RedisTimeSeries/RedisTimeSeries@008f5a9)) - MOD-17289 Suppress x86-only Valgrind false positive in MR_BuildCluster ([#2134](RedisTimeSeries/RedisTimeSeries#2134)) ([bb16996d](RedisTimeSeries/RedisTimeSeries@bb16996)) - MOD-17349 Add TS.QUERYLABELS to commands.json ([#2135](RedisTimeSeries/RedisTimeSeries#2135)) ([b278d809](RedisTimeSeries/RedisTimeSeries@b278d80)) - MOD-17350 Fix TS.CREATERULE advertised arity (-5 -> -6) ([#2136](RedisTimeSeries/RedisTimeSeries#2136)) ([b01a5426](RedisTimeSeries/RedisTimeSeries@b01a542)) - MOD-17281 Fix test_failover timeouts and hang ([#2138](RedisTimeSeries/RedisTimeSeries#2138)) ([b04f067a](RedisTimeSeries/RedisTimeSeries@b04f067)) - MOD-16600 Read INFOCLUSTER status from the end, not index 17 ([#2144](RedisTimeSeries/RedisTimeSeries#2144)) ([9e24dabd](RedisTimeSeries/RedisTimeSeries@9e24dab)) - MOD-17518 Use refined cluster types (allow RE+oss bdbs) ([#2149](RedisTimeSeries/RedisTimeSeries#2149)) ([0cc05c78](RedisTimeSeries/RedisTimeSeries@0cc05c7)) - MOD-17239 gorilla decoder guard over-read ([#2150](RedisTimeSeries/RedisTimeSeries#2150)) ([36c13128](RedisTimeSeries/RedisTimeSeries@36c1312)) - MOD-17209 Port missing topology-event tests and hunt for UAFs ([#2137](RedisTimeSeries/RedisTimeSeries#2137)) ([44d103be](RedisTimeSeries/RedisTimeSeries@44d103b)) - smarter soloution ([#2151](RedisTimeSeries/RedisTimeSeries#2151)) ([77270d3a](RedisTimeSeries/RedisTimeSeries@77270d3)) - MOD-17566 - add new stage to tag flow to verify tag version miss match ([#2152](RedisTimeSeries/RedisTimeSeries#2152)) ([f7d32579](RedisTimeSeries/RedisTimeSeries@f7d3257)) - MOD-16873 Fix TS.INCRBY/TS.DECRBY replicating a bogus TIMESTAMP label with LABELS ([#2160](RedisTimeSeries/RedisTimeSeries#2160)) ([4f26b4cb](RedisTimeSeries/RedisTimeSeries@4f26b4c)) - MOD-17281 Tolerate connection reset during demotion in test_failover ([#2162](RedisTimeSeries/RedisTimeSeries#2162)) ([6863942c](RedisTimeSeries/RedisTimeSeries@6863942)) - MOD-18192 - leak ssl in cluster err ([#2163](RedisTimeSeries/RedisTimeSeries#2163)) ([dc0f1a00](RedisTimeSeries/RedisTimeSeries@dc0f1a0)) - MOD-17439 Better handling of timeouts ([#2164](RedisTimeSeries/RedisTimeSeries#2164)) ([783eebfb](RedisTimeSeries/RedisTimeSeries@783eebf)) - MOD-18488 - Fix signed truncation in uncompressed upsert after RESTORE ([#2172](RedisTimeSeries/RedisTimeSeries#2172)) ([7c06d521](RedisTimeSeries/RedisTimeSeries@7c06d52)) - Remove Bullseye from automation testing matrices ([#2181](RedisTimeSeries/RedisTimeSeries#2181)) ([70a37c2b](RedisTimeSeries/RedisTimeSeries@70a37c2)) - MOD-18589 - Reject inconsistent sample counts in RDB loads ([#2189](RedisTimeSeries/RedisTimeSeries#2189)) ([a65a01a7](RedisTimeSeries/RedisTimeSeries@a65a01a)) - MOD-18751 / MOD-18906 / MOD-18913: bring the oss-cluster flow tests back ([#2194](RedisTimeSeries/RedisTimeSeries#2194)) ([9487ceef](RedisTimeSeries/RedisTimeSeries@9487cee)) - MOD-18948: verify every write command replicates to the replica ([#2201](RedisTimeSeries/RedisTimeSeries#2201)) ([0f34e70c](RedisTimeSeries/RedisTimeSeries@0f34e70)) - build: pin Homebrew OpenSSL 3 on macOS ([#2200](RedisTimeSeries/RedisTimeSeries#2200)) ([853c9905](RedisTimeSeries/RedisTimeSeries@853c990)) - MOD-18801 Bump deps/LibMR to its latest version ([#2199](RedisTimeSeries/RedisTimeSeries#2199)) ([fbcbd40b](RedisTimeSeries/RedisTimeSeries@fbcbd40)) - MOD-17236 - dup policy string length capping ([#2205](RedisTimeSeries/RedisTimeSeries#2205)) ([feaf6bc2](RedisTimeSeries/RedisTimeSeries@feaf6bc)) - MOD-18948: check clock rows by what the replica receives, not by timing ([#2207](RedisTimeSeries/RedisTimeSeries#2207)) ([d47c979c](RedisTimeSeries/RedisTimeSeries@d47c979)) - MOD-18475 Check promoted nodes against current Redis topology ([6060574b](RedisTimeSeries/RedisTimeSeries@6060574)) - MOD-18443 Enable server logs for TLS initialization regression ([b9f97109](RedisTimeSeries/RedisTimeSeries@b9f9710)) - MOD-18475 Refresh all node views throughout failover convergence ([11390b56](RedisTimeSeries/RedisTimeSeries@11390b5)) - MOD-19365 Use released RLTest 0.7.31 for module tests ([28cd329c](RedisTimeSeries/RedisTimeSeries@28cd329)) - CI: bound test-container loopback MSS with MTU 1500 ([e3c403ad](RedisTimeSeries/RedisTimeSeries@e3c403a)) - MOD-17216: replace CI MTU workaround with 60-second query idle timeout ([a01ca70a](RedisTimeSeries/RedisTimeSeries@a01ca70)) - MOD-17216: use requested 10-second distributed query idle limit ([386d2c9b](RedisTimeSeries/RedisTimeSeries@386d2c9)) - MOD-17216 Use response progress timeouts for distributed range queries ([00ad114f](RedisTimeSeries/RedisTimeSeries@00ad114)) - MOD-17216: reduce migration query fixture instead of changing timeouts ([1f0daea0](RedisTimeSeries/RedisTimeSeries@1f0daea)) - MOD-17216: reuse smaller migration fixture for TLS runs ([51adf485](RedisTimeSeries/RedisTimeSeries@51adf48)) - Prepare RedisTimeSeries 8.12 release candidate 8.11.90 ([a2448196](RedisTimeSeries/RedisTimeSeries@a244819)) - update openssl dep to version 4 on brew ([#2213](RedisTimeSeries/RedisTimeSeries#2213)) ([4bb5b630](RedisTimeSeries/RedisTimeSeries@4bb5b63)) </details>





Summary
TIMESTAMPis omitted,TSDB_incrby/TSDB_decrbyrewrite the replicated command by appendingTIMESTAMP <ts>at the end.LABELSclause, appendingTIMESTAMPafter it gets swallowed as a bogus label/value pair on replicas and AOF-replay, sinceLABELSgreedily consumes every token that follows it.TIMESTAMP <ts>before theLABELSclause instead of after it (only affects the create-on-write, no-explicit-TIMESTAMP path).Test plan
test_incrby_create_with_labels_replicates_correctlyintests/flow/test_ts_incrby.py, reproducing the bug on a replica before the fix, passing after.TEST=test_ts_incrby make flow_tests— 8/8 pass across all 5 configs (general, slaves, AOF, AOF+slaves, cluster).Note
Medium Risk
Changes replication and argv parsing for TS.INCRBY/DECRBY, which affects replica and AOF consistency; scope is limited to those commands but mistakes would corrupt timestamps or labels on secondaries.
Overview
Fixes TS.INCRBY / TS.DECRBY so replicas and AOF replay apply the same sample timestamp and labels as the primary when
TIMESTAMPis omitted or keywords collide with key/label names.Argument parsing in
TSDB_incrbynow locatesTIMESTAMPandLABELSonly from index 3 onward (past key and increment), ignores aTIMESTAMPtoken inside a trailingLABELSblock, and returns wrong arity whenTIMESTAMPhas no following value.Replication runs only after a successful write. If the command used implicit or
*timestamps, the primary rewrites the propagated command with the resolved millisecond timestamp—insertingTIMESTAMP <ts>before a realLABELSclause (so it is not eaten as a label pair), appending at the end when there is noLABELS, or replacingTIMESTAMP *inline; explicit numeric timestamps still replicate verbatim.Tests add replica/AOF coverage (including keys named
TIMESTAMP,LABELS, orIGNORE, label keyTIMESTAMP, create-on-write withLABELS, and trailingTIMESTAMPwithout a value), plus shared helpers to wait for replica sync.Reviewed by Cursor Bugbot for commit 2fe7148. Bugbot is set up for automated code reviews on this repo. Configure here.