From f2826ee4228f16961b9924e8781bc0392e984ef1 Mon Sep 17 00:00:00 2001 From: Yang Yuming <50571168+YangYumings@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:41:52 +0800 Subject: [PATCH] Prevent duplicate creation of the same table (#465) * Prevent duplicate creation of the same table * One thread is responsible for creating all the tables. * Collect all table names. * spotless:apply * Each thread creates the table that it is responsible for. * Each thread creates the table that it is responsible for. --- .../iotdb200/ModelStrategy/TableStrategy.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/iotdb-2.0/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb200/ModelStrategy/TableStrategy.java b/iotdb-2.0/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb200/ModelStrategy/TableStrategy.java index 3b542c2a4..a29f7abbf 100644 --- a/iotdb-2.0/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb200/ModelStrategy/TableStrategy.java +++ b/iotdb-2.0/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb200/ModelStrategy/TableStrategy.java @@ -96,11 +96,14 @@ public void registerDatabases(Session metaSession, List schema private void registerTable(Session metaSession, List timeseriesSchemas) throws TsdbException { try { + // get all tables + Set tableNames = getAllTables(timeseriesSchemas); + // register tables + DeviceSchema deviceSchema = timeseriesSchemas.get(0).getDeviceSchema(); HashMap> tables = new HashMap<>(); - for (TimeseriesSchema timeseriesSchema : timeseriesSchemas) { - DeviceSchema deviceSchema = timeseriesSchema.getDeviceSchema(); + for (String tableName : tableNames) { StringBuilder builder = new StringBuilder(); - builder.append("create table if not exists ").append(deviceSchema.getTable()).append("("); + builder.append("create table if not exists ").append(tableName).append("("); for (int i = 0; i < deviceSchema.getSensors().size(); i++) { if (i != 0) builder.append(", "); builder @@ -143,6 +146,15 @@ private void registerTable(Session metaSession, List timeserie } } + public Set getAllTables(List schemaList) { + Set tableNames = new HashSet<>(); + for (TimeseriesSchema timeseriesSchema : schemaList) { + DeviceSchema schema = timeseriesSchema.getDeviceSchema(); + tableNames.add(schema.getTable()); + } + return tableNames; + } + // region select @Override