Skip to content

Commit ab7e018

Browse files
committed
Add isConsistentVirtualTableRead() to StorageInfo
1 parent 7f9d80e commit ab7e018

24 files changed

+221
-33
lines changed

core/src/main/java/com/scalar/db/api/DistributedStorageAdmin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public interface DistributedStorageAdmin extends Admin, AutoCloseable {
4747
/**
4848
* Returns the storage information.
4949
*
50+
* <p>Note: This feature is primarily for internal use. Breaking changes can and will be
51+
* introduced to it. Users should not depend on it.
52+
*
5053
* @param namespace the namespace to get the storage information for
5154
* @return the storage information
5255
* @throws ExecutionException if the operation fails

core/src/main/java/com/scalar/db/api/StorageInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public interface StorageInfo {
2222
*/
2323
int getMaxAtomicMutationsCount();
2424

25+
/**
26+
* Returns whether the storage guarantees consistent reads for virtual tables.
27+
*
28+
* @return true if the storage guarantees consistent reads for virtual tables, false otherwise
29+
*/
30+
boolean isConsistentVirtualTableRead();
31+
2532
/**
2633
* The mutation atomicity unit of the storage.
2734
*

core/src/main/java/com/scalar/db/common/StorageInfoImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ public class StorageInfoImpl implements StorageInfo {
1111
private final String storageName;
1212
private final MutationAtomicityUnit mutationAtomicityUnit;
1313
private final int maxAtomicMutationsCount;
14+
private final boolean consistentVirtualTableRead;
1415

1516
public StorageInfoImpl(
1617
String storageName,
1718
MutationAtomicityUnit mutationAtomicityUnit,
18-
int maxAtomicMutationsCount) {
19+
int maxAtomicMutationsCount,
20+
boolean consistentVirtualTableRead) {
1921
this.storageName = storageName;
2022
this.mutationAtomicityUnit = mutationAtomicityUnit;
2123
this.maxAtomicMutationsCount = maxAtomicMutationsCount;
24+
this.consistentVirtualTableRead = consistentVirtualTableRead;
2225
}
2326

2427
@Override
@@ -36,6 +39,11 @@ public int getMaxAtomicMutationsCount() {
3639
return maxAtomicMutationsCount;
3740
}
3841

42+
@Override
43+
public boolean isConsistentVirtualTableRead() {
44+
return consistentVirtualTableRead;
45+
}
46+
3947
@Override
4048
public boolean equals(Object o) {
4149
if (this == o) {

core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public class CassandraAdmin implements DistributedStorageAdmin {
5757
"cassandra",
5858
StorageInfo.MutationAtomicityUnit.PARTITION,
5959
// No limit on the number of mutations
60-
Integer.MAX_VALUE);
60+
Integer.MAX_VALUE,
61+
false);
6162

6263
private final ClusterManager clusterManager;
6364
private final String metadataKeyspace;

core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public class CosmosAdmin implements DistributedStorageAdmin {
7474
"cosmos",
7575
StorageInfo.MutationAtomicityUnit.PARTITION,
7676
// No limit on the number of mutations
77-
Integer.MAX_VALUE);
77+
Integer.MAX_VALUE,
78+
false);
7879

7980
private final CosmosClient client;
8081
private final String metadataDatabase;

core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ public class DynamoAdmin implements DistributedStorageAdmin {
165165
"dynamo",
166166
StorageInfo.MutationAtomicityUnit.STORAGE,
167167
// DynamoDB has a limit of 100 items per transactional batch write operation
168-
100);
168+
100,
169+
false);
169170

170171
private final DynamoDbClient client;
171172
private final ApplicationAutoScalingClient applicationAutoScalingClient;

core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ public class JdbcAdmin implements DistributedStorageAdmin {
5353
@VisibleForTesting static final String JDBC_COL_DECIMAL_DIGITS = "DECIMAL_DIGITS";
5454

5555
private static final String INDEX_NAME_PREFIX = "index";
56-
private static final StorageInfo STORAGE_INFO =
57-
new StorageInfoImpl(
58-
"jdbc",
59-
StorageInfo.MutationAtomicityUnit.STORAGE,
60-
// No limit on the number of mutations
61-
Integer.MAX_VALUE);
6256

6357
private final RdbEngineStrategy rdbEngine;
6458
private final BasicDataSource dataSource;
@@ -1011,8 +1005,22 @@ public void upgrade(Map<String, String> options) throws ExecutionException {
10111005
}
10121006

10131007
@Override
1014-
public StorageInfo getStorageInfo(String namespace) {
1015-
return STORAGE_INFO;
1008+
public StorageInfo getStorageInfo(String namespace) throws ExecutionException {
1009+
boolean consistentVirtualTableRead;
1010+
try (Connection connection = dataSource.getConnection()) {
1011+
int isolationLevel = connection.getTransactionIsolation();
1012+
consistentVirtualTableRead =
1013+
isolationLevel >= rdbEngine.getMinimumIsolationLevelForConsistencyReads();
1014+
} catch (SQLException e) {
1015+
throw new ExecutionException("Getting the transaction isolation level failed", e);
1016+
}
1017+
1018+
return new StorageInfoImpl(
1019+
"jdbc",
1020+
StorageInfo.MutationAtomicityUnit.STORAGE,
1021+
// No limit on the number of mutations
1022+
Integer.MAX_VALUE,
1023+
consistentVirtualTableRead);
10161024
}
10171025

10181026
@Override

core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineDb2.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.scalar.db.storage.jdbc.query.SelectQuery;
2121
import com.scalar.db.storage.jdbc.query.SelectWithLimitQuery;
2222
import com.scalar.db.storage.jdbc.query.UpsertQuery;
23+
import java.sql.Connection;
2324
import java.sql.Driver;
2425
import java.sql.JDBCType;
2526
import java.sql.ResultSet;
@@ -588,4 +589,10 @@ public void throwIfCrossPartitionScanOrderingOnBlobColumnNotSupported(
588589
public String getTableNamesInNamespaceSql() {
589590
return "SELECT TABNAME FROM SYSCAT.TABLES WHERE TABSCHEMA = ? AND TYPE = 'T'";
590591
}
592+
593+
@Override
594+
public int getMinimumIsolationLevelForConsistencyReads() {
595+
// In Db2, REPEATABLE READ and SERIALIZABLE isolation levels guarantee consistent reads
596+
return Connection.TRANSACTION_REPEATABLE_READ;
597+
}
591598
}

core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,10 @@ public void setConnectionToReadOnly(Connection connection, boolean readOnly) thr
509509
public String getTableNamesInNamespaceSql() {
510510
return "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?";
511511
}
512+
513+
@Override
514+
public int getMinimumIsolationLevelForConsistencyReads() {
515+
// In MySQL, REPEATABLE READ and SERIALIZABLE isolation levels guarantee consistent reads
516+
return Connection.TRANSACTION_REPEATABLE_READ;
517+
}
512518
}

core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.scalar.db.storage.jdbc.query.UpsertQuery;
1919
import java.io.ByteArrayInputStream;
2020
import java.io.InputStream;
21+
import java.sql.Connection;
2122
import java.sql.Driver;
2223
import java.sql.JDBCType;
2324
import java.sql.PreparedStatement;
@@ -540,4 +541,10 @@ public void bindBlobColumnToPreparedStatement(
540541
public String getTableNamesInNamespaceSql() {
541542
return "SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = ?";
542543
}
544+
545+
@Override
546+
public int getMinimumIsolationLevelForConsistencyReads() {
547+
// In Oracle, only the SERIALIZABLE isolation level guarantees consistent reads
548+
return Connection.TRANSACTION_SERIALIZABLE;
549+
}
543550
}

0 commit comments

Comments
 (0)