Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Make TransactionConflictExceptions actually useful #5497

Merged
merged 2 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public final String toString() {

private final ImmutableList<CellConflict> spanningWrites;
private final ImmutableList<CellConflict> dominatingWrites;
private final TableReference conflictingTable;

/**
* These conflicts had a start timestamp before our start and a commit timestamp after our start.
Expand All @@ -96,6 +97,10 @@ public Collection<CellConflict> getDominatingWrites() {
return dominatingWrites;
}

public TableReference getConflictingTable() {
return conflictingTable;
}

public static TransactionConflictException create(
TableReference tableRef,
long timestamp,
Expand All @@ -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<CellConflict> conflicts, StringBuilder sb) {
Expand All @@ -136,9 +141,13 @@ private static void formatConflicts(Collection<CellConflict> conflicts, StringBu
}

private TransactionConflictException(
String message, Collection<CellConflict> spanningWrites, Collection<CellConflict> dominatingWrites) {
String message,
Collection<CellConflict> spanningWrites,
Collection<CellConflict> dominatingWrites,
TableReference conflictingTable) {
super(message);
this.spanningWrites = ImmutableList.copyOf(spanningWrites);
this.dominatingWrites = ImmutableList.copyOf(dominatingWrites);
this.conflictingTable = conflictingTable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,13 @@ private ListenableFuture<Map<Long, Long>> 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);
Comment on lines +927 to +933
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotless apparently.

},
MoreExecutors.directExecutor());
}
Expand Down
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-5497.v2.yml
Original file line number Diff line number Diff line change
@@ -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