From 5d3ca42bdbd45af04d4fc4bcac6cf580ed5cc3ed Mon Sep 17 00:00:00 2001 From: Jolyon Shah Date: Wed, 9 Jun 2021 16:29:55 +0100 Subject: [PATCH 1/2] actually useful --- .../api/TransactionConflictException.java | 13 +++++++++++-- .../TransactionSerializableConflictException.java | 11 +++++++++-- .../transaction/impl/SerializableTransaction.java | 12 +++++++----- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionConflictException.java b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionConflictException.java index 467b04c5a5b..ac578646681 100644 --- a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionConflictException.java +++ b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionConflictException.java @@ -80,6 +80,7 @@ public final String toString() { private final ImmutableList spanningWrites; private final ImmutableList dominatingWrites; + private final TableReference conflictingTable; /** * These conflicts had a start timestamp before our start and a commit timestamp after our start. @@ -96,6 +97,10 @@ public Collection getDominatingWrites() { return dominatingWrites; } + public TableReference getConflictingTable() { + return conflictingTable; + } + public static TransactionConflictException create( TableReference tableRef, long timestamp, @@ -122,7 +127,7 @@ public static TransactionConflictException create( formatConflicts(dominatingWrites, sb); sb.append('\n'); } - return new TransactionConflictException(sb.toString(), spanningWrites, dominatingWrites); + return new TransactionConflictException(sb.toString(), spanningWrites, dominatingWrites, tableRef); } private static void formatConflicts(Collection conflicts, StringBuilder sb) { @@ -136,9 +141,13 @@ private static void formatConflicts(Collection conflicts, StringBu } private TransactionConflictException( - String message, Collection spanningWrites, Collection dominatingWrites) { + String message, + Collection spanningWrites, + Collection dominatingWrites, + TableReference conflictingTable) { super(message); this.spanningWrites = ImmutableList.copyOf(spanningWrites); this.dominatingWrites = ImmutableList.copyOf(dominatingWrites); + this.conflictingTable = conflictingTable; } } diff --git a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionSerializableConflictException.java b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionSerializableConflictException.java index 016cad3487d..a878178e896 100644 --- a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionSerializableConflictException.java +++ b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionSerializableConflictException.java @@ -20,8 +20,11 @@ public class TransactionSerializableConflictException extends TransactionFailedRetriableException { private static final long serialVersionUID = 1L; - public TransactionSerializableConflictException(String message) { + private final TableReference conflictingTable; + + public TransactionSerializableConflictException(String message, TableReference conflictingTable) { super(message); + this.conflictingTable = conflictingTable; } public static TransactionSerializableConflictException create( @@ -31,6 +34,10 @@ public static TransactionSerializableConflictException create( + " and another transaction wrote a different value than this transaction read. startTs: %d " + " elapsedMillis: %d", tableRef.getQualifiedName(), timestamp, elapsedMillis); - return new TransactionSerializableConflictException(msg); + return new TransactionSerializableConflictException(msg, tableRef); + } + + public TableReference getConflictingTable() { + return conflictingTable; } } diff --git a/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/transaction/impl/SerializableTransaction.java b/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/transaction/impl/SerializableTransaction.java index c145524e0e7..a904661f17b 100644 --- a/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/transaction/impl/SerializableTransaction.java +++ b/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/transaction/impl/SerializableTransaction.java @@ -924,11 +924,13 @@ private ListenableFuture> getCommitTimestampsForTransactionsStar // should just fail out early. It may be the case that abort more transactions // than needed to break the deadlock cycle, but this should be pretty rare. transactionOutcomeMetrics.markReadWriteConflict(tableRef); - throw new TransactionSerializableConflictException("An uncommitted conflicting read was " - + "written after our start timestamp for table " - + tableRef + ". " - + "This case can cause deadlock and is very likely to be a " - + "read write conflict."); + throw new TransactionSerializableConflictException( + "An uncommitted conflicting read was " + + "written after our start timestamp for table " + + tableRef + ". " + + "This case can cause deadlock and is very likely to be a " + + "read write conflict.", + tableRef); }, MoreExecutors.directExecutor()); } From 617739ef2e21bb960802d1b8d4cdb5c79e28cd90 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Wed, 9 Jun 2021 15:33:40 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-5497.v2.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/@unreleased/pr-5497.v2.yml diff --git a/changelog/@unreleased/pr-5497.v2.yml b/changelog/@unreleased/pr-5497.v2.yml new file mode 100644 index 00000000000..34e36860396 --- /dev/null +++ b/changelog/@unreleased/pr-5497.v2.yml @@ -0,0 +1,6 @@ +type: improvement +improvement: + description: '`TransactionConflictException` and `TransactionSerializableConflictException` + now track the conflicting table, which can be retrieved via a getter.' + links: + - https://github.com/palantir/atlasdb/pull/5497