-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
1f16837
to
e97521c
Compare
e97521c
to
0212c8b
Compare
.../java/com/scalar/db/transaction/consensuscommit/ConsensusCommitMutationOperationChecker.java
Show resolved
Hide resolved
checkArgument(puts.size() != 0); | ||
puts.forEach(this::put); | ||
for (Put p : puts) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revised in 4e05db8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
There was a problem hiding this 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!
ConsensusCommitMutationOperationChecker operationChecker = | ||
new ConsensusCommitMutationOperationChecker(tableMetadataManager); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
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.