Skip to content

Commit

Permalink
update Tsubakuro (change SqlServiceCode)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishidama committed Sep 4, 2023
1 parent 0db89ea commit aefdb62
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import org.slf4j.LoggerFactory;

import com.tsurugidb.benchmark.costaccounting.batch.BatchConfig;
import com.tsurugidb.iceaxe.exception.TsurugiExceptionUtil;
import com.tsurugidb.iceaxe.transaction.TsurugiTransaction;
import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException;
import com.tsurugidb.iceaxe.transaction.manager.option.TgTmTxOptionAlways;
import com.tsurugidb.iceaxe.transaction.manager.retry.TgTmRetryInstruction;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;
import com.tsurugidb.tsubakuro.sql.SqlServiceCode;

public class BenchBatchTxOption extends TgTmTxOptionAlways {
private static final Logger LOG = LoggerFactory.getLogger(BenchBatchTxOption.class);
Expand Down Expand Up @@ -47,8 +47,9 @@ public BenchBatchTxOption(TgTxOption option) {

@Override
protected TgTmRetryInstruction isRetryable(TsurugiTransaction transaction, TsurugiTransactionException e) throws IOException, InterruptedException {
var code = e.getDiagnosticCode();
if (code == SqlServiceCode.ERR_INACTIVE_TRANSACTION) {
var exceptionUtil = TsurugiExceptionUtil.getInstance();
if (exceptionUtil.isInactiveTransaction(e)) {
var code = e.getDiagnosticCode();
return TgTmRetryInstruction.ofRetryable(code);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

import com.tsurugidb.benchmark.costaccounting.batch.task.BenchBatchTxOption;
import com.tsurugidb.iceaxe.exception.TsurugiDiagnosticCodeProvider;
import com.tsurugidb.iceaxe.exception.TsurugiExceptionUtil;
import com.tsurugidb.iceaxe.transaction.TsurugiTransaction;
import com.tsurugidb.iceaxe.transaction.manager.TgTmSetting;
import com.tsurugidb.iceaxe.transaction.manager.TsurugiTransactionManager;
import com.tsurugidb.iceaxe.transaction.manager.event.counter.TgTmCount;
import com.tsurugidb.iceaxe.transaction.manager.event.counter.TgTmLabelCounter;
import com.tsurugidb.iceaxe.transaction.manager.option.TgTmTxOption;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;
import com.tsurugidb.tsubakuro.sql.SqlServiceCode;

public class BenchDbCounter extends TgTmLabelCounter {

Expand Down Expand Up @@ -141,11 +141,12 @@ public void transactionException(TsurugiTransaction transaction, Throwable e) {
}

if (e instanceof TsurugiDiagnosticCodeProvider) {
var code = ((TsurugiDiagnosticCodeProvider) e).getDiagnosticCode();
if (code == SqlServiceCode.ERR_CONFLICT_ON_WRITE_PRESERVE) {
var t = (TsurugiDiagnosticCodeProvider) e;
var exceptionUtil = TsurugiExceptionUtil.getInstance();
if (exceptionUtil.isConflictOnWritePreserve(t)) {
counter.conflictOnWp.incrementAndGet();
}
if (code == SqlServiceCode.ERR_SERIALIZATION_FAILURE) {
if (exceptionUtil.isSerializationFailure(t)) {
String message = e.getMessage();
if (message.contains("shirakami response Status=ERR_CC")) {
if (message.contains("reason_code:CC_OCC_WP_VERIFY")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.iceaxe.TsurugiConnector;
import com.tsurugidb.iceaxe.exception.TsurugiDiagnosticCodeProvider;
import com.tsurugidb.iceaxe.exception.TsurugiExceptionUtil;
import com.tsurugidb.iceaxe.session.TgSessionOption;
import com.tsurugidb.iceaxe.session.TsurugiSession;
import com.tsurugidb.iceaxe.session.event.logging.file.TsurugiSessionTxFileLogConfig;
Expand All @@ -46,7 +47,6 @@
import com.tsurugidb.iceaxe.transaction.manager.exception.TsurugiTmIOException;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;
import com.tsurugidb.tsubakuro.channel.common.connection.UsernamePasswordCredential;
import com.tsurugidb.tsubakuro.sql.SqlServiceCode;

public class CostBenchDbManagerIceaxe extends CostBenchDbManager {
private static final Logger LOG = LoggerFactory.getLogger(CostBenchDbManagerIceaxe.class);
Expand Down Expand Up @@ -271,11 +271,11 @@ public <T> T execute(TgTmSetting setting, Supplier<T> supplier) {
}
});
} catch (TsurugiTmIOException e) {
var code = e.getDiagnosticCode();
if (code == SqlServiceCode.ERR_UNIQUE_CONSTRAINT_VIOLATION) {
var exceptionUtil = TsurugiExceptionUtil.getInstance();
if (exceptionUtil.isUniqueConstraintViolation(e)) {
throw new UniqueConstraintException(e);
}
if (code == SqlServiceCode.ERR_SERIALIZATION_FAILURE) {
if (exceptionUtil.isSerializationFailure(e)) {
String message = e.getMessage();
if (message.contains("reason_code:KVS_INSERT")) {
throw new UniqueConstraintException(e);
Expand Down Expand Up @@ -305,14 +305,14 @@ public boolean isRetryable(Throwable t) {
}

protected boolean isRetyiableTsurugiException(TsurugiDiagnosticCodeProvider e) {
var code = e.getDiagnosticCode();
if (code == SqlServiceCode.ERR_SERIALIZATION_FAILURE) {
var exceptionUtil = TsurugiExceptionUtil.getInstance();
if (exceptionUtil.isSerializationFailure(e)) {
return true;
}
if (code == SqlServiceCode.ERR_CONFLICT_ON_WRITE_PRESERVE) {
if (exceptionUtil.isConflictOnWritePreserve(e)) {
return true;
}
if (code == SqlServiceCode.ERR_INACTIVE_TRANSACTION) {
if (exceptionUtil.isInactiveTransaction(e)) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.tsurugidb.benchmark.costaccounting.db.iceaxe.CostBenchDbManagerIceaxe;
import com.tsurugidb.benchmark.costaccounting.db.iceaxe.dao.IceaxeColumn.RecordGetter;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.iceaxe.exception.TsurugiExceptionUtil;
import com.tsurugidb.iceaxe.session.TsurugiSession;
import com.tsurugidb.iceaxe.sql.TsurugiSql;
import com.tsurugidb.iceaxe.sql.TsurugiSqlPreparedQuery;
Expand All @@ -45,7 +46,6 @@
import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException;
import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionRuntimeException;
import com.tsurugidb.tsubakuro.explain.PlanGraph;
import com.tsurugidb.tsubakuro.sql.SqlServiceCode;

public abstract class IceaxeDao<E> {
protected final Logger LOG = LoggerFactory.getLogger(getClass());
Expand Down Expand Up @@ -376,8 +376,8 @@ private final <P> int[] executeAndGetCount(TsurugiSqlPreparedStatement<P> ps, Co
}

private boolean isUniqueConstraint(TsurugiTransactionException e) {
var code = e.getDiagnosticCode();
if (code == SqlServiceCode.ERR_UNIQUE_CONSTRAINT_VIOLATION) {
var exceptionUtil = TsurugiExceptionUtil.getInstance();
if (exceptionUtil.isUniqueConstraintViolation(e)) {
// 同一トランザクション内でinsertの一意制約違反
return true;
}
Expand All @@ -403,18 +403,10 @@ protected final <R> List<R> executeAndGetList(TsurugiSqlQuery<R> ps) {
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (TsurugiTransactionException e) {
wipRetry(e);
throw new TsurugiTransactionRuntimeException(e);
}
}

// TODO 暫定リトライ判定を廃止して正式版にする
private void wipRetry(TsurugiTransactionException e) {
if (e.getDiagnosticCode() == SqlServiceCode.ERR_ABORTED) {
throw new TsurugiTransactionRuntimeException(new TsurugiTransactionException("(WIP) retry", SqlServiceCode.ERR_SERIALIZATION_FAILURE, e));
}
}

protected abstract class CachePreparedQuery<P, R> extends AbstractCache<TsurugiSqlPreparedQuery<P, R>> {
protected TgParameterMapping<P> parameterMapping;
protected TgResultMapping<R> resultMapping;
Expand All @@ -435,7 +427,6 @@ protected final <R> R executeAndGetRecord(TsurugiSqlQuery<R> ps) {
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (TsurugiTransactionException e) {
wipRetry(e);
throw new TsurugiTransactionRuntimeException(e);
}
}
Expand All @@ -450,7 +441,6 @@ protected final <P, R> R executeAndGetRecord(TsurugiSqlPreparedQuery<P, R> ps, P
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (TsurugiTransactionException e) {
wipRetry(e);
throw new TsurugiTransactionRuntimeException(e);
}
}
Expand All @@ -465,7 +455,6 @@ protected final <P, R> List<R> executeAndGetList(TsurugiSqlPreparedQuery<P, R> p
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (TsurugiTransactionException e) {
wipRetry(e);
throw new TsurugiTransactionRuntimeException(e);
}
}
Expand All @@ -491,7 +480,6 @@ protected final <R> Stream<R> executeAndGetStream(TsurugiSqlQuery<R> ps) {
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (TsurugiTransactionException e) {
wipRetry(e);
throw new TsurugiTransactionRuntimeException(e);
}
}
Expand All @@ -517,7 +505,6 @@ protected final <P, R> Stream<R> executeAndGetStream(TsurugiSqlPreparedQuery<P,
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (TsurugiTransactionException e) {
wipRetry(e);
throw new TsurugiTransactionRuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import com.tsurugidb.tsubakuro.common.SessionBuilder;
import com.tsurugidb.tsubakuro.exception.ServerException;
import com.tsurugidb.tsubakuro.sql.SqlClient;
import com.tsurugidb.tsubakuro.sql.SqlServiceCode;
import com.tsurugidb.tsubakuro.sql.Transaction;
import com.tsurugidb.tsubakuro.sql.exception.CcException;
import com.tsurugidb.tsubakuro.sql.exception.TargetNotFoundException;
import com.tsurugidb.tsubakuro.sql.exception.UniqueConstraintViolationException;

public class CostBenchDbManagerTsubakuro extends CostBenchDbManager {
private static final Logger LOG = LoggerFactory.getLogger(CostBenchDbManagerTsubakuro.class);
Expand Down Expand Up @@ -141,7 +143,7 @@ public void executeDdl() {
try {
sqlClient.getTableMetadata(tableName).await();
} catch (ServerException e) {
if (e.getDiagnosticCode() == SqlServiceCode.ERR_NOT_FOUND) {
if (e instanceof TargetNotFoundException) {
continue;
}
throw new RuntimeException(e);
Expand Down Expand Up @@ -227,9 +229,8 @@ public <T> T execute(TgTmSetting setting, Supplier<T> supplier) {
counter.increment(setting, CounterName.ABORTED);
rollback();
// TODO abort retry
var code = e.getDiagnosticCode();
// FIXME コミット時の一意制約違反の判定方法
if (code == SqlServiceCode.ERR_UNIQUE_CONSTRAINT_VIOLATION) {
if (e instanceof UniqueConstraintViolationException) {
throw new UniqueConstraintException(e);
}
throw new RuntimeException(e);
Expand Down Expand Up @@ -258,8 +259,7 @@ public boolean isRetryable(Throwable t) {
}

protected boolean isRetyiableTsurugiException(ServerException e) {
var code = e.getDiagnosticCode();
return code == SqlServiceCode.ERR_SERIALIZATION_FAILURE;
return e instanceof CcException;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.iceaxe.TsurugiConnector;
import com.tsurugidb.iceaxe.exception.TsurugiExceptionUtil;
import com.tsurugidb.iceaxe.session.TsurugiSession;
import com.tsurugidb.iceaxe.sql.TsurugiSqlPreparedStatement;
import com.tsurugidb.iceaxe.sql.TsurugiSqlQuery;
Expand All @@ -30,7 +31,6 @@
import com.tsurugidb.iceaxe.transaction.manager.TgTmSetting;
import com.tsurugidb.iceaxe.transaction.manager.exception.TsurugiTmIOException;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;
import com.tsurugidb.tsubakuro.sql.SqlServiceCode;

/**
* iceaxe-dbtest DbInsertDuplicate2Test
Expand Down Expand Up @@ -216,7 +216,8 @@ public Void call() throws Exception {
execute(transaction, maxPs, insertPs, insert2Ps);
});
} catch (TsurugiTmIOException e) {
if (e.getDiagnosticCode() == SqlServiceCode.ERR_UNIQUE_CONSTRAINT_VIOLATION) {
var exceptionUtil = TsurugiExceptionUtil.getInstance();
if (exceptionUtil.isUniqueConstraintViolation(e)) {
// LOG.info("ERR_UNIQUE_CONSTRAINT_VIOLATION {}", i);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tsurugidb.benchmark.costaccounting.online;

import java.io.IOException;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.util.ArrayList;
Expand Down Expand Up @@ -39,13 +38,8 @@
import com.tsurugidb.benchmark.costaccounting.online.task.BenchOnlineUpdateMaterialTask;
import com.tsurugidb.benchmark.costaccounting.online.task.BenchTask;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.iceaxe.transaction.TsurugiTransaction;
import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException;
import com.tsurugidb.iceaxe.transaction.manager.TgTmSetting;
import com.tsurugidb.iceaxe.transaction.manager.retry.TgTmRetryInstruction;
import com.tsurugidb.iceaxe.transaction.manager.retry.TsurugiDefaultRetryPredicate;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;
import com.tsurugidb.tsubakuro.sql.SqlServiceCode;

public class CostAccountingOnline {
private static final Logger LOG = LoggerFactory.getLogger(CostAccountingOnline.class);
Expand Down Expand Up @@ -127,18 +121,6 @@ public static OnlineConfig createDefaultConfig(LocalDate batchDate, boolean txOp
}

public static CostBenchDbManager createDbManager(OnlineConfig config) {
TsurugiDefaultRetryPredicate.setInstance(new TsurugiDefaultRetryPredicate() {
@Override
protected TgTmRetryInstruction testOcc(TsurugiTransaction transaction, TsurugiTransactionException e) throws IOException, InterruptedException {
var code = e.getDiagnosticCode();
if (code == SqlServiceCode.ERR_ABORTED) {
return TgTmRetryInstruction.ofRetryable(code);
}

return super.testOcc(transaction, e);
}
});

var type = BenchConst.onlineDbManagerType();
var isolationLevel = config.getIsolationLevel();
boolean isMultiSession = config.isMultiSession();
Expand Down

0 comments on commit aefdb62

Please sign in to comment.