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_r308708860
##########
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();
Review comment:
> My only caution about this approach is that it makes it possible for the
original mutation list to be modified if there are no violations
Yeah that is a problem. One way to address the issue is for the originator
of the list to make it immutable. Accumulo could benefit from using more
immutable collections.
----------------------------------------------------------------
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