keith-turner commented on a change in pull request #1276: Refactor how
constraint violations are handled
URL: https://github.com/apache/accumulo/pull/1276#discussion_r306048539
##########
File path:
server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java
##########
@@ -1115,53 +1114,29 @@ private synchronized CommitSession
finishPreparingMutations(long time) {
return commitSession;
}
- public CommitSession prepareMutationsForCommit(TservConstraintEnv cenv,
List<Mutation> mutations)
- throws TConstraintViolationException {
-
- ConstraintChecker cc = constraintChecker.derive();
-
- List<Mutation> violators = null;
- Violations violations = new Violations();
+ public TabletMutationPrepAttempt prepareMutationsForCommit(final
TservConstraintEnv cenv,
+ final List<Mutation> mutations) {
cenv.setExtent(extent);
- for (Mutation mutation : mutations) {
- Violations more = cc.check(cenv, mutation);
- if (more != null) {
- violations.add(more);
- if (violators == null) {
- violators = new ArrayList<>();
- }
- violators.add(mutation);
- }
- }
-
- long time = tabletTime.setUpdateTimes(mutations);
-
- if (!violations.isEmpty()) {
-
- HashSet<Mutation> violatorsSet = new HashSet<>(violators);
- ArrayList<Mutation> nonViolators = new ArrayList<>();
-
- for (Mutation mutation : mutations) {
- if (!violatorsSet.contains(mutation)) {
- nonViolators.add(mutation);
- }
- }
-
- CommitSession commitSession = null;
-
- if (nonViolators.size() > 0) {
- // if everything is a violation, then it is expected that
- // code calling this will not log or commit
- commitSession = finishPreparingMutations(time);
- if (commitSession == null) {
- return null;
- }
+ final ConstraintChecker constraints = constraintChecker.derive();
+ final TabletMutationPrepAttempt attempt = new TabletMutationPrepAttempt();
+
+ // Check each mutation for violations.
+ mutations.forEach(mutation -> {
+ Violations violations = constraints.check(cenv, mutation);
+ if (violations != null) {
+ attempt.addViolator(mutation, violations);
+ } else {
+ attempt.addNonViolator(mutation);
}
+ });
- throw new TConstraintViolationException(violations, violators,
nonViolators, commitSession);
+ // If there are no violations, or at least some mutations that do not
violate the constraints,
+ // attempt to prepare the tablet and retrieve the commit session.
+ if (!attempt.hasViolations() || attempt.hasNonViolators()) {
Review comment:
Could this be `if(attempt.hasNonViolators()) {` ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services