fix: Always initialize an ack level row if it doesn't exist
PR 3 โ c-warren #12: fix: Always initialize an ack level row if it doesn't exist
๐ Stacked PR (3/3). Previous: #8286 ยท Next: none (top of stack)
What changed?
Add InsertHistoryDLQAckLevelIfNotExistsRow across the DLQ store stack (HistoryTaskDLQManager โ nosql/sql stores โ nosqlplugin interfaces, plus Cassandra/DynamoDB/MongoDB impls and regenerated mocks). The Cassandra impl uses an LWT and intentionally discards the [applied] result so an existing ack level is never overwritten.
Why?
https://github.com/cadence-workflow/cadence/issues/6697
Re-injection (PR 2) advances an ack level by updating its row, but a partition with no prior ack-level row had nothing to advance, so its progress couldn't be tracked. Seeding a sentinel row on demand guarantees an ack level always exists to advance, while the if-not-exists semantics ensure we never clobber recorded progress.
How did you test it?
go test -race ./common/persistence/nosql/... \
./common/persistence -run DLQAckLevel
Potential risks
Adds a new persistence method and regenerates mocks. Cassandra path relies on LWT (lightweight transaction) correctness; the discarded [applied] flag is deliberate. No schema migration required.
Release notes
N/A
Documentation Changes
N/A
Implements idempotent sentinel row initialization for history DLQ ack levels across the persistence stack, addressing the lack of progress tracking for partitions without prior ack data. Resolved the potential for redundant LWT calls and verified atomicity of initialization. ๐ common/persistence/history_task_dlq_manager.go:72-83 ๐ common/persistence/nosql/nosqlplugin/cassandra/history_task_dlq.go:201-215 ๐ common/persistence/nosql/nosqlplugin/cassandra/history_task_dlq_cql.go:50-52
DLQ writes are typically low-volume (failed standby tasks), so impact is bounded, but if a large burst of standby tasks is DLQ'd this adds an avoidable per-write Paxos round. Consider seeding the ack-level row lazily/once (e.g. cache that the partition has been initialized for the lifetime of the manager, or only seed when the partition is first observed) rather than on every task insert. ๐ common/persistence/history_task_dlq_manager.go:72-86
In 2 rules not applicable. Show all rules by commenting Auto-apply is off โ Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:Code Review โ
Approved 2 resolved / 2 findings
โ
2 resolved
โ
Performance: LWT issued on every DLQ task write to seed ack level
historyTaskDLQManagerImpl.CreateHistoryDLQTask now unconditionally calls CreateHistoryDLQAckLevelIfNotExists before every task insert (common/persistence/history_task_dlq_manager.go:72-83). On the Cassandra path this maps to InsertHistoryDLQAckLevelIfNotExistsRow, which executes an IF NOT EXISTS lightweight transaction (history_task_dlq_cql.go:50-52, history_task_dlq.go:201-215). LWTs require a Paxos round and are substantially more expensive than a normal write, yet the row only needs to be seeded once per partition โ every subsequent DLQ write pays the LWT cost just to no-op.โ
Bug: Ack-level seed not rolled back if task insert later fails
CreateHistoryDLQTask, the ack-level row is inserted first via CreateHistoryDLQAckLevelIfNotExists, and only afterward is the task written via CreateHistoryDLQTask (common/persistence/history_task_dlq_manager.go:72-99). If the ack-level insert succeeds but the subsequent task insert fails, the partition is left with a sentinel ack-level row at MinimumHistoryTaskKey but no task. This is benign for the re-injection processor (it will simply find no tasks to advance past), and the IF NOT EXISTS semantics make a later retry idempotent, so this is not a correctness bug โ but it does mean ack-level rows can exist for partitions that never successfully received a task. Worth a brief comment documenting that the ordering is intentional and the orphan row is harmless.Rules โ
All requirements met
Repository Rules
gitar display:verbose.Options
Display: compact โ Showing less information.
Auto-apply
Compact
gitar auto-apply:on
gitar display:verbose
Was this helpful? React with ๐ / ๐ | Gitar
Implements atomic sentinel row seeding for history DLQ ack levels using "if-not-exists" logic, resolving issues with missing ack level rows and improper transaction rollbacks. Refactoring also updates TaskType terminology and adds memoization to ensure consistent persistence across the task processing stack. ๐ common/persistence/history_task_dlq_manager.go:72-83 ๐ common/persistence/nosql/nosqlplugin/cassandra/history_task_dlq.go:201-215 ๐ common/persistence/nosql/nosqlplugin/cassandra/history_task_dlq_cql.go:50-52
DLQ writes are typically low-volume (failed standby tasks), so impact is bounded, but if a large burst of standby tasks is DLQ'd this adds an avoidable per-write Paxos round. Consider seeding the ack-level row lazily/once (e.g. cache that the partition has been initialized for the lifetime of the manager, or only seed when the partition is first observed) rather than on every task insert. ๐ common/persistence/history_task_dlq_manager.go:72-86
In 2 rules not applicable. Show all rules by commenting Auto-apply is off โ Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:Code Review โ
Approved 2 resolved / 2 findings
โ
2 resolved
โ
Performance: LWT issued on every DLQ task write to seed ack level
historyTaskDLQManagerImpl.CreateHistoryDLQTask now unconditionally calls CreateHistoryDLQAckLevelIfNotExists before every task insert (common/persistence/history_task_dlq_manager.go:72-83). On the Cassandra path this maps to InsertHistoryDLQAckLevelIfNotExistsRow, which executes an IF NOT EXISTS lightweight transaction (history_task_dlq_cql.go:50-52, history_task_dlq.go:201-215). LWTs require a Paxos round and are substantially more expensive than a normal write, yet the row only needs to be seeded once per partition โ every subsequent DLQ write pays the LWT cost just to no-op.โ
Bug: Ack-level seed not rolled back if task insert later fails
CreateHistoryDLQTask, the ack-level row is inserted first via CreateHistoryDLQAckLevelIfNotExists, and only afterward is the task written via CreateHistoryDLQTask (common/persistence/history_task_dlq_manager.go:72-99). If the ack-level insert succeeds but the subsequent task insert fails, the partition is left with a sentinel ack-level row at MinimumHistoryTaskKey but no task. This is benign for the re-injection processor (it will simply find no tasks to advance past), and the IF NOT EXISTS semantics make a later retry idempotent, so this is not a correctness bug โ but it does mean ack-level rows can exist for partitions that never successfully received a task. Worth a brief comment documenting that the ordering is intentional and the orphan row is harmless.Rules โ
All requirements met
Repository Rules
gitar display:verbose.Options
Display: compact โ Showing less information.
Auto-apply
Compact
gitar auto-apply:on
gitar display:verbose
Was this helpful? React with ๐ / ๐ | Gitar