Skip to content

Commit 11240e8

Browse files
committed
Fix secondary index behavior in Consensus Commit (#3133)
1 parent 51f8a18 commit 11240e8

20 files changed

+1501
-1273
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,36 @@ public enum CoreError implements ScalarDbError {
684684
"The namespace has non-ScalarDB tables and cannot be dropped. Namespace: %s; Tables in the namespace: %s",
685685
"",
686686
""),
687+
CONSENSUS_COMMIT_SPECIFYING_TRANSACTION_METADATA_COLUMNS_IN_PROJECTION_NOT_ALLOWED(
688+
Category.USER_ERROR,
689+
"0258",
690+
"Specifying transaction metadata columns in the projection is not allowed. Table: %s; Column: %s",
691+
"",
692+
""),
693+
CONSENSUS_COMMIT_SPECIFYING_TRANSACTION_METADATA_COLUMNS_IN_ORDERING_NOT_ALLOWED(
694+
Category.USER_ERROR,
695+
"0259",
696+
"Specifying transaction metadata columns in the ordering is not allowed. Table: %s; Column: %s",
697+
"",
698+
""),
699+
CONSENSUS_COMMIT_INDEX_GET_NOT_ALLOWED_IN_SERIALIZABLE(
700+
Category.USER_ERROR,
701+
"0260",
702+
"Get operations by using an index is not allowed in the SERIALIZABLE isolation level",
703+
"",
704+
""),
705+
CONSENSUS_COMMIT_INDEX_SCAN_NOT_ALLOWED_IN_SERIALIZABLE(
706+
Category.USER_ERROR,
707+
"0261",
708+
"Scan operations by using an index is not allowed in the SERIALIZABLE isolation level",
709+
"",
710+
""),
711+
CONSENSUS_COMMIT_CONDITION_ON_INDEXED_COLUMNS_NOT_ALLOWED_IN_CROSS_PARTITION_SCAN_IN_SERIALIZABLE(
712+
Category.USER_ERROR,
713+
"0262",
714+
"Conditions on indexed columns in cross-partition scan operations are not allowed in the SERIALIZABLE isolation level",
715+
"",
716+
""),
687717

688718
//
689719
// Errors for the concurrency error category

core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommit.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ public class ConsensusCommit extends AbstractDistributedTransaction {
5050
private final TransactionContext context;
5151
private final CrudHandler crud;
5252
private final CommitHandler commit;
53-
private final ConsensusCommitMutationOperationChecker mutationOperationChecker;
53+
private final ConsensusCommitOperationChecker operationChecker;
5454
@Nullable private final CoordinatorGroupCommitter groupCommitter;
5555

5656
@SuppressFBWarnings("EI_EXPOSE_REP2")
5757
public ConsensusCommit(
5858
TransactionContext context,
5959
CrudHandler crud,
6060
CommitHandler commit,
61-
ConsensusCommitMutationOperationChecker mutationOperationChecker,
61+
ConsensusCommitOperationChecker operationChecker,
6262
@Nullable CoordinatorGroupCommitter groupCommitter) {
6363
this.context = checkNotNull(context);
6464
this.crud = checkNotNull(crud);
6565
this.commit = checkNotNull(commit);
66-
this.mutationOperationChecker = mutationOperationChecker;
66+
this.operationChecker = operationChecker;
6767
this.groupCommitter = groupCommitter;
6868
}
6969

@@ -74,17 +74,40 @@ public String getId() {
7474

7575
@Override
7676
public Optional<Result> get(Get get) throws CrudException {
77-
return crud.get(copyAndSetTargetToIfNot(get), context);
77+
get = copyAndSetTargetToIfNot(get);
78+
79+
try {
80+
operationChecker.check(get, context);
81+
} catch (ExecutionException e) {
82+
throw new CrudException(e.getMessage(), e, getId());
83+
}
84+
85+
return crud.get(get, context);
7886
}
7987

8088
@Override
8189
public List<Result> scan(Scan scan) throws CrudException {
82-
return crud.scan(copyAndSetTargetToIfNot(scan), context);
90+
scan = copyAndSetTargetToIfNot(scan);
91+
92+
try {
93+
operationChecker.check(scan, context);
94+
} catch (ExecutionException e) {
95+
throw new CrudException(e.getMessage(), e, getId());
96+
}
97+
98+
return crud.scan(scan, context);
8399
}
84100

85101
@Override
86102
public Scanner getScanner(Scan scan) throws CrudException {
87103
scan = copyAndSetTargetToIfNot(scan);
104+
105+
try {
106+
operationChecker.check(scan, context);
107+
} catch (ExecutionException e) {
108+
throw new CrudException(e.getMessage(), e, getId());
109+
}
110+
88111
return crud.getScanner(scan, context);
89112
}
90113

@@ -245,7 +268,7 @@ void waitForRecoveryCompletion() throws CrudException {
245268

246269
private void checkMutation(Mutation mutation) throws CrudException {
247270
try {
248-
mutationOperationChecker.check(mutation);
271+
operationChecker.check(mutation);
249272
} catch (ExecutionException e) {
250273
throw new CrudException(e.getMessage(), e, getId());
251274
}

core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManager.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class ConsensusCommitManager extends AbstractDistributedTransactionManage
5656
private final CrudHandler crud;
5757
protected final CommitHandler commit;
5858
private final Isolation isolation;
59-
private final ConsensusCommitMutationOperationChecker mutationOperationChecker;
59+
private final ConsensusCommitOperationChecker operationChecker;
6060
@Nullable private final CoordinatorGroupCommitter groupCommitter;
6161

6262
@SuppressFBWarnings("EI_EXPOSE_REP2")
@@ -84,7 +84,9 @@ public ConsensusCommitManager(
8484
parallelExecutor);
8585
commit = createCommitHandler(config);
8686
isolation = config.getIsolation();
87-
mutationOperationChecker = new ConsensusCommitMutationOperationChecker(tableMetadataManager);
87+
operationChecker =
88+
new ConsensusCommitOperationChecker(
89+
tableMetadataManager, config.isIncludeMetadataEnabled());
8890
}
8991

9092
protected ConsensusCommitManager(DatabaseConfig databaseConfig) {
@@ -111,14 +113,17 @@ protected ConsensusCommitManager(DatabaseConfig databaseConfig) {
111113
parallelExecutor);
112114
commit = createCommitHandler(config);
113115
isolation = config.getIsolation();
114-
mutationOperationChecker = new ConsensusCommitMutationOperationChecker(tableMetadataManager);
116+
operationChecker =
117+
new ConsensusCommitOperationChecker(
118+
tableMetadataManager, config.isIncludeMetadataEnabled());
115119
}
116120

117121
@SuppressFBWarnings("EI_EXPOSE_REP2")
118122
@VisibleForTesting
119123
ConsensusCommitManager(
120124
DistributedStorage storage,
121125
DistributedStorageAdmin admin,
126+
ConsensusCommitConfig config,
122127
DatabaseConfig databaseConfig,
123128
Coordinator coordinator,
124129
ParallelExecutor parallelExecutor,
@@ -140,8 +145,9 @@ protected ConsensusCommitManager(DatabaseConfig databaseConfig) {
140145
this.commit = commit;
141146
this.groupCommitter = groupCommitter;
142147
this.isolation = isolation;
143-
this.mutationOperationChecker =
144-
new ConsensusCommitMutationOperationChecker(tableMetadataManager);
148+
this.operationChecker =
149+
new ConsensusCommitOperationChecker(
150+
tableMetadataManager, config.isIncludeMetadataEnabled());
145151
}
146152

147153
// `groupCommitter` must be set before calling this method.
@@ -259,7 +265,7 @@ DistributedTransaction begin(
259265
TransactionContext context =
260266
new TransactionContext(txId, snapshot, isolation, readOnly, oneOperation);
261267
DistributedTransaction transaction =
262-
new ConsensusCommit(context, crud, commit, mutationOperationChecker, groupCommitter);
268+
new ConsensusCommit(context, crud, commit, operationChecker, groupCommitter);
263269
if (readOnly) {
264270
transaction = new ReadOnlyDistributedTransaction(transaction);
265271
}

core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitMutationOperationChecker.java

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)