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_r306070322
 
 

 ##########
 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:
   The existing code attempts to minimize the work done when no mutations 
violate a constraint.  It would be nice to carry this behavior forward, but I 
am not sure of the best way to do this.
   
   Below is one possibility I thought of...
   
   ```java
   Iterator<Mutation> miter = mutations.iterator(); //TODO reverse iterator 
would be more efficient when everything is removed
   while(miter.hasNext()) {
     Mutation mutation = miter.next();
     Violations violations = constraints.check(cenv, mutation);
     if(violations != null) {
         attempt.addViolator(mutation, violations);  // TODO this method could 
allocate its internal list of vilolators the first time called
        miter.remove();  // TODO is it ok to modify the list passed in??
     }
   }
   
   // if nothing violates, then the passed in list is not copied or modified...
   attempt.setMutations(mutations);
   ```

----------------------------------------------------------------
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

Reply via email to