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_r306378738
##########
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:
> I checked each call to this function and there are cases where the
original mutations list is still subsequently used, so we should avoid
modifying it.
Ok, thanks for checking that. I suppose that is why the existing code does
something with a hashset when there are mutations. Could possibly do something
like the following.
```java
List<Mutation> vl = null;
for(Mutation mutation : mutations) {
// TODO check for violations and if when one is found add to vl...
creating vl if needed
}
if(vl.isEmpty()){
// just use mutations list
} else {
// copy mutations list and subtract violating 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