Repository navigation
7.0 fixes: Oracle dead-letter duplicates and scheduling hang, Cosmos DB replay, dead-letter ids under IdAndDestination, test isolation (#6153-#6157) - #6160
Merged
Conversation
…he move, which deletes only its own inbox row MoveToDeadLetterStorageAsync had no ORA-00001 handling, so a dead letter that already existed (a retried move whose first attempt committed, or a message that came back and failed again) failed the move on every attempt. A duplicate now means "already dead lettered", as it does for MessageDatabase: Oracle rolls back only the failed insert, so the delete in the same transaction still commits and the inbox row is retired. The delete matched the inbox row on the id alone, so under IdAndDestination it also deleted the row of the same message at another destination (GH-6158). It now matches id and received_at, like DeleteIncomingEnvelopeAsync and MessageDatabase, and keeps the id-only match for an envelope with no destination. dead_letter_that_already_exists_6155 dead-letters the same envelope twice, and retries a committed move, under both identity modes: 4 of 4 failed with ORA-00001 before, 4 of 4 pass now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… row in its own transaction on a duplicate On ORA-00001 the cleanup deleted the outgoing row on a second connection while the move's transaction still held that row's lock from its SELECT ... FOR UPDATE, so the delete waited on the method's own lock forever. Oracle rolls back only the failed statement, so the duplicate is now caught around the scheduled write and the outgoing row is deleted and committed in the same transaction. The scheduled write is a MERGE, so the duplicate only comes from a scheduled row another transaction had inserted and not committed. basic_functionality.move_from_outgoing_to_scheduled_when_the_scheduled_row_already_exists sets that race up with a second connection and bounds the move at 30 seconds: it timed out before, and passes now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r has its own id
Under MessageIdentity.IdAndDestination the dead letter was stored at dlq/{envelope id}, so the same
envelope id dead lettered at two destinations kept only the second dead letter while both inbox
documents were deleted.
New dead letters under IdAndDestination are stored at dlq/{incoming identity}, which carries the
destination. IdOnly, and an envelope with no destination, keep dlq/{id}. Nothing is migrated: the
lookups by envelope id (DeadLetterEnvelopeByIdAsync, QueryAsync and the bulk operations by MessageIds,
EditAndReplayAsync) load the old dlq/{id} document and, under IdAndDestination only, every
dlq/{id}/... document by id prefix, which RavenDB answers from the documents and never from a stale
index. The bulk operations act on the matched document ids rather than rebuilding an id from the
envelope id.
Shared compliance tests (MessageStoreCompliance, IdAndDestination only):
- the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_letters
- replay_and_discard_by_id_reach_the_dead_letter_of_every_destination
- dead_lettering_one_destination_leaves_the_same_id_at_another_destination_alone (GH-6158)
The first two failed on RavenDB before; the third failed on Oracle before GH-6158's fix.
RavenDbTests.dead_letter_ids_under_id_and_destination_6153 pins the id shapes and that a dead letter
written under the old id is still found, replayed, edited and discarded by id.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… back into the inbox ReplayMatchingAsync and EditAndReplayAsync marked dead letters replayable, but nothing in Wolverine.CosmosDb moved a replayable dead letter back into the inbox, so a replay never ran the message. CosmosDbMessageStore.MoveReplayableDeadLettersToIncomingAsync writes each replayable, unarchived dead letter into the inbox as the relational MoveReplayableErrorMessagesToIncomingOperation does (incoming, owned by any node, not scheduled, no attempts), and the durability agent runs it at the start of every recovery tick, before the inbox recovery that then runs the message. The inbox document and the dead letter are in different partitions, so there is no TransactionalBatch: the inbox document is written first and the dead letter deleted second, so a failure in between leaves a duplicate, never a loss. The delete is conditional on the dead letter's ETag, so one edited again or archived since it was read is left for the next pass. replaying_dead_letters_6154: the move itself, an edited body, an archived dead letter left alone, and end to end through the agent (a message dead lettered on its first attempt runs again after a replay). The end-to-end test timed out before; all 4 pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ter has its own id
Under MessageIdentity.IdAndDestination the dead letter was stored at deadletter|{envelope id}, and the
move upserts it, so the same envelope id dead lettered at two destinations kept only the second dead
letter while both inbox documents were deleted.
New dead letters under IdAndDestination are stored at deadletter|{id}|{destination}, with the
destination made safe for a Cosmos DB id the same way as the inbox identity. IdOnly, and an envelope
with no destination, keep deadletter|{id}, and IdOnly lookups are the same point reads as before.
Nothing is migrated: under IdAndDestination the lookups by envelope id (DeadLetterEnvelopeByIdAsync,
QueryAsync and the bulk operations by MessageIds, EditAndReplayAsync) query the dead-letter partition
by envelopeId, which every dead letter has always carried, so they find the old and the new id shapes.
Before, the shared compliance tests the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_letters
and replay_and_discard_by_id_reach_the_dead_letter_of_every_destination failed on Cosmos DB; they pass
now. dead_letter_ids_under_id_and_destination_6153 pins the id shapes and that a dead letter written
under the old id is still found, replayed, edited, discarded and moved back into the inbox.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…run, and the DQL expiration tests start from no schema
SqlServerMessageStoreTests used the shared receiver schema, so two SqlServerTests processes against
one SQL Server counted each other's rows, got each other's claims and deadlocked on the same tables.
A class fixture (SqlServerMessageStoreSchema) now gives it receiver_run_{8 hex}, unique to the run,
dropped when the class is done; a schema of that shape left by a killed run, with nothing created in
it for a day, is swept on the way in. Two concurrent runs of the class: 105/105 each.
PostgresqlMessageStore_DQL_expiration.no_expiration_column_normally failed on a reused container,
because the dlq_expiration schema and the expires column the other test adds outlived earlier runs.
Each test now drops the schema first. Before: 1 of 2 failed on this machine's reused container; after:
2 of 2, twice in a row. No assertion changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…GIN EXCLUSIVE migration lock The SQLite migration lock is an open BEGIN EXCLUSIVE transaction on the migrating connection (GH-2666). Weasel.Sqlite applies a change SQLite cannot ALTER, such as a primary key, by SQLite's table rebuild procedure: it sets PRAGMAs and opens its own transaction on the same connection, and that failed with "cannot start a transaction within a transaction". No such migration could run. Switching an existing database from IdOnly to IdAndDestination failed host startup on main. Under the lock, the store now checks whether the pending migration rebuilds a table. If it does, the store commits the lock and the rebuild runs in its own transaction, which SQLite serialises with every other writer. The base migration reads the schema again before applying anything. Every other migration keeps the exclusive lock. rebuild_migration_under_the_migration_lock_6167 switches an existing database to IdAndDestination: the inbox gets its (id, received_at) key and keeps its row. Before the fix the same switch failed with the nested-transaction error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… by (id, received_at) The SQLite dead letter table was keyed by the id alone under every identity. Under IdAndDestination, the same envelope id dead lettered at a second destination hit that key. MessageDatabase read the duplicate as "already dead lettered", completed the move and deleted the inbox row, so that destination's dead letter was lost. The shared compliance tests from #6153 caught it in CISqlite. Under IdAndDestination the key is now (id, received_at), as it is for the inbox here and for the dead letters of every other relational store. received_at is NOT NULL, because a dead letter with no destination is written with DatabaseConstants.UnknownReceivedAt. IdOnly is unchanged. An existing table migrates by a table rebuild, which needs GH-6167. Before the fix, the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_letters and replay_and_discard_by_id_reach_the_dead_letter_of_every_destination failed on SqliteMessageStore_with_IdAndDestination_Identity; both pass now. dead_letter_key_under_id_and_destination_6166 pins the key under both identities, and that a dead letter table keyed by id alone migrates with its rows and then keeps a second destination's dead letter beside the old one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6153
Closes #6154
Closes #6155
Closes #6156
Closes #6157
Closes #6158
Closes #6166
Closes #6167
Three more bugs turned up along the way. Each is filed separately and fixed here:
#6155 Oracle: a dead letter that already exists failed the move forever
What was wrong.
OracleMessageStore.MoveToDeadLetterStorageAsynchad no ORA-00001 handling. When the dead letter already existed, every later attempt failed. That happens after a retried move whose first attempt committed, or when a message comes back and fails again. The receiver then kept rescheduling a message it could never retire.The change. ORA-00001 on the dead-letter insert now means "already dead lettered", as it does for
MessageDatabase. Oracle rolls back only the failed statement, so the inbox delete earlier in the same transaction still commits and the inbox row is retired.The test.
OracleTests.dead_letter_that_already_exists_6155runs under bothIdOnlyandIdAndDestination:Before the fix all 4 cases failed with ORA-00001. Now all 4 pass.
#6158 Oracle: under IdAndDestination, a dead-letter move deleted another destination's inbox row
What was wrong. The same method deleted the inbox row with
WHERE id = :id. UnderIdAndDestinationthat also deleted the row of the same message received at another destination. That copy is a different message whose handler may not have run yet. This is the same class of bug as #4701.The change. The delete now matches
idandreceived_at, likeDeleteIncomingEnvelopeAsyncandMessageDatabase. An envelope with no destination (GH-3166) still matches on its id alone, as before.The test. I added a shared compliance test,
dead_lettering_one_destination_leaves_the_same_id_at_another_destination_alone, which runs only under IdAndDestination. It failed onOracleMessageStore_with_IdAndDestination_Identitybefore the fix and passes now. It also passes on the other stores.#6156 Oracle: MoveFromOutgoingToScheduledAsync could wait forever on its own row lock
What was wrong. On ORA-00001, the cleanup deleted the outgoing row on a second connection. The first transaction still held that row's lock from its
SELECT ... FOR UPDATE, so the delete waited on the method's own lock.The change. The duplicate is now caught around the scheduled write. The outgoing row is then deleted and committed in the same transaction, and the second connection is gone.
The test.
basic_functionality.move_from_outgoing_to_scheduled_when_the_scheduled_row_already_exists. The scheduled write is aMERGE, which updates a row it can see. So the duplicate only comes from a scheduled row that another transaction inserted and had not yet committed. The test sets up that race with a second connection, checks that the move is waiting, then commits. The move is bounded at 30 seconds so a hang fails the test instead of hanging the suite. Before the fix it timed out after 30 seconds. Now it passes.#6154 Cosmos DB: replaying dead letters did nothing
What was wrong.
ReplayMatchingAsyncandEditAndReplayAsyncsetReplayable = true, but nothing moved a replayable dead letter back into the inbox.The change. New
CosmosDbMessageStore.MoveReplayableDeadLettersToIncomingAsync. It writes each replayable, unarchived dead letter into the inbox the same way the relationalMoveReplayableErrorMessagesToIncomingOperationdoes: incoming, owned by any node, not scheduled, attempts 0.CosmosDbDurabilityAgentruns it at the start of every recovery tick, before the inbox recovery that then runs the message.The inbox document and the dead letter are in different partitions, so there is no
TransactionalBatch:I added
InternalsVisibleTo("CosmosDbTests")so the tests can call the mover directly.The tests.
CosmosDbTests.replaying_dead_letters_6154covers:Before the fix the end-to-end test timed out. All 4 pass now.
#6153 RavenDB and Cosmos DB: dead-letter ids under IdAndDestination (backward compatible)
What was wrong. Under
IdAndDestinationthe dead-letter id left out the destination (dlq/{id}on RavenDB,deadletter|{id}on Cosmos DB). When one envelope id was dead-lettered at two destinations, the second dead letter overwrote the first, so one destination's dead letter was lost.The change. No API change and no data migration.
dlq/{incoming identity}, that isdlq/{id}/{destination}.deadletter|{id}|{destination}, with the destination made safe for a Cosmos id the same way as the inbox identity.dlq/{id}/deadletter|{id}.DeadLetterEnvelopeByIdAsync,QueryAsyncand the bulk operations withMessageIds, andEditAndReplayAsync.dlq/{id}plus everydlq/{id}/...document by id prefix (LoadStartingWithAsync). That is answered from the documents, never from a possibly stale index.envelopeId, which every dead letter has always carried.dlq/{id}from the envelope id.EditAndReplayAsyncedits every destination's dead letter for that id, as the relational stores update every row with the id.The tests.
the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_lettersandreplay_and_discard_by_id_reach_the_dead_letter_of_every_destination. Both failed on RavenDB and Cosmos DB before the fix. They pass now, and pass on Oracle, PostgreSQL and SQL Server.RavenDbTests.dead_letter_ids_under_id_and_destination_6153andCosmosDbTests.dead_letter_ids_under_id_and_destination_6153pin the backward compatibility:#6166 SQLite: under IdAndDestination the dead letter table was keyed by id alone
What was wrong. CISqlite failed two of the new shared compliance tests on this PR, deterministically:
the_same_id_dead_lettered_at_two_destinations_keeps_both_dead_lettersandreplay_and_discard_by_id_reach_the_dead_letter_of_every_destination. The SQLite dead letter table was keyed byidunder every identity mode. So the second destination's dead letter for one envelope id hit the primary key.MessageDatabaseread that duplicate as "already dead lettered", completed the move and deleted the inbox row, and that dead letter was lost. This is the same loss as #6153.The change. Under IdAndDestination the key is now
(id, received_at), as it is for this store's inbox and for the dead letters of every other relational store.received_atis NOT NULL, because a dead letter without a destination is written withDatabaseConstants.UnknownReceivedAt. IdOnly is unchanged.The tests.
SqliteMessageStore_with_IdAndDestination_Identitybefore the fix and pass now.SqliteTests.dead_letter_key_under_id_and_destination_6166pins the key under both identities. It also takes an existing IdAndDestination dead letter table keyed byidalone, with a dead letter in it, and checks that it migrates with its row and then keeps a second destination's dead letter beside the old one. That migration test needs SQLite: every message store migration that rebuilds a table fails with 'cannot start a transaction within a transaction' under the migration lock #6167.#6167 SQLite: every migration that rebuilds a table failed under the migration lock
What was wrong. The SQLite migration lock is an open
BEGIN EXCLUSIVEtransaction on the migrating connection (GH-2666). Weasel.Sqlite applies a change SQLite cannotALTER, such as a primary key, with SQLite's table rebuild procedure on that same connection. That procedure sets PRAGMAs and opens its own transaction, which failed withcannot start a transaction within a transaction.So no SQLite migration that needs a rebuild could ever run. On main today, switching an existing database from IdOnly to IdAndDestination fails host startup. Without this fix, #6166's key change would also have broken startup for every existing SQLite IdAndDestination database.
The change. Under the lock,
SqliteMessageStorenow checks whether the pending migration rebuilds a table. If it does, the store commits the lock and the rebuild runs in its own transaction, which SQLite serialises with every other writer. The base migration reads the schema again before applying anything. Every other migration keeps the exclusive lock.There is still a window: two processes upgrading one SQLite file at the same moment can both decide to rebuild.
MigrateAsyncretries once and reads the schema again.The test.
SqliteTests.rebuild_migration_under_the_migration_lock_6167switches an existing database to IdAndDestination. The inbox gets its(id, received_at)key and keeps its row. Before the fix the same switch failed with the nested-transaction error.#6157 Test isolation
SQL Server.
SqlServerMessageStoreTestsshared thereceiverschema. A new class fixture,SqlServerMessageStoreSchema, gives itreceiver_run_{8 hex}, unique to the run.receiverschema would have broken other sessions' suites on this machine's SQL Server.PostgreSQL.
PostgresqlMessageStore_DQL_expirationnow drops itsdlq_expirationschema at the start of each test. Before the fix,no_expiration_column_normallyfailed on this machine's reused container (1 of 2 failed). After it, 2 of 2 passed in two runs in a row. No assertion changed.What I ran
Apple Silicon Mac, net10.0. Containers: Oracle (
gvenzl/oracle-free:23-slim), PostgreSQL on 5433, SQL Server on 1434, embedded RavenDB, and the Cosmos DB vnext emulator through Testcontainers, which runs on arm64.dotnet build wolverine.slnx -c Release -f net10.0(on the final tree, with main through #6152 and #6159 merged in)SqliteTests(full, final tree)MySqlTests(full, before the merge of main)*IdAndDestination_Identity*and*dead_letter_move_is_atomic*(#6152) classes, final treeOracleTests(full)RavenDbTests(full)CosmosDbTests(full, box quiet)SqlServerTests(full)PostgresqlTests(full)SqlServerTests.Persistence.SqlServerMessageStore*after the rebase onto #6148The first full
CosmosDbTestsrun had 9 failures in agent-timing tests:scheduled_promotion_semantics(2),scheduled_job_compliance(1),durability_recovery_capacity(3),destination_recovery_isolation_5587(2), and the new end-to-end replay test. That run overlapped the full SQL Server suite on the same machine. All 9 tests passed when rerun on their own (18/18 in those classes), and the full suite then passed 409/409 with the box quiet.The full Oracle, RavenDB, Cosmos DB, SQL Server and PostgreSQL runs above were on the tree before main (#6148, #6152, #6159) was merged in.
Every suite that runs the shared
MessageStoreCompliancehas now been run: Oracle, RavenDB, Cosmos DB, SQL Server, PostgreSQL, SQLite and MySQL. PolecatTests, MartenTests and the EF Core suites have noMessageStoreCompliancesubclass, so none of the new compliance tests run there.The branch is updated with a merge of
origin/maininstead of a rebase, because the repository rules refuse a force push.🤖 Generated with Claude Code