Search in sources :

Example 11 with IZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.

the class Utils method getNextId.

static <T extends AbstractId> T getNextId(String name, Instance instance, Function<String, T> newIdFunction) throws AcceptableThriftTableOperationException {
    try {
        IZooReaderWriter zoo = ZooReaderWriter.getInstance();
        final String ntp = ZooUtil.getRoot(instance) + Constants.ZTABLES;
        byte[] nid = zoo.mutate(ntp, ZERO_BYTE, ZooUtil.PUBLIC, currentValue -> {
            BigInteger nextId = new BigInteger(new String(currentValue, UTF_8), Character.MAX_RADIX);
            nextId = nextId.add(BigInteger.ONE);
            return nextId.toString(Character.MAX_RADIX).getBytes(UTF_8);
        });
        return newIdFunction.apply(new String(nid, UTF_8));
    } catch (Exception e1) {
        log.error("Failed to assign id to " + name, e1);
        throw new AcceptableThriftTableOperationException(null, name, TableOperation.CREATE, TableOperationExceptionType.OTHER, e1.getMessage());
    }
}
Also used : IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) BigInteger(java.math.BigInteger) KeeperException(org.apache.zookeeper.KeeperException) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)

Example 12 with IZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.

the class FateAdmin method main.

public static void main(String[] args) throws Exception {
    Help opts = new Help();
    JCommander jc = new JCommander(opts);
    jc.setProgramName(FateAdmin.class.getName());
    LinkedHashMap<String, TxOpts> txOpts = new LinkedHashMap<>(2);
    txOpts.put("fail", new FailOpts());
    txOpts.put("delete", new DeleteOpts());
    for (Entry<String, TxOpts> entry : txOpts.entrySet()) {
        jc.addCommand(entry.getKey(), entry.getValue());
    }
    jc.addCommand("print", new PrintOpts());
    jc.parse(args);
    if (opts.help || jc.getParsedCommand() == null) {
        jc.usage();
        System.exit(1);
    }
    System.err.printf("This tool has been deprecated%nFATE administration now available within 'accumulo shell'%n$ fate fail <txid>... | delete <txid>... | print [<txid>...]%n%n");
    AdminUtil<Master> admin = new AdminUtil<>();
    Instance instance = HdfsZooInstance.getInstance();
    String path = ZooUtil.getRoot(instance) + Constants.ZFATE;
    String masterPath = ZooUtil.getRoot(instance) + Constants.ZMASTER_LOCK;
    IZooReaderWriter zk = ZooReaderWriter.getInstance();
    ZooStore<Master> zs = new ZooStore<>(path, zk);
    if (jc.getParsedCommand().equals("fail")) {
        for (String txid : txOpts.get(jc.getParsedCommand()).txids) {
            if (!admin.prepFail(zs, zk, masterPath, txid)) {
                System.exit(1);
            }
        }
    } else if (jc.getParsedCommand().equals("delete")) {
        for (String txid : txOpts.get(jc.getParsedCommand()).txids) {
            if (!admin.prepDelete(zs, zk, masterPath, txid)) {
                System.exit(1);
            }
            admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, txid);
        }
    } else if (jc.getParsedCommand().equals("print")) {
        admin.print(new ReadOnlyStore<>(zs), zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS);
    }
}
Also used : Help(org.apache.accumulo.core.cli.Help) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ZooStore(org.apache.accumulo.fate.ZooStore) LinkedHashMap(java.util.LinkedHashMap) Master(org.apache.accumulo.master.Master) AdminUtil(org.apache.accumulo.fate.AdminUtil) JCommander(com.beust.jcommander.JCommander) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter)

Example 13 with IZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.

the class CompactRange method call.

@Override
public Repo<Master> call(final long tid, Master env) throws Exception {
    String zTablePath = Constants.ZROOT + "/" + env.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    byte[] cid;
    try {
        cid = zoo.mutate(zTablePath, null, null, new Mutator() {

            @Override
            public byte[] mutate(byte[] currentValue) throws Exception {
                String cvs = new String(currentValue, UTF_8);
                String[] tokens = cvs.split(",");
                long flushID = Long.parseLong(tokens[0]);
                flushID++;
                String txidString = String.format("%016x", tid);
                for (int i = 1; i < tokens.length; i++) {
                    if (tokens[i].startsWith(txidString))
                        // skip self
                        continue;
                    log.debug("txidString : {}", txidString);
                    log.debug("tokens[{}] : {}", i, tokens[i]);
                    throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Another compaction with iterators and/or a compaction strategy is running");
                }
                StringBuilder encodedIterators = new StringBuilder();
                if (config != null) {
                    Hex hex = new Hex();
                    encodedIterators.append(",");
                    encodedIterators.append(txidString);
                    encodedIterators.append("=");
                    encodedIterators.append(new String(hex.encode(config), UTF_8));
                }
                return (Long.toString(flushID) + encodedIterators).getBytes(UTF_8);
            }
        });
        return new CompactionDriver(Long.parseLong(new String(cid, UTF_8).split(",")[0]), namespaceId, tableId, startRow, endRow);
    } catch (NoNodeException nne) {
        throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null);
    }
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Mutator(org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) Hex(org.apache.commons.codec.binary.Hex) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)

Example 14 with IZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.

the class CompactRange method removeIterators.

static void removeIterators(Master environment, final long txid, Table.ID tableId) throws Exception {
    String zTablePath = Constants.ZROOT + "/" + environment.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    zoo.mutate(zTablePath, null, null, new Mutator() {

        @Override
        public byte[] mutate(byte[] currentValue) throws Exception {
            String cvs = new String(currentValue, UTF_8);
            String[] tokens = cvs.split(",");
            long flushID = Long.parseLong(tokens[0]);
            String txidString = String.format("%016x", txid);
            StringBuilder encodedIterators = new StringBuilder();
            for (int i = 1; i < tokens.length; i++) {
                if (tokens[i].startsWith(txidString))
                    continue;
                encodedIterators.append(",");
                encodedIterators.append(tokens[i]);
            }
            return (Long.toString(flushID) + encodedIterators).getBytes(UTF_8);
        }
    });
}
Also used : Mutator(org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 15 with IZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.

the class TraceServer method registerInZooKeeper.

private void registerInZooKeeper(String name, String root) throws Exception {
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    zoo.putPersistentData(root, new byte[0], NodeExistsPolicy.SKIP);
    log.info("Registering tracer {} at {}", name, root);
    String path = zoo.putEphemeralSequential(root + "/trace-", name.getBytes(UTF_8));
    zoo.exists(path, this);
}
Also used : IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter)

Aggregations

IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)57 KeeperException (org.apache.zookeeper.KeeperException)25 IOException (java.io.IOException)13 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 Instance (org.apache.accumulo.core.client.Instance)11 AcceptableThriftTableOperationException (org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)8 Mutator (org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator)6 HdfsZooInstance (org.apache.accumulo.server.client.HdfsZooInstance)6 AccumuloException (org.apache.accumulo.core.client.AccumuloException)5 TException (org.apache.thrift.TException)5 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)5 ArrayList (java.util.ArrayList)4 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)4 ZooReaderWriterFactory (org.apache.accumulo.server.zookeeper.ZooReaderWriterFactory)4 File (java.io.File)3 Entry (java.util.Map.Entry)3 Connector (org.apache.accumulo.core.client.Connector)3 Scanner (org.apache.accumulo.core.client.Scanner)3 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)3 Key (org.apache.accumulo.core.data.Key)3