Skip to content

Commit f49497c

Browse files
authored
feat: switched from lock-scanned ranges to FOR UPDATE (GoogleCloudPlatform#3215)
1 parent 4077191 commit f49497c

6 files changed

Lines changed: 10 additions & 39 deletions

File tree

benchmarks/tpcc/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ mvn spring-boot:run -Dspring-boot.run.arguments="
3333
--tpcc.truncate-before-load=false
3434
--tpcc.run-benchmark=false
3535
--tpcc.use-read-only-transactions=false
36-
--tpcc.lock-scanned-ranges=false
3736
--spanner.project=my-project
3837
--spanner.instance=my-instance
3938
--spanner.database=my-database
@@ -53,7 +52,6 @@ mvn spring-boot:run -Dspring-boot.run.arguments="
5352
--tpcc.run-benchmark=false
5453
--tpcc.benchmark-runner=client_lib_gsql
5554
--tpcc.use-read-only-transactions=false
56-
--tpcc.lock-scanned-ranges=false
5755
--spanner.project=my-project
5856
--spanner.instance=my-instance
5957
--spanner.database=my-database
@@ -77,7 +75,6 @@ mvn spring-boot:run -Dspring-boot.run.arguments="
7775
--tpcc.run-benchmark=true
7876
--tpcc.benchmark-runner=pgadapter
7977
--tpcc.use-read-only-transactions=true
80-
--tpcc.lock-scanned-ranges=false
8178
--spanner.project=my-project
8279
--spanner.instance=my-instance
8380
--spanner.database=my-database
@@ -97,7 +94,6 @@ mvn spring-boot:run -Dspring-boot.run.arguments="
9794
--tpcc.run-benchmark=true
9895
--tpcc.benchmark-runner=spanner_jdbc
9996
--tpcc.use-read-only-transactions=true
100-
--tpcc.lock-scanned-ranges=false
10197
--spanner.project=my-project
10298
--spanner.instance=my-instance
10399
--spanner.database=my-database
@@ -117,7 +113,6 @@ mvn spring-boot:run -Dspring-boot.run.arguments="
117113
--tpcc.run-benchmark=true
118114
--tpcc.benchmark-runner=client_lib_pg
119115
--tpcc.use-read-only-transactions=true
120-
--tpcc.lock-scanned-ranges=false
121116
--spanner.project=my-project
122117
--spanner.instance=my-instance
123118
--spanner.database=my-database
@@ -137,7 +132,6 @@ mvn spring-boot:run -Dspring-boot.run.arguments="
137132
--tpcc.run-benchmark=true
138133
--tpcc.benchmark-runner=client_lib_gsql
139134
--tpcc.use-read-only-transactions=true
140-
--tpcc.lock-scanned-ranges=false
141135
--spanner.project=my-project
142136
--spanner.instance=my-instance
143137
--spanner.database=my-database

benchmarks/tpcc/src/main/java/com/google/cloud/pgadapter/tpcc/AbstractBenchmarkRunner.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,9 @@ private void newOrder() throws SQLException {
180180
executeStatement("begin transaction");
181181
row =
182182
paramQueryRow(
183-
(tpccConfiguration.isLockScannedRanges() ? "/*@ lock_scanned_ranges=exclusive */" : "")
184-
+ "SELECT c_discount, c_last, c_credit, w_tax "
183+
"SELECT c_discount, c_last, c_credit, w_tax "
185184
+ "FROM customer c, warehouse w "
186-
+ "WHERE w.w_id = ? AND c.w_id = w.w_id AND c.d_id = ? AND c.c_id = ?",
185+
+ "WHERE w.w_id = ? AND c.w_id = w.w_id AND c.d_id = ? AND c.c_id = ? FOR UPDATE",
187186
new Object[] {warehouseId, districtId, customerId});
188187
BigDecimal discount = (BigDecimal) row[0];
189188
String last = (String) row[1];
@@ -192,10 +191,9 @@ private void newOrder() throws SQLException {
192191

193192
row =
194193
paramQueryRow(
195-
(tpccConfiguration.isLockScannedRanges() ? "/*@ lock_scanned_ranges=exclusive */" : "")
196-
+ "SELECT d_next_o_id, d_tax "
194+
"SELECT d_next_o_id, d_tax "
197195
+ "FROM district "
198-
+ "WHERE w_id = ? AND d_id = ?",
196+
+ "WHERE w_id = ? AND d_id = ? FOR UPDATE",
199197
new Object[] {warehouseId, districtId});
200198
long districtNextOrderId = (long) row[0];
201199
BigDecimal districtTax = (BigDecimal) row[1];
@@ -235,12 +233,9 @@ private void newOrder() throws SQLException {
235233

236234
row =
237235
paramQueryRow(
238-
(tpccConfiguration.isLockScannedRanges()
239-
? "/*@ lock_scanned_ranges=exclusive */"
240-
: "")
241-
+ "SELECT s_quantity, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10 "
236+
"SELECT s_quantity, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10 "
242237
+ "FROM stock "
243-
+ "WHERE s_i_id = ? AND w_id= ?",
238+
+ "WHERE s_i_id = ? AND w_id= ? FOR UPDATE",
244239
new Object[] {orderLineItemId, orderLineSupplyWarehouseId});
245240
long stockQuantity = (long) row[0];
246241
String stockData = (String) row[1];
@@ -375,10 +370,9 @@ private void payment() throws SQLException {
375370
}
376371
row =
377372
paramQueryRow(
378-
(tpccConfiguration.isLockScannedRanges() ? "/*@ lock_scanned_ranges=exclusive */" : "")
379-
+ "SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since "
373+
"SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since "
380374
+ "FROM customer "
381-
+ "WHERE w_id = ? AND d_id= ? AND c_id=?",
375+
+ "WHERE w_id = ? AND d_id= ? AND c_id=? FOR UPDATE",
382376
new Object[] {customerWarehouseId, customerDistrictId, customerId});
383377
String firstName = (String) row[0];
384378
String middleName = (String) row[1];
@@ -556,14 +550,11 @@ private void delivery() throws SQLException {
556550
long districtId = Long.reverse(district);
557551
row =
558552
paramQueryRow(
559-
(tpccConfiguration.isLockScannedRanges()
560-
? "/*@ lock_scanned_ranges=exclusive */"
561-
: "")
562-
+ "SELECT o_id, c_id "
553+
"SELECT o_id, c_id "
563554
+ "FROM new_orders "
564555
+ "WHERE d_id = ? AND w_id = ? "
565556
+ "ORDER BY o_id ASC "
566-
+ "LIMIT 1",
557+
+ "LIMIT 1 FOR UPDATE",
567558
new Object[] {districtId, warehouseId});
568559
if (row != null) {
569560
long newOrderId = (long) row[0];

benchmarks/tpcc/src/main/java/com/google/cloud/pgadapter/tpcc/Statistics.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void print(Duration runtime) {
4949
\rNum threads: %d\t
5050
\rDuration: %s\t
5151
\rRead-only tx: %s\t
52-
\rExclusive lock: %s\t
5352
\r
5453
\rNew orders: %d (%.2f/s)\t
5554
\rPayments: %d (%.2f/s)\t
@@ -67,7 +66,6 @@ void print(Duration runtime) {
6766
tpccConfiguration.getBenchmarkThreads(),
6867
runtime,
6968
tpccConfiguration.isUseReadOnlyTransactions(),
70-
tpccConfiguration.isLockScannedRanges(),
7169
getNewOrder(),
7270
getNewOrderPerSecond(runtime),
7371
getPayment(),

benchmarks/tpcc/src/main/java/com/google/cloud/pgadapter/tpcc/config/TpccConfiguration.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public class TpccConfiguration {
5454
/** --- Optimizations --- */
5555
private boolean useReadOnlyTransactions;
5656

57-
private boolean lockScannedRanges;
58-
5957
public boolean isLoadData() {
6058
return loadData;
6159
}
@@ -151,12 +149,4 @@ public boolean isUseReadOnlyTransactions() {
151149
public void setUseReadOnlyTransactions(boolean useReadOnlyTransactions) {
152150
this.useReadOnlyTransactions = useReadOnlyTransactions;
153151
}
154-
155-
public boolean isLockScannedRanges() {
156-
return lockScannedRanges;
157-
}
158-
159-
public void setLockScannedRanges(boolean lockScannedRanges) {
160-
this.lockScannedRanges = lockScannedRanges;
161-
}
162152
}

benchmarks/tpcc/src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ tpcc.item-count=100000
4040

4141
# --- Possible optimizations for TPC-C --- #
4242
tpcc.use-read-only-transactions=false
43-
tpcc.lock-scanned-ranges=false
4443

4544
# Change these to match your Cloud Spanner PostgreSQL-dialect database.
4645
spanner.project=my-project

benchmarks/tpcc/src/test/java/com/google/cloud/pgadapter/tpcc/BenchmarkApplicationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public void testRunApplication() throws Exception {
7777
System.setProperty("tpcc.run-benchmark", "false");
7878
System.setProperty("tpcc.benchmark-runner", "pgadapter");
7979
System.setProperty("tpcc.use-read-only-transactions", "true");
80-
System.setProperty("tpcc.lock-scanned-ranges", "false");
8180
System.setProperty("spanner.project", "test-project");
8281
System.setProperty("spanner.instance", "test-instance");
8382
System.setProperty("spanner.database", "tpcc");

0 commit comments

Comments
 (0)