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

Add validation for consensus commit mutation operation #873

Merged
merged 5 commits into from
May 24, 2023

Conversation

Torch3333
Copy link
Contributor

@Torch3333 Torch3333 commented May 15, 2023

Context
There is no validation to ensure Put or Delete operations do not mutate consensus commit metadata columns. Since these columns are only for internal use, users should not be allowed to modify them.

Changes
A validation step is added to make sure Put or Delete operations do not mutate consensus commit metadata columns. Additionally, setting operation conditions (see #837 ) targeting consensus commit metadata columns are also forbidden.

@Torch3333 Torch3333 self-assigned this May 15, 2023
@Torch3333 Torch3333 added the enhancement New feature or request label May 15, 2023
@Torch3333 Torch3333 force-pushed the validate_consensus_commit_mutation_op branch 2 times, most recently from 1f16837 to e97521c Compare May 15, 2023 08:28
@Torch3333 Torch3333 force-pushed the validate_consensus_commit_mutation_op branch from e97521c to 0212c8b Compare May 15, 2023 08:31
@Torch3333 Torch3333 marked this pull request as ready for review May 16, 2023 02:20
@Torch3333 Torch3333 requested review from a team, komamitsu, brfrn169 and feeblefakie and removed request for a team May 16, 2023 02:20
checkArgument(puts.size() != 0);
puts.forEach(this::put);
for (Put p : puts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[just out of curiosity] Is this change for suppressing warning or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this::put throws the checked exception CrudException but the Consumer functional interface does not throw any checked exception.

public void forEach(java.util.function.Consumer<? super T> action)

Our only option is to use a non-lambda for each if we want to propagate the CrudException.

if (!(condition instanceof PutIf
|| condition instanceof PutIfNotExists
|| condition instanceof PutIfExists)) {
throw new IllegalArgumentException("The condition is not allowed on Put operation");
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess a user would be interested in the type of the wrong condition when receiving this exception. How about showing it in the error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is a good point, thank you. I will add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revised in 4e05db8

Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

Left one minor comment. Other than that, LGTM. Please take a look when you have time!

Comment on lines 183 to 184
ConsensusCommitMutationOperationChecker operationChecker =
new ConsensusCommitMutationOperationChecker(tableMetadataManager);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of creating a ConsensusCommitMutationOperationChecker instance each time, can we hold it as an instance field of ConsensusCommitManager and pass it to ConsensusCommit instances?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good point, thank you.
My bad, I did it for the 2pc transaction manager but not for this one.
Revised in de06ddc

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM (except for what Toshi pointed out)! Thank you!
I also left a question for just confirmation.

put.getCondition()
.ifPresent(
condition -> {
if (!(condition instanceof PutIf
Copy link
Contributor

Choose a reason for hiding this comment

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

Just quick confirmation.
This check will be deleted in another PR, which makes conditions usable, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe there is a misunderstanding but this step validates DeleteIf and DeleteIfExists conditions are not used for Put operation so I plan to keep this code even when condition are usable. Is that ok ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry, yes, that's my misunderstanding. Thanks!

@Torch3333 Torch3333 requested a review from brfrn169 May 24, 2023 02:04
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@brfrn169 brfrn169 merged commit 26c0a07 into master May 24, 2023
12 checks passed
@brfrn169 brfrn169 deleted the validate_consensus_commit_mutation_op branch May 24, 2023 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants