cadence icon indicating copy to clipboard operation
cadence copied to clipboard

fix: Always initialize an ack level row if it doesn't exist

Open c-warren opened this issue 5 months ago โ€ข 1 comments

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

c-warren avatar Jun 25 '26 21:06 c-warren

Code Review โœ… Approved 2 resolved / 2 findings

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.

โœ… 2 resolved
โœ… Performance: LWT issued on every DLQ task write to seed ack level

๐Ÿ“„ 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 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.

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.

โœ… Bug: Ack-level seed not rolled back if task insert later fails

๐Ÿ“„ common/persistence/history_task_dlq_manager.go:72-86 In 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

โœ… GitHub Issue Linking Requirement: The PR description contains a valid linked issue (https://github.com/cadence-workflow/cadence/issues/6697).
โœ… PR Description Quality Standards: The PR description follows the template with substantive 'What changed?', 'Why?', 'How did you test it?', 'Potential risks', 'Release notes', and 'Documentation Changes' sections.

2 rules not applicable. Show all rules by commenting gitar display:verbose.

Options

Auto-apply is off โ†’ Gitar will not commit updates to this branch.
Display: compact โ†’ Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with ๐Ÿ‘ / ๐Ÿ‘Ž | Gitar

gitar-bot avatar Jul 08 '26 04:07 gitar-bot

Code Review โœ… Approved 2 resolved / 2 findings

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.

โœ… 2 resolved
โœ… Performance: LWT issued on every DLQ task write to seed ack level

๐Ÿ“„ 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 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.

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.

โœ… Bug: Ack-level seed not rolled back if task insert later fails

๐Ÿ“„ common/persistence/history_task_dlq_manager.go:72-86 In 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

โœ… GitHub Issue Linking Requirement: The PR description includes a valid issue link (https://github.com/cadence-workflow/cadence/issues/6697) pointing to the cadence-workflow organization.
โœ… PR Description Quality Standards: The PR description follows the required structure and guidance from the project's PR template, providing clear 'why', 'what', and 'how' information.

2 rules not applicable. Show all rules by commenting gitar display:verbose.

Options

Auto-apply is off โ†’ Gitar will not commit updates to this branch.
Display: compact โ†’ Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with ๐Ÿ‘ / ๐Ÿ‘Ž | Gitar

gitar-bot avatar Jul 10 '26 00:07 gitar-bot