From 85e7332d4580893670c190889772e1cd1e75cb83 Mon Sep 17 00:00:00 2001 From: Sonal Agarwal Date: Tue, 9 Jul 2024 14:36:53 +0530 Subject: [PATCH] Support for multiple drivers in tpcc (#150) Add support for multiple drivers, can be changed based on DB type. Co-authored-by: Sonal Agarwal --- config/workload_all.xml | 2 +- config/workload_all_pg.xml | 56 ++++ ivy.xml | 3 +- pom.xml | 12 +- src/com/oltpbenchmark/ConfigFileOptions.java | 4 + src/com/oltpbenchmark/DBWorkload.java | 3 + .../oltpbenchmark/WorkloadConfiguration.java | 8 + .../oltpbenchmark/api/BenchmarkModule.java | 81 ++++-- src/com/oltpbenchmark/api/Worker.java | 3 +- .../oltpbenchmark/schema/SchemaManager.java | 5 +- .../schema/SchemaManagerFactory.java | 2 +- .../schema/TPCCTableSchemas.java | 264 +++++++++--------- .../defaultschema/DefaultSchemaManager.java | 20 +- .../GeoPartitionedSchemaManager.java | 7 +- 14 files changed, 297 insertions(+), 173 deletions(-) create mode 100644 config/workload_all_pg.xml diff --git a/config/workload_all.xml b/config/workload_all.xml index 062b801..6663116 100644 --- a/config/workload_all.xml +++ b/config/workload_all.xml @@ -1,6 +1,6 @@ - postgres + yugabyte com.yugabyte.Driver 5433 yugabyte diff --git a/config/workload_all_pg.xml b/config/workload_all_pg.xml new file mode 100644 index 0000000..6d77682 --- /dev/null +++ b/config/workload_all_pg.xml @@ -0,0 +1,56 @@ + + + postgres + org.postgresql.Driver + 5432 + postgres + postgres + Password321 + TRANSACTION_REPEATABLE_READ + + + + + + 128 + true + true + true + 180000 + true + false + false + + + + NewOrder + 45 + + + Payment + 43 + + + OrderStatus + 4 + + + Delivery + 4 + + + StockLevel + 4 + + + + 1800 + 10000 + + 2 + 2 + + diff --git a/ivy.xml b/ivy.xml index 9843604..5f7f3d9 100644 --- a/ivy.xml +++ b/ivy.xml @@ -22,7 +22,8 @@ - + + diff --git a/pom.xml b/pom.xml index aed5f26..7c72d54 100644 --- a/pom.xml +++ b/pom.xml @@ -77,11 +77,17 @@ httpmime 4.3.1 - + com.yugabyte jdbc-yugabytedb - 42.3.5-yb-3 - + 42.3.5-yb-3 + + + + org.postgresql + postgresql + 42.4.5 + org.hsqldb hsqldb-j5 diff --git a/src/com/oltpbenchmark/ConfigFileOptions.java b/src/com/oltpbenchmark/ConfigFileOptions.java index 360a9b4..934c1f6 100644 --- a/src/com/oltpbenchmark/ConfigFileOptions.java +++ b/src/com/oltpbenchmark/ConfigFileOptions.java @@ -9,6 +9,10 @@ public ConfigFileOptions(String filePath) throws ConfigurationException { super(filePath); } + public String getDbType() { + return xmlConfig.getString("dbtype"); + } + public String getDbDriver() { return xmlConfig.getString("driver"); } diff --git a/src/com/oltpbenchmark/DBWorkload.java b/src/com/oltpbenchmark/DBWorkload.java index 9fc5a06..e5005d3 100644 --- a/src/com/oltpbenchmark/DBWorkload.java +++ b/src/com/oltpbenchmark/DBWorkload.java @@ -52,6 +52,7 @@ public class DBWorkload { private static final Map transactionTypes = new HashMap<>(); private static JsonMetricsHelper jsonMetricsHelper = new JsonMetricsHelper(); + public static String dbtype = ""; /** * Returns true if asserts are enabled. This assumes that * we're always using the default system ClassLoader @@ -159,6 +160,8 @@ public static void main(String[] args) throws Exception { wrkld.setNodes(nodes); wrkld.setDBName(configOptions.getDbName()); + wrkld.setDBType(configOptions.getDbType()); + DBWorkload.dbtype = configOptions.getDbType(); wrkld.setDBUsername(configOptions.getDbUsername()); wrkld.setDBPassword(configOptions.getDbPassword()); diff --git a/src/com/oltpbenchmark/WorkloadConfiguration.java b/src/com/oltpbenchmark/WorkloadConfiguration.java index f832ab7..1556118 100644 --- a/src/com/oltpbenchmark/WorkloadConfiguration.java +++ b/src/com/oltpbenchmark/WorkloadConfiguration.java @@ -41,6 +41,7 @@ public void setBenchmarkName(String benchmarkName) { } private List nodes; + private String db_type; private String db_name; private String db_username; private String db_password; @@ -117,6 +118,10 @@ public void setDBName(String dbname) { this.db_name = dbname; } + public void setDBType(String dbtype) { + this.db_type = dbtype; + } + public void setLoaderThreads(int loaderThreads) { this.loaderThreads = loaderThreads; } @@ -140,6 +145,9 @@ public String getDBName() { return db_name; } + public String getDBType() { + return db_type; + } public void setDBUsername(String username) { this.db_username = username; } diff --git a/src/com/oltpbenchmark/api/BenchmarkModule.java b/src/com/oltpbenchmark/api/BenchmarkModule.java index d237655..d5d3a44 100644 --- a/src/com/oltpbenchmark/api/BenchmarkModule.java +++ b/src/com/oltpbenchmark/api/BenchmarkModule.java @@ -90,9 +90,13 @@ public void createDataSource() { ThreadUtil.sleep(5000); } Properties props = new Properties(); - props.setProperty("dataSourceClassName", "com.yugabyte.ysql.YBClusterAwareDataSource"); - //props.setProperty("dataSource.serverNames", ip); - props.setProperty("dataSource.serverName", ip); + if(workConf.getDBType().equals("yugabyte")){ + props.setProperty("dataSourceClassName", "com.yugabyte.ysql.YBClusterAwareDataSource"); + } else { + props.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource"); + } + //props.setProperty("dataSource.serverNames", ip); + props.setProperty("dataSource.serverName", ip); props.setProperty("dataSource.portNumber", Integer.toString(workConf.getPort())); props.setProperty("dataSource.user", workConf.getDBUsername()); props.setProperty("dataSource.password", workConf.getDBPassword()); @@ -119,30 +123,57 @@ public void createDataSource() { } public final Connection makeConnection() throws SQLException { - YBClusterAwareDataSource ds = new YBClusterAwareDataSource(); - ds.setProperty("user", workConf.getDBUsername()); - ds.setProperty("password", workConf.getDBPassword()); - ds.setProperty("reWriteBatchedInserts", "true"); - - if (workConf.getSslCert() != null && workConf.getSslCert().length() > 0) { - assert(workConf.getSslKey().length() > 0) : "The SSL key is empty."; - ds.setProperty("sslmode", "require"); - ds.setProperty("sslcert", workConf.getSslCert()); - ds.setProperty("sslkey", workConf.getSslKey()); + Connection conn = null; + if(workConf.getDBType().equals("yugabyte")) { + YBClusterAwareDataSource ds = new YBClusterAwareDataSource(); + ds.setProperty("user", workConf.getDBUsername()); + ds.setProperty("password", workConf.getDBPassword()); + ds.setProperty("reWriteBatchedInserts", "true"); + + if (workConf.getSslCert() != null && workConf.getSslCert().length() > 0) { + assert (workConf.getSslKey().length() > 0) : "The SSL key is empty."; + ds.setProperty("sslmode", "require"); + ds.setProperty("sslcert", workConf.getSslCert()); + ds.setProperty("sslkey", workConf.getSslKey()); + } + int r = dataSourceCounter.getAndIncrement() % workConf.getNodes().size(); + String connectStr; + if (workConf.getJdbcURL() != null && workConf.getJdbcURL().length() > 0) { + connectStr = workConf.getJdbcURL(); + } else { + connectStr = String.format("jdbc:yugabytedb://%s:%d/%s", + workConf.getNodes().get(r), + workConf.getPort(), + workConf.getDBName()); + } + ds.setUrl(connectStr); + conn = ds.getConnection(); } + else { + java.util.Properties props = new java.util.Properties(); + props.put("user", workConf.getDBUsername()); + props.put("password", workConf.getDBPassword()); + props.put("reWriteBatchedInserts", "true"); - int r = dataSourceCounter.getAndIncrement() % workConf.getNodes().size(); - String connectStr; - if (workConf.getJdbcURL() != null && workConf.getJdbcURL().length()>0) { - connectStr=workConf.getJdbcURL(); - } else { - connectStr = String.format("jdbc:yugabytedb://%s:%d/%s", - workConf.getNodes().get(r), - workConf.getPort(), - workConf.getDBName()); + if (workConf.getSslCert() != null && workConf.getSslCert().length() > 0) { + assert (workConf.getSslKey().length() > 0) : "The SSL key is empty."; + props.put("sslmode", "require"); + props.put("sslcert", workConf.getSslCert()); + props.put("sslkey", workConf.getSslKey()); + } + int r = dataSourceCounter.getAndIncrement() % workConf.getNodes().size(); + String connectStr; + if (workConf.getJdbcURL() != null && workConf.getJdbcURL().length() > 0) { + connectStr = workConf.getJdbcURL(); + } else { + connectStr = String.format("jdbc:postgresql://%s:%d/%s", + workConf.getNodes().get(r), + workConf.getPort(), + workConf.getDBName()); + } + conn = DriverManager.getConnection(connectStr, props); } - ds.setUrl(connectStr); - return ds.getConnection(); + return conn; } private static final AtomicInteger dataSourceCounter = new AtomicInteger(0); @@ -199,7 +230,7 @@ public final void createDatabase() { try { Connection conn = makeConnection(); SchemaManager schemaManager = SchemaManagerFactory.getSchemaManager(workConf, conn); - schemaManager.create(); + schemaManager.create(workConf.getDBType()); conn.close(); } catch (SQLException ex) { throw new RuntimeException(String.format("Unexpected error when trying to create the %s database", this.benchmarkName), ex); diff --git a/src/com/oltpbenchmark/api/Worker.java b/src/com/oltpbenchmark/api/Worker.java index 845f77d..6fe92f1 100644 --- a/src/com/oltpbenchmark/api/Worker.java +++ b/src/com/oltpbenchmark/api/Worker.java @@ -482,7 +482,8 @@ protected final ArrayList> do conn = dataSource.getConnection(); try { - conn.createStatement().execute("SET yb_enable_expression_pushdown to on"); + if(wrkld.getDBType().equals("yugabyte")) + conn.createStatement().execute("SET yb_enable_expression_pushdown to on"); if (next.getProcedureClass() != StockLevel.class) { // In accordance with 2.8.2.3 of the TPCC spec, StockLevel should execute each query in its own Snapshot // Isolation. diff --git a/src/com/oltpbenchmark/schema/SchemaManager.java b/src/com/oltpbenchmark/schema/SchemaManager.java index c2e8105..0b5285c 100644 --- a/src/com/oltpbenchmark/schema/SchemaManager.java +++ b/src/com/oltpbenchmark/schema/SchemaManager.java @@ -15,13 +15,12 @@ public SchemaManager(Connection db_connection) { this.db_connection = db_connection; } - public abstract void create() throws SQLException; - + public abstract void create(String dbType) throws SQLException; public abstract void enableForeignKeyConstraints() throws SQLException; public abstract void dropForeignKeyConstraints() throws SQLException; - protected abstract void createIndexes() throws SQLException; + protected abstract void createIndexes(String dbType) throws SQLException; public static Set getTableNames() { return TPCCTableSchemas.tables.keySet(); diff --git a/src/com/oltpbenchmark/schema/SchemaManagerFactory.java b/src/com/oltpbenchmark/schema/SchemaManagerFactory.java index 3e48fc2..bbe43a5 100644 --- a/src/com/oltpbenchmark/schema/SchemaManagerFactory.java +++ b/src/com/oltpbenchmark/schema/SchemaManagerFactory.java @@ -10,6 +10,6 @@ public class SchemaManagerFactory { public static SchemaManager getSchemaManager(WorkloadConfiguration workConf, Connection conn) { return workConf.getGeoPartitioningEnabled() ? new GeoPartitionedSchemaManager(workConf.getGeoPartitioningPolicy(), conn) - : new DefaultSchemaManager(conn); + : new DefaultSchemaManager(conn, workConf.getDBType()); } } diff --git a/src/com/oltpbenchmark/schema/TPCCTableSchemas.java b/src/com/oltpbenchmark/schema/TPCCTableSchemas.java index adc1643..1e9cb38 100644 --- a/src/com/oltpbenchmark/schema/TPCCTableSchemas.java +++ b/src/com/oltpbenchmark/schema/TPCCTableSchemas.java @@ -5,139 +5,147 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import com.oltpbenchmark.DBWorkload; import com.oltpbenchmark.benchmarks.tpcc.TPCCConstants; public class TPCCTableSchemas { - public static final Map tables = Collections.unmodifiableMap(Stream.of( - new TableSchemaBuilder(TPCCConstants.TABLENAME_ORDERLINE) - .column("ol_w_id", "int ") - .column("ol_d_id", "int ") - .column("ol_o_id", "int ") - .column("ol_number", "int ") - .column("ol_i_id", "int ") - .column("ol_delivery_d", "timestamp NULL DEFAULT NULL") - .column("ol_amount", "decimal(6,2) ") - .column("ol_supply_w_id", "int ") - .column("ol_quantity", "decimal(2,0) ") - .column("ol_dist_info", "char(24) ") - .primaryKey("((ol_w_id,ol_d_id) HASH,ol_o_id,ol_number)") - .partitionKey("(ol_w_id)") - .build(), - new TableSchemaBuilder(TPCCConstants.TABLENAME_NEWORDER) - .column("no_w_id", "int ") - .column("no_d_id", "int ") - .column("no_o_id", "int ") - .primaryKey("((no_w_id,no_d_id) HASH,no_o_id)") - .partitionKey("(no_w_id)") - .build(), - new TableSchemaBuilder(TPCCConstants.TABLENAME_STOCK) - .column("s_w_id", "int ") - .column("s_i_id", "int ") - .column("s_quantity", "decimal(4,0) ") - .column("s_ytd", "decimal(8,2) ") - .column("s_order_cnt", "int ") - .column("s_remote_cnt", "int ") - .column("s_data", "varchar(50) ") - .column("s_dist_01", "char(24) ") - .column("s_dist_02", "char(24) ") - .column("s_dist_03", "char(24) ") - .column("s_dist_04", "char(24) ") - .column("s_dist_05", "char(24) ") - .column("s_dist_06", "char(24) ") - .column("s_dist_07", "char(24) ") - .column("s_dist_08", "char(24) ") - .column("s_dist_09", "char(24) ") - .column("s_dist_10", "char(24) ") - .primaryKey("(s_w_id HASH, s_i_id ASC)") - .partitionKey("(s_w_id)") - .build(), - new TableSchemaBuilder(TPCCConstants.TABLENAME_OPENORDER) - .column("o_w_id", "int ") - .column("o_d_id", "int ") - .column("o_id", "int ") - .column("o_c_id", "int ") - .column("o_carrier_id", "int DEFAULT NULL") - .column("o_ol_cnt", "decimal(2,0) ") - .column("o_all_local", "decimal(1,0) ") - .column("o_entry_d", "timestamp DEFAULT CURRENT_TIMESTAMP") - .primaryKey("((o_w_id,o_d_id) HASH,o_id)") - .partitionKey("(o_w_id)") - .build(), - new TableSchemaBuilder(TPCCConstants.TABLENAME_HISTORY) - .column("h_c_id", "int ") - .column("h_c_d_id", "int ") - .column("h_c_w_id", "int ") - .column("h_d_id", "int ") - .column("h_w_id", "int ") - .column("h_date", "timestamp DEFAULT CURRENT_TIMESTAMP") - .column("h_amount", "decimal(6,2) ") - .column("h_data", "varchar(24) ") - .partitionKey("(h_w_id)") - .build(), - new TableSchemaBuilder(TPCCConstants.TABLENAME_CUSTOMER) - .column("c_w_id", "int ") - .column("c_d_id", "int ") - .column("c_id", "int ") - .column("c_discount", "decimal(4,4) ") - .column("c_credit", "char(2) ") - .column("c_last", "varchar(16) ") - .column("c_first", "varchar(16) ") - .column("c_credit_lim", "decimal(12,2) ") - .column("c_balance", "decimal(12,2) ") - .column("c_ytd_payment", "float ") - .column("c_payment_cnt", "int ") - .column("c_delivery_cnt", "int ") - .column("c_street_1", "varchar(20) ") - .column("c_street_2", "varchar(20) ") - .column("c_city", "varchar(20) ") - .column("c_state", "char(2) ") - .column("c_zip", "char(9) ") - .column("c_phone", "char(16) ") - .column("c_since", "timestamp DEFAULT CURRENT_TIMESTAMP") - .column("c_middle", "char(2) ") - .column("c_data", "varchar(500) ") - .primaryKey("((c_w_id,c_d_id) HASH,c_id)") - .partitionKey("(c_w_id)") - .build(), - new TableSchemaBuilder(TPCCConstants.TABLENAME_DISTRICT) - .column("d_w_id", "int ") - .column("d_id", "int ") - .column("d_ytd", "decimal(12,2) ") - .column("d_tax", "decimal(4,4) ") - .column("d_next_o_id", "int ") - .column("d_name", "varchar(10) ") - .column("d_street_1", "varchar(20) ") - .column("d_street_2", "varchar(20) ") - .column("d_city", "varchar(20) ") - .column("d_state", "char(2) ") - .column("d_zip", "char(9) ") - .primaryKey("((d_w_id,d_id) HASH)") - .partitionKey("(d_w_id)") - .build(), - new TableSchemaBuilder(TPCCConstants.TABLENAME_ITEM) - .column("i_id", "int ") - .column("i_name", "varchar(24) ") - .column("i_price", "decimal(5,2) ") - .column("i_data", "varchar(50) ") - .column("i_im_id", "int ") - .primaryKey("(i_id)") - .build(), - new TableSchemaBuilder(TPCCConstants.TABLENAME_WAREHOUSE) - .column("w_id", "int ") - .column("w_ytd", "decimal(12,2) ") - .column("w_tax", "decimal(4,4) ") - .column("w_name", "varchar(10) ") - .column("w_street_1", "varchar(20) ") - .column("w_street_2", "varchar(20) ") - .column("w_city", "varchar(20) ") - .column("w_state", "char(2) ") - .column("w_zip", "char(9) ") - .primaryKey("(w_id)") - .partitionKey("(w_id)") - .build() + public static Map tables; + public static boolean schemaUpdated = false; + public static void updateTableSchema(String dbType){ + if(!schemaUpdated) { + tables = Collections.unmodifiableMap(Stream.of( + new TableSchemaBuilder(TPCCConstants.TABLENAME_ORDERLINE) + .column("ol_w_id", "int ") + .column("ol_d_id", "int ") + .column("ol_o_id", "int ") + .column("ol_number", "int ") + .column("ol_i_id", "int ") + .column("ol_delivery_d", "timestamp NULL DEFAULT NULL") + .column("ol_amount", "decimal(6,2) ") + .column("ol_supply_w_id", "int ") + .column("ol_quantity", "decimal(2,0) ") + .column("ol_dist_info", "char(24) ") + .primaryKey(dbType.equals("yugabyte") ? "((ol_w_id,ol_d_id) HASH, ol_o_id,ol_number)" : "(ol_w_id,ol_d_id,ol_o_id,ol_number)") + .partitionKey("(ol_w_id)") + .build(), + new TableSchemaBuilder(TPCCConstants.TABLENAME_NEWORDER) + .column("no_w_id", "int ") + .column("no_d_id", "int ") + .column("no_o_id", "int ") + .primaryKey(dbType.equals("yugabyte") ? "((no_w_id,no_d_id) HASH,no_o_id)" : "(no_w_id,no_d_id,no_o_id)") + .partitionKey("(no_w_id)") + .build(), + new TableSchemaBuilder(TPCCConstants.TABLENAME_STOCK) + .column("s_w_id", "int ") + .column("s_i_id", "int ") + .column("s_quantity", "decimal(4,0) ") + .column("s_ytd", "decimal(8,2) ") + .column("s_order_cnt", "int ") + .column("s_remote_cnt", "int ") + .column("s_data", "varchar(50) ") + .column("s_dist_01", "char(24) ") + .column("s_dist_02", "char(24) ") + .column("s_dist_03", "char(24) ") + .column("s_dist_04", "char(24) ") + .column("s_dist_05", "char(24) ") + .column("s_dist_06", "char(24) ") + .column("s_dist_07", "char(24) ") + .column("s_dist_08", "char(24) ") + .column("s_dist_09", "char(24) ") + .column("s_dist_10", "char(24) ") + .primaryKey(dbType.equals("yugabyte") ? "(s_w_id HASH, s_i_id ASC)" : "(s_w_id,s_i_id)") + .partitionKey("(s_w_id)") + .build(), + new TableSchemaBuilder(TPCCConstants.TABLENAME_OPENORDER) + .column("o_w_id", "int ") + .column("o_d_id", "int ") + .column("o_id", "int ") + .column("o_c_id", "int ") + .column("o_carrier_id", "int DEFAULT NULL") + .column("o_ol_cnt", "decimal(2,0) ") + .column("o_all_local", "decimal(1,0) ") + .column("o_entry_d", "timestamp DEFAULT CURRENT_TIMESTAMP") + .primaryKey(dbType.equals("yugabyte") ? "((o_w_id,o_d_id) HASH,o_id)" : "(o_w_id,o_d_id,o_id)") + .partitionKey("(o_w_id)") + .build(), + new TableSchemaBuilder(TPCCConstants.TABLENAME_HISTORY) + .column("h_c_id", "int ") + .column("h_c_d_id", "int ") + .column("h_c_w_id", "int ") + .column("h_d_id", "int ") + .column("h_w_id", "int ") + .column("h_date", "timestamp DEFAULT CURRENT_TIMESTAMP") + .column("h_amount", "decimal(6,2) ") + .column("h_data", "varchar(24) ") + .partitionKey("(h_w_id)") + .build(), + new TableSchemaBuilder(TPCCConstants.TABLENAME_CUSTOMER) + .column("c_w_id", "int ") + .column("c_d_id", "int ") + .column("c_id", "int ") + .column("c_discount", "decimal(4,4) ") + .column("c_credit", "char(2) ") + .column("c_last", "varchar(16) ") + .column("c_first", "varchar(16) ") + .column("c_credit_lim", "decimal(12,2) ") + .column("c_balance", "decimal(12,2) ") + .column("c_ytd_payment", "float ") + .column("c_payment_cnt", "int ") + .column("c_delivery_cnt", "int ") + .column("c_street_1", "varchar(20) ") + .column("c_street_2", "varchar(20) ") + .column("c_city", "varchar(20) ") + .column("c_state", "char(2) ") + .column("c_zip", "char(9) ") + .column("c_phone", "char(16) ") + .column("c_since", "timestamp DEFAULT CURRENT_TIMESTAMP") + .column("c_middle", "char(2) ") + .column("c_data", "varchar(500) ") + .primaryKey(dbType.equals("yugabyte") ? "((c_w_id,c_d_id) HASH,c_id)" : "(c_w_id,c_d_id,c_id)") + .partitionKey("(c_w_id)") + .build(), + new TableSchemaBuilder(TPCCConstants.TABLENAME_DISTRICT) + .column("d_w_id", "int ") + .column("d_id", "int ") + .column("d_ytd", "decimal(12,2) ") + .column("d_tax", "decimal(4,4) ") + .column("d_next_o_id", "int ") + .column("d_name", "varchar(10) ") + .column("d_street_1", "varchar(20) ") + .column("d_street_2", "varchar(20) ") + .column("d_city", "varchar(20) ") + .column("d_state", "char(2) ") + .column("d_zip", "char(9) ") + .primaryKey(dbType.equals("yugabyte") ? "((d_w_id,d_id) HASH)" : "(d_w_id,d_id)") + .partitionKey("(d_w_id)") + .build(), + new TableSchemaBuilder(TPCCConstants.TABLENAME_ITEM) + .column("i_id", "int ") + .column("i_name", "varchar(24) ") + .column("i_price", "decimal(5,2) ") + .column("i_data", "varchar(50) ") + .column("i_im_id", "int ") + .primaryKey("(i_id)") + .build(), + new TableSchemaBuilder(TPCCConstants.TABLENAME_WAREHOUSE) + .column("w_id", "int ") + .column("w_ytd", "decimal(12,2) ") + .column("w_tax", "decimal(4,4) ") + .column("w_name", "varchar(10) ") + .column("w_street_1", "varchar(20) ") + .column("w_street_2", "varchar(20) ") + .column("w_city", "varchar(20) ") + .column("w_state", "char(2) ") + .column("w_zip", "char(9) ") + .primaryKey("(w_id)") + .partitionKey("(w_id)") + .build() ).collect(Collectors.toMap(TableSchema::name, e -> e))); - + schemaUpdated = true; + } + } public static TableSchema getTableSchema(String tablename) { + updateTableSchema(DBWorkload.dbtype); return tables.get(tablename); } } diff --git a/src/com/oltpbenchmark/schema/defaultschema/DefaultSchemaManager.java b/src/com/oltpbenchmark/schema/defaultschema/DefaultSchemaManager.java index 376ff4e..278d40e 100644 --- a/src/com/oltpbenchmark/schema/defaultschema/DefaultSchemaManager.java +++ b/src/com/oltpbenchmark/schema/defaultschema/DefaultSchemaManager.java @@ -14,31 +14,37 @@ public class DefaultSchemaManager extends SchemaManager { private final Map tables = new HashMap(); - public DefaultSchemaManager(Connection db_connection) { + public DefaultSchemaManager(Connection db_connection, String dbType) { super(db_connection); + TPCCTableSchemas.updateTableSchema(dbType); for (TableSchema t : TPCCTableSchemas.tables.values()) { tables.put(t.name(), new DefaultTable(t)); } } @Override - public void create() throws SQLException { + public void create(String dbType) throws SQLException { for (Table t : tables.values()) { execute(t.getDropDdl()); execute(t.getCreateDdl()); } // TODO -- can we defer this until after load as well? - execute("CREATE INDEX idx_customer_name ON customer ((c_w_id,c_d_id) HASH,c_last,c_first)"); - execute("CREATE UNIQUE INDEX idx_order ON oorder ((o_w_id,o_d_id) HASH,o_c_id,o_id DESC)"); + createIndexes(dbType); if (!db_connection.getAutoCommit()) { db_connection.commit(); } } - public void createIndexes() throws SQLException { - execute("CREATE INDEX idx_customer_name ON customer ((c_w_id,c_d_id) HASH,c_last,c_first)"); - execute("CREATE UNIQUE INDEX idx_order ON oorder ((o_w_id,o_d_id) HASH,o_c_id,o_id DESC)"); + public void createIndexes(String dbType) throws SQLException { + String idx_customer = "CREATE INDEX idx_customer_name ON customer (" + + (dbType.equals("yugabyte")? "(c_w_id,c_d_id) HASH,c_last,c_first" :"c_w_id,c_d_id,c_last,c_first") + + ")"; + String idx_oorder = "CREATE UNIQUE INDEX idx_order ON oorder (" + + (dbType.equals("yugabyte") ? "(o_w_id,o_d_id) HASH,o_c_id,o_id DESC" :"o_w_id,o_d_id,o_c_id,o_id DESC") + + ")"; + execute(idx_customer); + execute(idx_oorder); } public void dropForeignKeyConstraints() throws SQLException { diff --git a/src/com/oltpbenchmark/schema/geopartitioned/GeoPartitionedSchemaManager.java b/src/com/oltpbenchmark/schema/geopartitioned/GeoPartitionedSchemaManager.java index 7f413c9..37b8eaa 100644 --- a/src/com/oltpbenchmark/schema/geopartitioned/GeoPartitionedSchemaManager.java +++ b/src/com/oltpbenchmark/schema/geopartitioned/GeoPartitionedSchemaManager.java @@ -23,6 +23,7 @@ public class GeoPartitionedSchemaManager extends SchemaManager { public GeoPartitionedSchemaManager(GeoPartitionPolicy geoPartitioningPolicy, Connection conn) { super(conn); this.geoPartitionPolicy = geoPartitioningPolicy; + TPCCTableSchemas.updateTableSchema("yugabyte"); for (TableSchema t : TPCCTableSchemas.tables.values()) { tables.put(t.name(), t.name().equals(TPCCConstants.TABLENAME_ITEM) ? new DefaultTable(t, geoPartitioningPolicy.getTablespaceForItemTable()) @@ -35,7 +36,7 @@ private int numPartitions() { } @Override - public void create() throws SQLException { + public void create(String dbType) throws SQLException { for (Table t : tables.values()) { execute(t.getDropDdl()); } @@ -46,7 +47,7 @@ public void create() throws SQLException { execute(t.getCreateDdl()); } // TODO -- can we defer this until after load as well? - createIndexes(); + createIndexes(dbType); if (!db_connection.getAutoCommit()) { db_connection.commit(); @@ -54,7 +55,7 @@ public void create() throws SQLException { } @Override - public void createIndexes() throws SQLException { + public void createIndexes(String dbType) throws SQLException { for (int i = 1; i <= numPartitions(); ++i) { execute(String.format("CREATE INDEX idx_customer_name%d ON customer%d ((c_w_id,c_d_id) HASH,c_last,c_first) TABLESPACE %s", i, i, geoPartitionPolicy.getTablespaceForPartition(i - 1)));