Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Tablegroups in Geo-distributed TPCC #123

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions config/geopartitioned_workload.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0"?>
<parameters>
<enableGeoPartitionedWorkload>false</enableGeoPartitionedWorkload>
<numberOfPartitions>2</numberOfPartitions>
<enableGeoPartitionedWorkload>true</enableGeoPartitionedWorkload>
<useTablegroups>true</useTablegroups>
<numberOfPartitions>1</numberOfPartitions>
<tablespaces>
<tablespace>
<name>tablespace0</name>
Expand All @@ -13,7 +14,7 @@
<placementBlock>
<cloud>aws</cloud>
<region>us-west-2</region>
<zone>us-west-2a0</zone>
<zone>us-west-2a</zone>
<minReplicationFactor>1</minReplicationFactor>
</placementBlock>
</placementPolicy>
Expand All @@ -26,7 +27,7 @@
<placementBlock>
<cloud>aws</cloud>
<region>us-west-2</region>
<zone>us-west-2a1</zone>
<zone>us-west-2b</zone>
<minReplicationFactor>1</minReplicationFactor>
</placementBlock>
</placementPolicy>
Expand All @@ -39,10 +40,26 @@
<placementBlock>
<cloud>aws</cloud>
<region>us-west-2</region>
<zone>us-west-2a2</zone>
<zone>us-west-2c</zone>
<minReplicationFactor>1</minReplicationFactor>
</placementBlock>
</placementPolicy>
</tablespace>
</tablespaces>
<tablegroups>
<tablegroup>
<name>tablegroup0</name>
<tablespace>tablespace0</tablespace>
</tablegroup>
<tablegroup>
<name>tablegroup1</name>
<tablespace>tablespace1</tablespace>
<storePartitions>true</storePartitions>
</tablegroup>
<tablegroup>
<name>tablegroup2</name>
<tablespace>tablespace2</tablespace>
<storePartitions>true</storePartitions>
</tablegroup>
</tablegroups>
</parameters>
17 changes: 16 additions & 1 deletion src/com/oltpbenchmark/GeoPartitionedConfigFileOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public GeoPartitionPolicy getGeoPartitionPlacement(final int totalWarehousesAcro
}

// Verify that the current TPCC client can access only a single partition.
GeoPartitionPolicy policy = new GeoPartitionPolicy(numPartitions, totalWarehousesAcrossShards);
GeoPartitionPolicy policy = new GeoPartitionPolicy(numPartitions, totalWarehousesAcrossShards, isFlagSet("useTablegroups"));
int partitionForStartWarehouse = policy.getPartitionForWarehouse(startWarehouseIdForShard);
int partitionForEndWarehouse = policy.getPartitionForWarehouse(startWarehouseIdForShard + numWarehouses - 1);

Expand All @@ -53,6 +53,21 @@ public GeoPartitionPolicy getGeoPartitionPlacement(final int totalWarehousesAcro
numPartitions, numWarehouses, startWarehouseIdForShard, totalWarehousesAcrossShards));
}

// Iterate through all the tablegroups in the config.
// The lists in XMLConfiguration are 1-based, so start the
// loop from 1.
for (int ii = 1; ii <= getNumTablespaces(); ++ii) {
final String tablegroupPath = String.format("tablegroups/tablegroup[%d]/", ii);
final String tablegroupName = getRequiredStringOpt(tablegroupPath + "name");
final String tablespaceName = getRequiredStringOpt(tablegroupPath + "tablespace");

if (isFlagSet(tablegroupPath + "storePartitions")) {
policy.addTablegroupForPartition(tablegroupName);
}

policy.addTablegroup(tablegroupName, tablespaceName);
}

// Iterate through all the tablespaces in the config.
// The lists in XMLConfiguration are 1-based, so start the
// loop from 1.
Expand Down
3 changes: 0 additions & 3 deletions src/com/oltpbenchmark/api/BenchmarkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ public final void createDatabase() {

/**
* Invoke this benchmark's database loader.
* We return the handle to Loader object that we created to do this.
* You probably don't need it and can simply ignore. There are some
* test cases that use it. That's why it's here.
*/
public final void loadDatabase() {
Loader loader = this.makeLoaderImpl();
Expand Down
14 changes: 7 additions & 7 deletions src/com/oltpbenchmark/schema/TPCCTableSchemas.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class TPCCTableSchemas {
.column("ol_supply_w_id", "int NOT NULL")
.column("ol_quantity", "decimal(2,0) NOT NULL")
.column("ol_dist_info", "char(24) NOT NULL")
.primaryKey("((ol_w_id,ol_d_id) HASH,ol_o_id,ol_number)")
.primaryKey("(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 NOT NULL")
.column("no_d_id", "int NOT NULL")
.column("no_o_id", "int NOT NULL")
.primaryKey("((no_w_id,no_d_id) HASH,no_o_id)")
.primaryKey("(no_w_id,no_d_id,no_o_id)")
.partitionKey("(no_w_id)")
.build(),
new TableSchemaBuilder(TPCCConstants.TABLENAME_STOCK)
Expand All @@ -48,7 +48,7 @@ public class TPCCTableSchemas {
.column("s_dist_08", "char(24) NOT NULL")
.column("s_dist_09", "char(24) NOT NULL")
.column("s_dist_10", "char(24) NOT NULL")
.primaryKey("(s_w_id HASH, s_i_id ASC)")
.primaryKey("(s_w_id, s_i_id ASC)")
.partitionKey("(s_w_id)")
.build(),
new TableSchemaBuilder(TPCCConstants.TABLENAME_OPENORDER)
Expand All @@ -60,7 +60,7 @@ public class TPCCTableSchemas {
.column("o_ol_cnt", "decimal(2,0) NOT NULL")
.column("o_all_local", "decimal(1,0) NOT NULL")
.column("o_entry_d", "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP")
.primaryKey("((o_w_id,o_d_id) HASH,o_id)")
.primaryKey("(o_w_id,o_d_id,o_id)")
.partitionKey("(o_w_id)")
.build(),
new TableSchemaBuilder(TPCCConstants.TABLENAME_HISTORY)
Expand Down Expand Up @@ -96,7 +96,7 @@ public class TPCCTableSchemas {
.column("c_since", "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP")
.column("c_middle", "char(2) NOT NULL")
.column("c_data", "varchar(500) NOT NULL")
.primaryKey("((c_w_id,c_d_id) HASH,c_id)")
.primaryKey("(c_w_id,c_d_id,c_id)")
.partitionKey("(c_w_id)")
.build(),
new TableSchemaBuilder(TPCCConstants.TABLENAME_DISTRICT)
Expand All @@ -111,7 +111,7 @@ public class TPCCTableSchemas {
.column("d_city", "varchar(20) NOT NULL")
.column("d_state", "char(2) NOT NULL")
.column("d_zip", "char(9) NOT NULL")
.primaryKey("((d_w_id,d_id) HASH)")
.primaryKey("(d_w_id,d_id)")
.partitionKey("(d_w_id)")
.build(),
new TableSchemaBuilder(TPCCConstants.TABLENAME_ITEM)
Expand All @@ -136,7 +136,7 @@ public class TPCCTableSchemas {
.partitionKey("(w_id)")
.build()
).collect(Collectors.toMap(TableSchema::name, e -> e)));

public static TableSchema getTableSchema(String tablename) {
return tables.get(tablename);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public GeoPartitionedSchemaManager(GeoPartitionPolicy geoPartitioningPolicy, Con
super(conn);
this.geoPartitionPolicy = geoPartitioningPolicy;
for (TableSchema t : TPCCTableSchemas.tables.values()) {
tables.put(t.name(),
t.name().equals(TPCCConstants.TABLENAME_ITEM) ? new DefaultTable(t, geoPartitioningPolicy.getTablespaceForItemTable())
tables.put(t.name(),
t.name().equals(TPCCConstants.TABLENAME_ITEM) ? new DefaultTable(t, geoPartitioningPolicy.getTablespaceForItemTable())
: new PartitionedTable(t, geoPartitionPolicy));
}
}
Expand All @@ -41,6 +41,7 @@ public void create() throws SQLException {
}

createTablespaces();
createTablegroups();

for (Table t : tables.values()) {
execute(t.getCreateDdl());
Expand Down Expand Up @@ -73,6 +74,16 @@ private void createTablespaces() throws SQLException {
}
}

private void createTablegroups() throws SQLException {
if (!geoPartitionPolicy.shouldUseTablegroups()) {
return;
}
for (Map.Entry<String, String> entry : geoPartitionPolicy.getTablegroups().entrySet()) {
execute(String.format("DROP TABLEGROUP IF EXISTS %s", entry.getKey()));
execute(String.format("CREATE TABLEGROUP %s TABLESPACE %s", entry.getKey(), entry.getValue()));
}
}

@Override
public void enableForeignKeyConstraints() throws SQLException {
// Create foreign key relations among the partitions themselves, rather than between
Expand Down Expand Up @@ -116,7 +127,7 @@ public void enableForeignKeyConstraints() throws SQLException {
"(OL_SUPPLY_W_ID, OL_I_ID) REFERENCES STOCK%d (S_W_ID, S_I_ID) NOT VALID", idx, idx, idx));
}
}

@Override
public void createSqlProcedures() throws Exception {
try (Statement st = db_connection.createStatement()) {
Expand Down
16 changes: 12 additions & 4 deletions src/com/oltpbenchmark/schema/geopartitioned/PartitionedTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ private String tablespaceForPartition(int idx) {
return policy.getTablespaceForPartition(idx);
}

private String tablegroupForPartition(int idx) {
return policy.getTablegroupForPartition(idx);
}

@Override
public String getCreateDdl() {
StringBuilder sb = new StringBuilder();
Expand All @@ -38,9 +42,9 @@ public String getCreateDdl() {
private String createPartitionedTable() {
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE ").append(schema.name()).append(" ( ");

addColDescForCreateDDL(sb);

// Append the partition key.
sb.append(")\n PARTITION BY RANGE ").append(schema.getPartitionKey());
// Append the tablespace name.
Expand All @@ -63,15 +67,19 @@ private String createPartitionTable(int idx) {
// While creating partitions, skip the column declaration.
sb.append("\n").append(c.getName()).append(',');
}

// Remove trailing comma added after the last column in above loop.
sb.setLength(sb.length() - 1);

if (schema.getPrimaryKey() != null) {
sb.append(String.format(",\n PRIMARY KEY %s", schema.getPrimaryKey()));
}
sb.append(String.format(")\n FOR VALUES FROM (%d) TO (%d)", start, end));
sb.append(String.format(" TABLESPACE %s;", tablespaceForPartition(idx - 1)));
if (policy.shouldUseTablegroups()) {
sb.append(String.format(" TABLEGROUP %s;", tablegroupForPartition(idx - 1)));
} else {
sb.append(String.format(" TABLESPACE %s;", tablespaceForPartition(idx - 1)));
}

return sb.toString();
}
Expand Down
34 changes: 31 additions & 3 deletions src/com/oltpbenchmark/util/GeoPartitionPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,45 @@
* be replicated and placed.
*/
public class GeoPartitionPolicy {
private final Map<String, PlacementPolicy> tablespaceToPlacementPolicy = new HashMap<String, PlacementPolicy>();;
private final Map<String, PlacementPolicy> tablespaceToPlacementPolicy = new HashMap<>();
private final Map<String, String> tablegroupToTablespace = new HashMap<>();

private String tablespaceForPartitionedTables;

private String tablespaceForItemTable;

private final List<String> tablespacesForPartitions = new ArrayList<String>();
private final List<String> tablespacesForPartitions = new ArrayList<>();
private final List<String> tablegroupsForPartitions = new ArrayList<>();

private final int numWarehouses;

private final int numPartitions;

public GeoPartitionPolicy(int numPartitions, int numWarehouses) {
private final boolean useTablegroups;

public GeoPartitionPolicy(int numPartitions, int numWarehouses, boolean useTablegroups) {
this.numPartitions = numPartitions;
this.numWarehouses = numWarehouses;
this.useTablegroups = useTablegroups;
}

public int getNumPartitions() {
return numPartitions;
}

public boolean shouldUseTablegroups() {
return useTablegroups;
}

// Getters and setters.
public Map<String, PlacementPolicy> getTablespaceToPlacementPolicy() {
return tablespaceToPlacementPolicy;
}

public Map<String, String> getTablegroups() {
return tablegroupToTablespace;
}

public String getTablespaceForPartitionedTables() {
return tablespaceForPartitionedTables;
}
Expand All @@ -63,6 +76,9 @@ public void setTablespaceForItemTable(String tablespaceForItemTable) {
public List<String> getTablespacesForPartitions() {
return tablespacesForPartitions;
}
public List<String> getTablegroupsForPartitions() {
return tablegroupsForPartitions;
}

public int getNumWarehouses() {
return numWarehouses;
Expand All @@ -72,10 +88,18 @@ public void addTablespacePlacementPolicy(String tablespace, PlacementPolicy poli
tablespaceToPlacementPolicy.put(tablespace, policy);
}

public void addTablegroup(String tablegroup, String tablespace) {
tablegroupToTablespace.put(tablegroup, tablespace);
}

public void addTablespaceForPartition(String tablespace) {
tablespacesForPartitions.add(tablespace);
}

public void addTablegroupForPartition(String tablegroup) {
tablegroupsForPartitions.add(tablegroup);
}

public String getTablespaceCreationJson(String tablespace) {
PlacementPolicy placementPolicy = tablespaceToPlacementPolicy.get(tablespace);
// Handle errors.
Expand All @@ -87,6 +111,10 @@ public String getTablespaceForPartition(int idx) {
return tablespacesForPartitions.get(idx);
}

public String getTablegroupForPartition(int idx) {
return tablegroupsForPartitions.get(idx);
}

public int getStartWarehouseForPartition(int idx) {
return (idx - 1) * numWareHousesPerSplit() + 1;
}
Expand Down