Search in sources :

Example 1 with ComparableBytes

use of org.apache.accumulo.core.dataImpl.ComparableBytes in project accumulo by apache.

the class ConstraintChecker method check.

public Violations check(Environment env, Mutation m) {
    if (!tabletContains(env.getTablet(), new ComparableBytes(m.getRow()))) {
        Violations violations = new Violations();
        ConstraintViolationSummary cvs = new ConstraintViolationSummary(SystemConstraint.class.getName(), (short) -1, "Mutation outside of tablet extent", 1);
        violations.add(cvs);
        // do not bother with further checks since this mutation does not go with this tablet
        return violations;
    }
    // violations is intentionally initialized as null for performance
    Violations violations = null;
    for (Constraint constraint : getConstraints()) {
        try {
            List<Short> violationCodes = constraint.check(env, m);
            if (violationCodes != null) {
                String className = constraint.getClass().getName();
                for (Short vcode : violationCodes) {
                    violations = addViolation(violations, new ConstraintViolationSummary(className, vcode, constraint.getViolationDescription(vcode), 1));
                }
            }
        } catch (Exception e) {
            log.warn("CONSTRAINT FAILED : {}", e.getMessage(), e);
            // constraint failed in some way, do not allow mutation to pass
            short vcode;
            String msg;
            if (e instanceof NullPointerException) {
                vcode = -1;
                msg = "threw NullPointerException";
            } else if (e instanceof ArrayIndexOutOfBoundsException) {
                vcode = -2;
                msg = "threw ArrayIndexOutOfBoundsException";
            } else if (e instanceof NumberFormatException) {
                vcode = -3;
                msg = "threw NumberFormatException";
            } else {
                vcode = -100;
                msg = "threw some Exception";
            }
            violations = addViolation(violations, new ConstraintViolationSummary(constraint.getClass().getName(), vcode, "CONSTRAINT FAILED : " + msg, 1));
        }
    }
    return violations;
}
Also used : Violations(org.apache.accumulo.core.constraints.Violations) Constraint(org.apache.accumulo.core.data.constraints.Constraint) ComparableBytes(org.apache.accumulo.core.dataImpl.ComparableBytes) ConstraintViolationSummary(org.apache.accumulo.core.data.ConstraintViolationSummary)

Aggregations

Violations (org.apache.accumulo.core.constraints.Violations)1 ConstraintViolationSummary (org.apache.accumulo.core.data.ConstraintViolationSummary)1 Constraint (org.apache.accumulo.core.data.constraints.Constraint)1 ComparableBytes (org.apache.accumulo.core.dataImpl.ComparableBytes)1