无法加载accumulo约束,导致UnsatisfiableConstraint失败

时间:2015-07-20 06:32:45

标签: java accumulo

我一直在尝试在Accumulo中处理自定义约束。我通过实现org.apache.accumulo.core.constraints.Constraint创建了约束。

但是当它应用于表格时,我会收到以下错误

  

约束失败:ConstraintViolationSummary(constrainClass:org.apache.accumulo.tserver.constraints.UnsatisfiableConstraint,violationCode:-1,violationDescription:无法加载约束,不接受突变。,numberOfViolatingMutations:1)

下面是我的代码段

 package samplepackageforconstraints;

    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.List;

    import org.apache.accumulo.core.constraints.Constraint;
    import org.apache.accumulo.core.data.ColumnUpdate;
    import org.apache.accumulo.core.data.Mutation;

public class LengthConstraintsTest implements Constraint{

    private static final short NOT_ENOUGH_LENGTH = 1;

    @Override
    public List<Short> check(Environment env, Mutation mutation) {
        List<Short> violations = null;
        Collection<ColumnUpdate> updates = mutation.getUpdates();

        for (ColumnUpdate columnUpdate : updates) {

            if (!isLessThanThree(columnUpdate.getValue()))
                violations = addViolation(violations, NOT_ENOUGH_LENGTH);

        }
        return violations;
    }

    @Override
    public String getViolationDescription(short violationCode) {
         switch (violationCode) {
          case NOT_ENOUGH_LENGTH:
            return "Value should be more than 3 character";
        }
        return null;
    }

    private List<Short> addViolation(List<Short> violations, short violation) {
        if (violations == null) {

            violations = new ArrayList<Short>();
            violations.add(violation);
        } else if (!violations.contains(violation)) {

            violations.add(violation);
        }
        return violations;
    }

    private boolean isLessThanThree(byte[] value) {
        if(value.length <3)
        return false;
        else
            return true;
    }
}

我已按照 user manual of accumulo version 1.7中给出的步骤操作 还cloudera 用于加载约束

我正在使用版本:accumulo的1.6.0-cdh5.1.4

提前致谢:)

1 个答案:

答案 0 :(得分:1)

当无法加载约束时,这意味着从类路径(通常)加载类时出现问题,或者(不太可能)该类与Constraint接口不对应。

您需要将包含自定义约束的jar添加到每个平板电脑服务器的类路径中。

您可以通过检查引发此异常的节点上的服务器日志来进一步调试此问题。