Skip to content

Commit

Permalink
Added read area
Browse files Browse the repository at this point in the history
  • Loading branch information
hishidama committed Jul 26, 2023
1 parent a3554a3 commit c3596bf
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.slf4j.LoggerFactory;

import com.tsurugidb.benchmark.costaccounting.db.CostBenchDbManager.DbManagerPurpose;
import com.tsurugidb.benchmark.costaccounting.db.dao.ResultTableDao;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst.BatchFactoryOrder;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst.IsolationLevel;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;
Expand Down Expand Up @@ -148,7 +147,7 @@ public void setTxOptions(String txOptionProperty) {
private static TgTxOption createTxOption(String s) {
switch (s) {
case "LTX":
return TgTxOption.ofLTX(ResultTableDao.TABLE_NAME);
return CostAccountingBatch.BATCH_LTX_OPTION;
case "OCC":
return TgTxOption.ofOCC();
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
import com.tsurugidb.benchmark.costaccounting.batch.task.BenchBatchTxOption;
import com.tsurugidb.benchmark.costaccounting.db.CostBenchDbManager;
import com.tsurugidb.benchmark.costaccounting.db.CostBenchDbManager.DbManagerPurpose;
import com.tsurugidb.benchmark.costaccounting.db.dao.CostMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.FactoryMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.ItemConstructionMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.ItemManufacturingMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.ItemMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.MeasurementMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.ResultTableDao;
import com.tsurugidb.benchmark.costaccounting.db.entity.ItemManufacturingMaster;
import com.tsurugidb.benchmark.costaccounting.init.InitialData;
Expand All @@ -34,12 +38,22 @@
import com.tsurugidb.benchmark.costaccounting.util.BenchRandom;
import com.tsurugidb.iceaxe.transaction.manager.TgTmSetting;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;
import com.tsurugidb.iceaxe.transaction.option.TgTxOptionLtx;

public class CostAccountingBatch {
private static final Logger LOG = LoggerFactory.getLogger(CostAccountingBatch.class);

private static final TgTmSetting TX_BATCH = TgTmSetting.of( //
TgTxOption.ofLTX(ResultTableDao.TABLE_NAME));
public static final TgTxOptionLtx BATCH_LTX_OPTION;
static {
if (BenchConst.useReadArea()) {
BATCH_LTX_OPTION = TgTxOption.ofLTX(BenchConst.DEFAULT_TX_OPTION).addWritePreserve(ResultTableDao.TABLE_NAME) //
.addInclusiveReadArea(ItemManufacturingMasterDao.TABLE_NAME, ItemConstructionMasterDao.TABLE_NAME, ItemMasterDao.TABLE_NAME, CostMasterDao.TABLE_NAME,
MeasurementMasterDao.TABLE_NAME);
} else {
BATCH_LTX_OPTION = TgTxOption.ofLTX(ResultTableDao.TABLE_NAME);
}
}
private static final TgTmSetting TX_BATCH = TgTmSetting.of(BATCH_LTX_OPTION);

public static void main(String... args) {
int exitCode = main0(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private TgTxOption getOption(String s) {
case "OCC":
return TgTxOption.ofOCC();
default:
return TgTxOption.ofLTX(ResultTableDao.TABLE_NAME);
return CostAccountingBatch.BATCH_LTX_OPTION;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
import com.tsurugidb.benchmark.costaccounting.batch.StringUtil;
import com.tsurugidb.benchmark.costaccounting.db.CostBenchDbManager;
import com.tsurugidb.benchmark.costaccounting.db.CostBenchDbManager.DbManagerPurpose;
import com.tsurugidb.benchmark.costaccounting.db.dao.ResultTableDao;
import com.tsurugidb.benchmark.costaccounting.init.InitialData;
import com.tsurugidb.benchmark.costaccounting.online.CostAccountingOnline;
import com.tsurugidb.benchmark.costaccounting.online.OnlineConfig;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst.IsolationLevel;
import com.tsurugidb.benchmark.costaccounting.watcher.TsurugidbWatcher;
import com.tsurugidb.benchmark.costaccounting.watcher.TsurugidbWatcherService;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;

public class OnlineCbCommand implements ExecutableCommand {
private static final Logger LOG = LoggerFactory.getLogger(OnlineCbCommand.class);
Expand Down Expand Up @@ -108,7 +106,7 @@ private int execute1(OnlineConfig config, int attempt, List<OnlineResult> record
LOG.info("pre-batch start");
var preConfig = new BatchConfig(DbManagerPurpose.PRE_BATCH, BenchConst.PARALLEL_FACTORY_SESSION, config.getBatchDate(), null, 100);
preConfig.setIsolationLevel(IsolationLevel.READ_COMMITTED);
preConfig.setDefaultTxOption(TgTxOption.ofLTX(ResultTableDao.TABLE_NAME));
preConfig.setDefaultTxOption(CostAccountingBatch.BATCH_LTX_OPTION);
preConfig.setBatchFactoryOrder(BenchConst.getBatchFactoryOrder());
CostAccountingBatch.initializeConfig(preConfig);

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

import com.tsurugidb.benchmark.costaccounting.batch.StringUtil;
import com.tsurugidb.benchmark.costaccounting.db.CostBenchDbManager;
import com.tsurugidb.benchmark.costaccounting.db.dao.CostMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.StockHistoryDao;
import com.tsurugidb.benchmark.costaccounting.db.entity.CostMaster;
import com.tsurugidb.benchmark.costaccounting.db.entity.StockHistory;
Expand Down Expand Up @@ -50,7 +51,14 @@ public BenchPeriodicUpdateStockTask(int taskId) {

@Override
public void initializeSetting() {
this.settingMain = config.getSetting(LOG, this, () -> TgTxOption.ofLTX(StockHistoryDao.TABLE_NAME));
this.settingMain = config.getSetting(LOG, this, () -> {
if (BenchConst.useReadArea()) {
return TgTxOption.ofLTX(BenchConst.DEFAULT_TX_OPTION).addWritePreserve(StockHistoryDao.TABLE_NAME) //
.addInclusiveReadArea(CostMasterDao.TABLE_NAME);
} else {
return TgTxOption.ofLTX(StockHistoryDao.TABLE_NAME);
}
});
setTxOptionDescription(settingMain);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.tsurugidb.benchmark.costaccounting.init.InitialData;
import com.tsurugidb.benchmark.costaccounting.init.InitialData03ItemMaster;
import com.tsurugidb.benchmark.costaccounting.init.InitialData04ItemManufacturingMaster;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.iceaxe.transaction.manager.TgTmSetting;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;

Expand All @@ -44,8 +45,22 @@ public BenchOnlineNewItemTask(int taskId) {

@Override
public void initializeSetting() {
this.settingPre = config.getSetting(LOG, this, () -> TgTxOption.ofLTX(ItemMasterDao.TABLE_NAME, ItemConstructionMasterDao.TABLE_NAME));
this.settingMain = config.getSetting(LOG, this, () -> TgTxOption.ofLTX(ItemManufacturingMasterDao.TABLE_NAME));
this.settingPre = config.getSetting(LOG, this, () -> {
if (BenchConst.useReadArea()) {
return TgTxOption.ofLTX(BenchConst.DEFAULT_TX_OPTION).addWritePreserve(ItemMasterDao.TABLE_NAME, ItemConstructionMasterDao.TABLE_NAME) //
.addInclusiveReadArea(ItemMasterDao.TABLE_NAME);
} else {
return TgTxOption.ofLTX(ItemMasterDao.TABLE_NAME, ItemConstructionMasterDao.TABLE_NAME);
}
});
this.settingMain = config.getSetting(LOG, this, () -> {
if (BenchConst.useReadArea()) {
return TgTxOption.ofLTX(BenchConst.DEFAULT_TX_OPTION).addWritePreserve(ItemManufacturingMasterDao.TABLE_NAME) //
.addInclusiveReadArea(ItemManufacturingMasterDao.TABLE_NAME);
} else {
return TgTxOption.ofLTX(ItemManufacturingMasterDao.TABLE_NAME);
}
});
setTxOptionDescription(settingMain);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import com.tsurugidb.benchmark.costaccounting.db.CostBenchDbManager;
import com.tsurugidb.benchmark.costaccounting.db.dao.CostMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.ItemMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.dao.MeasurementMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.entity.CostMaster;
import com.tsurugidb.benchmark.costaccounting.db.entity.ItemMaster;
import com.tsurugidb.benchmark.costaccounting.init.InitialData;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.benchmark.costaccounting.util.MeasurementUtil;
import com.tsurugidb.iceaxe.transaction.manager.TgTmSetting;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;
Expand All @@ -30,7 +32,14 @@ public BenchOnlineUpdateCostAddTask(int taskId) {
@Override
public void initializeSetting() {
this.settingPre = TgTmSetting.ofAlways(TgTxOption.ofRTX().label(TASK_NAME + ".pre"));
this.settingMain = config.getSetting(LOG, this, () -> TgTxOption.ofLTX(CostMasterDao.TABLE_NAME));
this.settingMain = config.getSetting(LOG, this, () -> {
if (BenchConst.useReadArea()) {
return TgTxOption.ofLTX(BenchConst.DEFAULT_TX_OPTION).addWritePreserve(CostMasterDao.TABLE_NAME) //
.addInclusiveReadArea(CostMasterDao.TABLE_NAME, ItemMasterDao.TABLE_NAME, MeasurementMasterDao.TABLE_NAME);
} else {
return TgTxOption.ofLTX(CostMasterDao.TABLE_NAME);
}
});
setTxOptionDescription(settingMain);
this.coverRate = config.getCoverRateForTask(title);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.tsurugidb.benchmark.costaccounting.db.dao.CostMasterDao;
import com.tsurugidb.benchmark.costaccounting.db.entity.CostMaster;
import com.tsurugidb.benchmark.costaccounting.init.InitialData;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.iceaxe.transaction.manager.TgTmSetting;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;

Expand All @@ -27,7 +28,14 @@ public BenchOnlineUpdateCostSubTask(int taskId) {
@Override
public void initializeSetting() {
this.settingPre = TgTmSetting.ofAlways(TgTxOption.ofRTX().label(TASK_NAME + ".pre"));
this.settingMain = config.getSetting(LOG, this, () -> TgTxOption.ofLTX(CostMasterDao.TABLE_NAME));
this.settingMain = config.getSetting(LOG, this, () -> {
if (BenchConst.useReadArea()) {
return TgTxOption.ofLTX(BenchConst.DEFAULT_TX_OPTION).addWritePreserve(CostMasterDao.TABLE_NAME) //
.addInclusiveReadArea(CostMasterDao.TABLE_NAME);
} else {
return TgTxOption.ofLTX(CostMasterDao.TABLE_NAME);
}
});
setTxOptionDescription(settingMain);
this.coverRate = config.getCoverRateForTask(title);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.tsurugidb.benchmark.costaccounting.db.iceaxe.CostBenchDbManagerIceaxe;
import com.tsurugidb.benchmark.costaccounting.init.InitialData;
import com.tsurugidb.benchmark.costaccounting.init.InitialData04ItemManufacturingMaster;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.iceaxe.transaction.TgCommitType;
import com.tsurugidb.iceaxe.transaction.TsurugiTransaction;
import com.tsurugidb.iceaxe.transaction.event.TsurugiTransactionEventListener;
Expand Down Expand Up @@ -41,7 +42,14 @@ public BenchOnlineUpdateManufacturingTask(int taskId) {

@Override
public void initializeSetting() {
this.settingMain = config.getSetting(LOG, this, () -> TgTxOption.ofLTX(ItemManufacturingMasterDao.TABLE_NAME));
this.settingMain = config.getSetting(LOG, this, () -> {
if (BenchConst.useReadArea()) {
return TgTxOption.ofLTX(BenchConst.DEFAULT_TX_OPTION).addWritePreserve(ItemManufacturingMasterDao.TABLE_NAME) //
.addInclusiveReadArea(ItemManufacturingMasterDao.TABLE_NAME);
} else {
return TgTxOption.ofLTX(ItemManufacturingMasterDao.TABLE_NAME);
}
});
setTxOptionDescription(settingMain);
this.coverRate = config.getCoverRateForTask(title);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.tsurugidb.benchmark.costaccounting.db.entity.ItemMaster;
import com.tsurugidb.benchmark.costaccounting.init.InitialData;
import com.tsurugidb.benchmark.costaccounting.init.InitialData03ItemMaster;
import com.tsurugidb.benchmark.costaccounting.util.BenchConst;
import com.tsurugidb.iceaxe.transaction.manager.TgTmSetting;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;

Expand Down Expand Up @@ -45,7 +46,14 @@ public BenchOnlineUpdateMaterialTask(int taskId) {

@Override
public void initializeSetting() {
this.settingMain = config.getSetting(LOG, this, () -> TgTxOption.ofLTX(ItemConstructionMasterDao.TABLE_NAME));
this.settingMain = config.getSetting(LOG, this, () -> {
if (BenchConst.useReadArea()) {
return TgTxOption.ofLTX(BenchConst.DEFAULT_TX_OPTION).addWritePreserve(ItemConstructionMasterDao.TABLE_NAME) //
.addInclusiveReadArea(ItemConstructionMasterDao.TABLE_NAME, ItemMasterDao.TABLE_NAME);
} else {
return TgTxOption.ofLTX(ItemConstructionMasterDao.TABLE_NAME);
}
});
setTxOptionDescription(settingMain);
this.coverRate = config.getCoverRateForTask(title);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.slf4j.Logger;

import com.tsurugidb.benchmark.costaccounting.db.DbmsType;
import com.tsurugidb.iceaxe.transaction.option.TgTxOption;

public class BenchConst {
/** 暫定回避 */ // TODO 暫定回避策廃止
Expand Down Expand Up @@ -537,8 +538,18 @@ public static String timeCommandResultFile() {

// share

public static boolean useReadArea() {
return getPropertyBoolean("use.read-area", true);
}

public static final int DECIMAL_SCALE = getPropertyInt("decimal.scale", 20);

// Iceaxeのデフォルトトランザクションオプションの使用例
// 例えば原価計算ベンチマークと料金計算ベンチマークのテーブルが同じDBにあるとき、原価計算ベンチマークからは料金計算ベンチマークのテーブルを絶対参照しない。
// こうした絶対参照しないと分かっているテーブルをデフォルトトランザクションオプション(exclusive read area)として定義しておく。
/** Iceaxe default transaction option */
public static final TgTxOption DEFAULT_TX_OPTION = TgTxOption.ofLTX()/*.addExclusiveReadArea("billing", "contracts", "history")*/;

// properties

private static volatile Properties properties;
Expand Down

0 comments on commit c3596bf

Please sign in to comment.