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

Backport to branch(3) : Delay throwing an exception for the combination of two-phase commit interface and the group commit feature to when begin() is called #1908

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public TwoPhaseConsensusCommitManager(
this.storage = storage;
this.admin = admin;
config = new ConsensusCommitConfig(databaseConfig);
throwIfGroupCommitIsEnabled(config);
tableMetadataManager =
new TransactionTableMetadataManager(
admin, databaseConfig.getMetadataCacheExpirationTimeSecs());
Expand All @@ -61,9 +60,7 @@ public TwoPhaseConsensusCommitManager(DatabaseConfig databaseConfig) {
StorageFactory storageFactory = StorageFactory.create(databaseConfig.getProperties());
storage = storageFactory.getStorage();
admin = storageFactory.getStorageAdmin();

config = new ConsensusCommitConfig(databaseConfig);
throwIfGroupCommitIsEnabled(config);
tableMetadataManager =
new TransactionTableMetadataManager(
admin, databaseConfig.getMetadataCacheExpirationTimeSecs());
Expand All @@ -90,7 +87,6 @@ public TwoPhaseConsensusCommitManager(DatabaseConfig databaseConfig) {
this.storage = storage;
this.admin = admin;
this.config = config;
throwIfGroupCommitIsEnabled(config);
tableMetadataManager =
new TransactionTableMetadataManager(
admin, databaseConfig.getMetadataCacheExpirationTimeSecs());
Expand All @@ -102,7 +98,7 @@ public TwoPhaseConsensusCommitManager(DatabaseConfig databaseConfig) {
mutationOperationChecker = new ConsensusCommitMutationOperationChecker(tableMetadataManager);
}

private void throwIfGroupCommitIsEnabled(ConsensusCommitConfig config) {
private void throwIfGroupCommitIsEnabled() {
if (CoordinatorGroupCommitter.isEnabled(config)) {
throw new IllegalArgumentException(
CoreError.CONSENSUS_COMMIT_GROUP_COMMIT_WITH_TWO_PHASE_COMMIT_INTERFACE_NOT_ALLOWED
Expand Down Expand Up @@ -132,6 +128,7 @@ TwoPhaseCommitTransaction begin(Isolation isolation, SerializableStrategy strate
@VisibleForTesting
TwoPhaseCommitTransaction begin(String txId, Isolation isolation, SerializableStrategy strategy)
throws TransactionException {
throwIfGroupCommitIsEnabled();
return createNewTransaction(txId, isolation, strategy);
}

Expand All @@ -144,6 +141,7 @@ public TwoPhaseCommitTransaction join(String txId) throws TransactionException {
@VisibleForTesting
TwoPhaseCommitTransaction join(String txId, Isolation isolation, SerializableStrategy strategy)
throws TransactionException {
throwIfGroupCommitIsEnabled();
// If the transaction associated with the specified transaction ID is active, resume it
if (isTransactionActive(txId)) {
return resume(txId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,6 @@ public void setUp() throws Exception {
commit);
}

@Test
public void constructor_GroupCommitEnabledGiven_ShouldThrowException() {
// Arrange
when(config.isCoordinatorGroupCommitEnabled()).thenReturn(true);

// Act Assert
assertThatThrownBy(
() ->
new TwoPhaseConsensusCommitManager(
storage,
admin,
config,
databaseConfig,
coordinator,
parallelExecutor,
recovery,
commit))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
public void begin_NoArgumentGiven_ReturnWithSomeTxIdAndSnapshotIsolation()
throws TransactionException {
Expand Down Expand Up @@ -168,6 +148,24 @@ public void begin_CalledTwiceWithSameTxId_ThrowTransactionException()
assertThatThrownBy(() -> manager.begin(ANY_TX_ID)).isInstanceOf(TransactionException.class);
}

@Test
public void begin_NoArgumentGiven_WithGroupCommitEnabled_ShouldThrowException() {
// Arrange
when(config.isCoordinatorGroupCommitEnabled()).thenReturn(true);

// Act Assert
assertThatThrownBy(() -> manager.begin()).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void begin_TxIdGiven_WithGroupCommitEnabled_ShouldThrowException() {
// Arrange
when(config.isCoordinatorGroupCommitEnabled()).thenReturn(true);

// Act Assert
assertThatThrownBy(() -> manager.begin(ANY_TX_ID)).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void start_NoArgumentGiven_ReturnWithSomeTxIdAndSnapshotIsolation()
throws TransactionException {
Expand Down Expand Up @@ -236,6 +234,24 @@ public void start_CalledTwiceWithSameTxId_ThrowTransactionException()
assertThatThrownBy(() -> manager.start(ANY_TX_ID)).isInstanceOf(TransactionException.class);
}

@Test
public void start_NoArgumentGiven_WithGroupCommitEnabled_ShouldThrowException() {
// Arrange
when(config.isCoordinatorGroupCommitEnabled()).thenReturn(true);

// Act Assert
assertThatThrownBy(() -> manager.start()).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void start_TxIdGiven_WithGroupCommitEnabled_ShouldThrowException() {
// Arrange
when(config.isCoordinatorGroupCommitEnabled()).thenReturn(true);

// Act Assert
assertThatThrownBy(() -> manager.start(ANY_TX_ID)).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void join_TxIdGiven_ReturnWithSpecifiedTxIdAndSnapshotIsolation()
throws TransactionException {
Expand Down Expand Up @@ -265,6 +281,15 @@ public void join_CalledAfterJoinWithSameTxId_ReturnSameTransactionObject()
assertThat(transaction1).isEqualTo(transaction2);
}

@Test
public void join_TxIdGiven_WithGroupCommitEnabled_ShouldThrowException() {
// Arrange
when(config.isCoordinatorGroupCommitEnabled()).thenReturn(true);

// Act Assert
assertThatThrownBy(() -> manager.join(ANY_TX_ID)).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void resume_CalledWithBegin_ReturnSameTransactionObject() throws TransactionException {
// Arrange
Expand Down
Loading