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 re-throwing the exception after cancelling the group commit might mask the original stack trace, making debugging harder. Consider logging the caught exception before re-throwing it to preserve the context.

Suggested change
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
try {
return super.canOnePhaseCommit(snapshot);
} catch (CommitException e) {
cancelGroupCommitIfNeeded(snapshot.getId());
throw e;
}
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
try {
return super.canOnePhaseCommit(snapshot);
} catch (CommitException e) {
logger.warn("canOnePhaseCommit failed", e); // Log the exception
cancelGroupCommitIfNeeded(snapshot.getId());
throw e;
}
}

}

@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

The createCommitHandlerWithOnePhaseCommit method is duplicated here and in CommitHandlerWithGroupCommitTest.java. Consider creating a single method in a common base class or utility class to avoid duplication and improve maintainability.


@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 +223
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    verify(groupCommitter).remove(anyId());
  }

}

@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 +234
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    verify(groupCommitter).remove(anyId());
  }

}

@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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    verify(groupCommitter).remove(anyId());
  }

}

@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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    verify(groupCommitter).remove(anyId());
  }

}

@Test
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations() {}
@Override
public void canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse() throws Exception {
super.canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse();
groupCommitter.remove(anyId());
}
Comment on lines 261 to +266
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    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());
}
Comment on lines +268 to +273
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    groupCommitter.remove(anyId());
  }


@Test
public void
onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException() {}
@Override
public void canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse() throws Exception {
super.canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse();
groupCommitter.remove(anyId());
}
Comment on lines 275 to +280
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    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());
Comment on lines +282 to +287
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    groupCommitter.remove(anyId());
  }

}

@Test
public void
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException() {}
@Override
public void canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue() throws Exception {
super.canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue();
groupCommitter.remove(anyId());
Comment on lines +289 to +294
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    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());
Comment on lines +297 to +301
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    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());
Comment on lines 304 to +313
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    groupCommitter.remove(anyId());
  }


@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 +332
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 remove method of groupCommitter is called, but the return value is not checked. If remove fails, it might indicate an issue that should be handled. Consider logging a warning if remove returns false.

    groupCommitter.remove(anyId());
  }

}