Repository navigation
Conversation
| */ | ||
| @SuppressWarnings("unchecked") | ||
| private static Map<DuplicateIDCache, Set<ByteArray>> sentInTransaction(final Transaction tx) { | ||
| Map<DuplicateIDCache, Set<ByteArray>> sent = (Map<DuplicateIDCache, Set<ByteArray>>) tx.getProperty(TransactionPropertyIndexes.DUPLICATE_IDS); |
There was a problem hiding this comment.
I feel like you could use tx.getOrCreateOperation:
There was a problem hiding this comment.
I guess this is the answer to my question, right?
There was a problem hiding this comment.
Good idea, getOrCreateOperation fits better than a bare property. I'll rework it: a small TransactionOperation registered with tx.getOrCreateOperation(TransactionPropertyIndexes.DUPLICATE_IDS, ...) that holds the IDs the transaction has sent, by cache, and the check asks it. Adding to the cache stays where it is, in the AddDuplicateIDOperation that addToCache(id, tx, false) registers with tx.afterStore, so the timing doesn't change.
#6883 isn't the answer to this one, though. It covers a send outside a transaction, where addToCache(id, tx, true) put the ID in the cache at once. Inside a client transaction the ID only reaches the cache in afterCommit, so without this check a second send of it in the same transaction still passes cache.contains.
There was a problem hiding this comment.
Done: the IDs now live in a TransactionOperation registered with tx.getOrCreateOperation(TransactionPropertyIndexes.DUPLICATE_IDS, ...), and the property-based helpers are gone. DuplicateDetectionTest passes locally; the CI run for the new commit is waiting for approval.
be0a5b3 to
4e50dfa
Compare
PostOfficeImpl.checkNotBridgeDuplicateIDchecked each send againstcache.containsonly. In a client transaction the id is not in the cache yet:addToCache(duplID, tx, false)adds it after the commit, so that a client resending a transaction after a failure is not rejected. A second send of the same id in the same transaction therefore passed the check too, and the commit delivered both messages (and added the id to the cache twice, see ARTEMIS-6361).The ids a transaction sends are now kept in the transaction, by cache, and a send whose id the transaction already sent is a duplicate: the transaction is marked rollback-only, as for an id already in the cache. Other transactions do not see them, so a resent transaction is still accepted.
DuplicateDetectionTest.testSameIdTwiceInOneTransactionsends two messages with the same id in one transaction, expects the commit to fail withActiveMQDuplicateIdExceptionand no message to arrive, then sends the id in a new transaction and gets it. It fails without the fix.https://issues.apache.org/jira/browse/ARTEMIS-6360