Search in sources :

Example 1 with ConstraintChecker

use of org.apache.accumulo.tserver.constraints.ConstraintChecker in project accumulo by apache.

the class Tablet method checkConstraints.

public void checkConstraints() {
    ConstraintChecker cc = constraintChecker.get();
    if (cc.classLoaderChanged()) {
        ConstraintChecker ncc = new ConstraintChecker(tableConfiguration);
        constraintChecker.compareAndSet(cc, ncc);
    }
}
Also used : ConstraintChecker(org.apache.accumulo.tserver.constraints.ConstraintChecker)

Example 2 with ConstraintChecker

use of org.apache.accumulo.tserver.constraints.ConstraintChecker in project accumulo by apache.

the class Tablet method prepareMutationsForCommit.

public CommitSession prepareMutationsForCommit(TservConstraintEnv cenv, List<Mutation> mutations) throws TConstraintViolationException {
    ConstraintChecker cc = constraintChecker.get();
    List<Mutation> violators = null;
    Violations violations = new Violations();
    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;
        }
        throw new TConstraintViolationException(violations, violators, nonViolators, commitSession);
    }
    return finishPreparingMutations(time);
}
Also used : Violations(org.apache.accumulo.core.constraints.Violations) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Mutation(org.apache.accumulo.core.data.Mutation) ConstraintChecker(org.apache.accumulo.tserver.constraints.ConstraintChecker) TConstraintViolationException(org.apache.accumulo.tserver.TConstraintViolationException) HashSet(java.util.HashSet)

Aggregations

ConstraintChecker (org.apache.accumulo.tserver.constraints.ConstraintChecker)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Violations (org.apache.accumulo.core.constraints.Violations)1 Mutation (org.apache.accumulo.core.data.Mutation)1 TConstraintViolationException (org.apache.accumulo.tserver.TConstraintViolationException)1