Skip to content

Commit

Permalink
chore: cleanup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Apr 13, 2021
1 parent 6c14164 commit 510fdb3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
Expand Up @@ -69,7 +69,7 @@ interface ConnectionStatementExecutor {
StatementResult statementSetReturnCommitStats(Boolean returnCommitStats);

StatementResult statementShowReturnCommitStats();

StatementResult statementSetStatementTag(String tag);

StatementResult statementShowStatementTag();
Expand Down
Expand Up @@ -246,7 +246,7 @@ public StatementResult statementShowReturnCommitStats() {
return resultSet(
"RETURN_COMMIT_STATS", getConnection().isReturnCommitStats(), SHOW_RETURN_COMMIT_STATS);
}

@Override
public StatementResult statementSetStatementTag(String tag) {
getConnection().setStatementTag("".equals(tag) ? null : tag);
Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.google.cloud.spanner.Mutation;
import com.google.cloud.spanner.Options;
import com.google.cloud.spanner.Options.QueryOption;
import com.google.cloud.spanner.Options.TransactionOption;
import com.google.cloud.spanner.Options.UpdateOption;
import com.google.cloud.spanner.ResultSet;
import com.google.cloud.spanner.SpannerException;
Expand Down Expand Up @@ -72,7 +73,7 @@ class ReadWriteTransaction extends AbstractMultiUseTransaction {
private static final int MAX_INTERNAL_RETRIES = 50;
private final long transactionId;
private final DatabaseClient dbClient;
private TransactionManager txManager;
private final TransactionManager txManager;
private final boolean retryAbortsInternally;
private int transactionRetryAttempts;
private int successfulRetries;
Expand Down Expand Up @@ -138,10 +139,22 @@ private ReadWriteTransaction(Builder builder) {
this.dbClient = builder.dbClient;
this.retryAbortsInternally = builder.retryAbortsInternally;
this.transactionRetryListeners = builder.transactionRetryListeners;
this.txManager =
builder.returnCommitStats
? dbClient.transactionManager(Options.commitStats())
: dbClient.transactionManager();
int numOptions = 0;
if (builder.returnCommitStats) {
numOptions++;
}
if (this.transactionTag != null) {
numOptions++;
}
TransactionOption[] options = new TransactionOption[numOptions];
int index = 0;
if (builder.returnCommitStats) {
options[index++] = Options.commitStats();
}
if (this.transactionTag != null) {
options[index++] = Options.tag(this.transactionTag);
}
this.txManager = dbClient.transactionManager(options);
}

@Override
Expand Down Expand Up @@ -192,11 +205,7 @@ void checkValidTransaction() {
new Callable<TransactionContext>() {
@Override
public TransactionContext call() throws Exception {
TransactionContext context = txManager.begin();
if (transactionTag != null) {
context.withTransactionTag(transactionTag);
}
return context;
return txManager.begin();
}
},
SpannerGrpc.getBeginTransactionMethod());
Expand Down Expand Up @@ -768,9 +777,6 @@ private void handleAborted(AbortedException aborted) {
}
try {
TransactionContext context = txManager.resetForRetry();
if (transactionTag != null) {
context.withTransactionTag(transactionTag);
}
txContextFuture = ApiFutures.immediateFuture(context);
// Inform listeners about the transaction retry that is about to start.
invokeTransactionRetryListenersOnStart();
Expand Down
Expand Up @@ -311,6 +311,7 @@
"converterName": "ClientSideStatementValueConverters$BooleanConverter"
}
},
{
"name": "SET STATEMENT_TAG = '<tag>'",
"executorName": "ClientSideStatementSetExecutor",
"resultType": "NO_RESULT",
Expand Down
Expand Up @@ -1941,10 +1941,6 @@ public List<AbstractMessage> getRequests() {
return new ArrayList<>(this.requests);
}

public void clearRequests() {
this.requests.clear();
}

@SuppressWarnings("unchecked")
public <T extends AbstractMessage> List<T> getRequestsOfType(Class<T> type) {
List<T> result = new ArrayList<>();
Expand Down Expand Up @@ -1974,17 +1970,6 @@ public int countRequestsOfType(Class<? extends AbstractMessage> type) {
return c;
}

@SuppressWarnings("unchecked")
public <T extends AbstractMessage> List<T> getRequestsOfType(Class<T> type) {
List<T> res = new ArrayList<>();
for (AbstractMessage m : this.requests) {
if (m.getClass().equals(type)) {
res.add((T) m);
}
}
return res;
}

public void waitForLastRequestToBe(Class<? extends AbstractMessage> type, long timeoutMillis)
throws InterruptedException, TimeoutException {
Stopwatch watch = Stopwatch.createStarted();
Expand Down
Expand Up @@ -1514,14 +1514,14 @@ public void testTransactionTagNotAllowedAfterTransactionStarted() {
when(unitOfWork.executeQueryAsync(
any(ParsedStatement.class), any(AnalyzeMode.class), Mockito.<QueryOption>anyVararg()))
.thenReturn(ApiFutures.immediateFuture(mock(ResultSet.class)));
when(unitOfWork.rollbackAsync()).thenReturn(ApiFutures.immediateFuture(null));
try (ConnectionImpl connection =
new ConnectionImpl(connectionOptions, spannerPool, ddlClient, dbClient) {
@Override
UnitOfWork createNewUnitOfWork() {
return unitOfWork;
}
}) {

// Start a transaction
connection.execute(Statement.of("SELECT FOO FROM BAR"));
try {
Expand Down

0 comments on commit 510fdb3

Please sign in to comment.