Skip to content
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 @@ -57,6 +57,23 @@ public void commit(Snapshot snapshot, boolean readOnly)
super.commit(snapshot, readOnly);
}

@Override
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
try {
return super.canOnePhaseCommit(snapshot);
} catch (CommitException e) {
cancelGroupCommitIfNeeded(snapshot.getId());
throw e;
}
Comment on lines +61 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Wrapping the call to super.canOnePhaseCommit in a try-catch block and then throwing the caught exception is redundant. You can simplify this by directly throwing the exception after canceling the group commit if needed.

Also, consider logging the exception before re-throwing it to aid in debugging.

Suggested change
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
try {
return super.canOnePhaseCommit(snapshot);
} catch (CommitException e) {
cancelGroupCommitIfNeeded(snapshot.getId());
throw e;
}
@Override
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
try {
return super.canOnePhaseCommit(snapshot);
} catch (CommitException e) {
cancelGroupCommitIfNeeded(snapshot.getId());
throw e; // Re-throw the exception
}
}

}

@Override
void onePhaseCommitRecords(Snapshot snapshot)
throws CommitConflictException, UnknownTransactionStatusException {
cancelGroupCommitIfNeeded(snapshot.getId());
super.onePhaseCommitRecords(snapshot);
}

@Override
protected void onFailureBeforeCommit(Snapshot snapshot) {
cancelGroupCommitIfNeeded(snapshot.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ protected CommitHandler createCommitHandler(boolean coordinatorWriteOmissionOnRe
false);
}

protected CommitHandler createCommitHandlerWithOnePhaseCommit() {
return new CommitHandler(
storage, coordinator, tableMetadataManager, parallelExecutor, mutationsGrouper, true, true);
}
Comment on lines +93 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This method createCommitHandlerWithOnePhaseCommit is duplicated in CommitHandlerTest.java and CommitHandlerWithGroupCommitTest.java. Consider creating this method in a common base class to avoid duplication.


@BeforeEach
void setUp() throws Exception {
MockitoAnnotations.openMocks(this).close();
Expand Down Expand Up @@ -1068,8 +1073,9 @@ public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() t
}

@Test
public void canOnePhaseCommit_WhenMutationsGrouperThrowsException_ShouldThrowCommitException()
throws ExecutionException {
public void
canOnePhaseCommit_WhenMutationsGrouperThrowsExecutionException_ShouldThrowCommitException()
throws ExecutionException {
// Arrange
CommitHandler handler = createCommitHandlerWithOnePhaseCommit();
Snapshot snapshot = prepareSnapshot();
Expand Down Expand Up @@ -1180,11 +1186,6 @@ public void commit_OnePhaseCommitted_ShouldNotThrowAnyException()
verify(handler).onFailureBeforeCommit(snapshot);
}

private CommitHandler createCommitHandlerWithOnePhaseCommit() {
return new CommitHandler(
storage, coordinator, tableMetadataManager, parallelExecutor, mutationsGrouper, true, true);
}

protected void doThrowExceptionWhenCoordinatorPutState(
TransactionState targetState, Class<? extends Exception> exceptionClass)
throws CoordinatorException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

import com.scalar.db.api.TransactionState;
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.exception.transaction.CommitConflictException;
import com.scalar.db.exception.transaction.CommitException;
import com.scalar.db.exception.transaction.UnknownTransactionStatusException;
import com.scalar.db.exception.transaction.ValidationConflictException;
import com.scalar.db.transaction.consensuscommit.CoordinatorGroupCommitter.CoordinatorGroupCommitKeyManipulator;
import com.scalar.db.util.groupcommit.GroupCommitConfig;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -75,6 +75,20 @@ protected CommitHandler createCommitHandler(boolean coordinatorWriteOmissionOnRe
groupCommitter);
}

@Override
protected CommitHandler createCommitHandlerWithOnePhaseCommit() {
createGroupCommitterIfNotExists();
return new CommitHandlerWithGroupCommit(
storage,
coordinator,
tableMetadataManager,
parallelExecutor,
mutationsGrouper,
true,
true,
groupCommitter);
}

private String anyGroupCommitParentId() {
return parentKey;
}
Expand Down Expand Up @@ -199,72 +213,121 @@ public void commit_NoReadsInSnapshot_ShouldNotValidateRecords(boolean withSnapsh
verify(groupCommitter, never()).remove(anyId());
}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse() {}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenValidationRequired_ShouldReturnFalse() {}
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations()
throws CommitConflictException, UnknownTransactionStatusException, ExecutionException {
super.onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations();

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse() {}
// Assert
verify(groupCommitter).remove(anyId());
}
Comment on lines 216 to +224
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The verify(groupCommitter).remove(anyId()) call is made after calling the super method. It would be more readable if this was done before the super method call, to clearly indicate the order of operations.

Suggested change
@Test
public void canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse() {}
@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenValidationRequired_ShouldReturnFalse() {}
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations()
throws CommitConflictException, UnknownTransactionStatusException, ExecutionException {
super.onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations();
@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse() {}
// Assert
verify(groupCommitter).remove(anyId());
}
@Test
@Override
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations()
throws CommitConflictException, UnknownTransactionStatusException, ExecutionException {
// Assert
verify(groupCommitter).remove(anyId());
super.onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations();
}


@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenDeleteWithoutExistingRecord_ShouldReturnFalse() {}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue() {}
public void
onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException()
throws ExecutionException {
super.onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException();

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() {}
// Assert
verify(groupCommitter).remove(anyId());
}
Comment on lines 226 to +235
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The verify(groupCommitter).remove(anyId()) call is made after calling the super method. It would be more readable if this was done before the super method call, to clearly indicate the order of operations.

Suggested change
@Test
public void canOnePhaseCommit_WhenDeleteWithoutExistingRecord_ShouldReturnFalse() {}
@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue() {}
public void
onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException()
throws ExecutionException {
super.onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException();
@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() {}
// Assert
verify(groupCommitter).remove(anyId());
}
@Test
@Override
public void
onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException()
throws ExecutionException {
// Assert
verify(groupCommitter).remove(anyId());
super.onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException();
}


@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void canOnePhaseCommit_WhenMutationsGrouperThrowsException_ShouldThrowCommitException() {}
@Override
public void
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException()
throws ExecutionException {
super
.onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException();

@Disabled("Enabling both one-phase commit and group commit is not supported")
// Assert
verify(groupCommitter).remove(anyId());
Comment on lines 237 to +246
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The verify(groupCommitter).remove(anyId()) call is made after calling the super method. It would be more readable if this was done before the super method call, to clearly indicate the order of operations.

Suggested change
@Test
public void canOnePhaseCommit_WhenMutationsGrouperThrowsException_ShouldThrowCommitException() {}
@Override
public void
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException()
throws ExecutionException {
super
.onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException();
@Disabled("Enabling both one-phase commit and group commit is not supported")
// Assert
verify(groupCommitter).remove(anyId());
@Test
@Override
public void
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException()
throws ExecutionException {
// Assert
verify(groupCommitter).remove(anyId());
super
.onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException();
}

}

@Test
@Override
public void
onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException()
throws ExecutionException {
super
.onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException();

// Assert
verify(groupCommitter).remove(anyId());
Comment on lines +248 to +258
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The verify(groupCommitter).remove(anyId()) call is made after calling the super method. It would be more readable if this was done before the super method call, to clearly indicate the order of operations.

  @Test
  @Override
  public void
      onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException()
          throws ExecutionException {
    // Assert
    verify(groupCommitter).remove(anyId());

    super
        .onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException();
  }

}

@Test
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations() {}
@Override
public void canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse() throws Exception {
super.canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse();
groupCommitter.remove(anyId());
}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Test
@Override
public void canOnePhaseCommit_WhenValidationRequired_ShouldReturnFalse() throws Exception {
super.canOnePhaseCommit_WhenValidationRequired_ShouldReturnFalse();
groupCommitter.remove(anyId());
}

@Test
public void
onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException() {}
@Override
public void canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse() throws Exception {
super.canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse();
groupCommitter.remove(anyId());
}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Test
@Override
public void canOnePhaseCommit_WhenDeleteWithoutExistingRecord_ShouldReturnFalse()
throws Exception {
super.canOnePhaseCommit_WhenDeleteWithoutExistingRecord_ShouldReturnFalse();
groupCommitter.remove(anyId());
}

@Test
public void
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException() {}
@Override
public void canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue() throws Exception {
super.canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue();
groupCommitter.remove(anyId());
}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Test
@Override
public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() throws Exception {
super.canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse();
groupCommitter.remove(anyId());
}

@Test
@Override
public void
onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException() {}
canOnePhaseCommit_WhenMutationsGrouperThrowsExecutionException_ShouldThrowCommitException()
throws ExecutionException {
super
.canOnePhaseCommit_WhenMutationsGrouperThrowsExecutionException_ShouldThrowCommitException();

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Override
@Test
public void commit_OnePhaseCommitted_ShouldNotThrowAnyException() {}
// Assert
verify(groupCommitter).remove(anyId());
}

@Disabled("Enabling both one-phase commit and group commit is not supported")
@Test
@Override
public void commit_OnePhaseCommitted_ShouldNotThrowAnyException()
throws CommitException, UnknownTransactionStatusException {
super.commit_OnePhaseCommitted_ShouldNotThrowAnyException();
groupCommitter.remove(anyId());
}
Comment on lines +316 to +322
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The groupCommitter.remove(anyId()) call is made after calling the super method. It would be more readable if this was done before the super method call, to clearly indicate the order of operations.

  @Test
  @Override
  public void commit_OnePhaseCommitted_ShouldNotThrowAnyException()
      throws CommitException, UnknownTransactionStatusException {
    // Assert
    groupCommitter.remove(anyId());

    super.commit_OnePhaseCommitted_ShouldNotThrowAnyException();
  }


@Test
@Override
public void
commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException() {}
commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException()
throws CommitException, UnknownTransactionStatusException {
super
.commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException();
groupCommitter.remove(anyId());
Comment on lines 324 to +331
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The groupCommitter.remove(anyId()) call is made after calling the super method. It would be more readable if this was done before the super method call, to clearly indicate the order of operations.

  @Test
  @Override
  public void
      commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException()
          throws CommitException, UnknownTransactionStatusException {
    // Assert
    groupCommitter.remove(anyId());

    super
        .commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException();
  }

}
}