From c3596bfd111e171197dcc53e827141562f0ea356 Mon Sep 17 00:00:00 2001 From: Hishida Masato Date: Wed, 26 Jul 2023 17:53:31 +0900 Subject: [PATCH] Added read area --- .../costaccounting/batch/BatchConfig.java | 3 +-- .../batch/CostAccountingBatch.java | 18 ++++++++++++++++-- .../batch/command/BatchCbCommand.java | 2 +- .../online/command/OnlineCbCommand.java | 4 +--- .../BenchPeriodicUpdateStockTask.java | 10 +++++++++- .../online/task/BenchOnlineNewItemTask.java | 19 +++++++++++++++++-- .../task/BenchOnlineUpdateCostAddTask.java | 11 ++++++++++- .../task/BenchOnlineUpdateCostSubTask.java | 10 +++++++++- .../BenchOnlineUpdateManufacturingTask.java | 10 +++++++++- .../task/BenchOnlineUpdateMaterialTask.java | 10 +++++++++- .../costaccounting/util/BenchConst.java | 11 +++++++++++ 11 files changed, 93 insertions(+), 15 deletions(-) diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/BatchConfig.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/BatchConfig.java index 21edbaee..1698905f 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/BatchConfig.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/BatchConfig.java @@ -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; @@ -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: diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/CostAccountingBatch.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/CostAccountingBatch.java index e6a6a6fb..a976d2b7 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/CostAccountingBatch.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/CostAccountingBatch.java @@ -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; @@ -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); diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/command/BatchCbCommand.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/command/BatchCbCommand.java index d87bf975..7c7b9bf4 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/command/BatchCbCommand.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/batch/command/BatchCbCommand.java @@ -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; } } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/command/OnlineCbCommand.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/command/OnlineCbCommand.java index 5c536be4..f99b008b 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/command/OnlineCbCommand.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/command/OnlineCbCommand.java @@ -17,7 +17,6 @@ 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; @@ -25,7 +24,6 @@ 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); @@ -108,7 +106,7 @@ private int execute1(OnlineConfig config, int attempt, List 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); diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/periodic/BenchPeriodicUpdateStockTask.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/periodic/BenchPeriodicUpdateStockTask.java index 0d4e5d9f..e858c5d5 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/periodic/BenchPeriodicUpdateStockTask.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/periodic/BenchPeriodicUpdateStockTask.java @@ -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; @@ -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); } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineNewItemTask.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineNewItemTask.java index bacb4d9f..2f06bdb9 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineNewItemTask.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineNewItemTask.java @@ -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; @@ -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); } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateCostAddTask.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateCostAddTask.java index 148905c9..c35f0af2 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateCostAddTask.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateCostAddTask.java @@ -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; @@ -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); } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateCostSubTask.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateCostSubTask.java index ac380a24..621e4dfd 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateCostSubTask.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateCostSubTask.java @@ -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; @@ -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); } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateManufacturingTask.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateManufacturingTask.java index cc56870a..cab6df74 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateManufacturingTask.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateManufacturingTask.java @@ -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; @@ -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); } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateMaterialTask.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateMaterialTask.java index 239e1e5f..4395805b 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateMaterialTask.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineUpdateMaterialTask.java @@ -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; @@ -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); } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/util/BenchConst.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/util/BenchConst.java index 9d667091..a8127438 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/util/BenchConst.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/util/BenchConst.java @@ -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 暫定回避策廃止 @@ -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;