Search in sources :

Example 1 with ZooStore

use of org.apache.accumulo.fate.ZooStore in project accumulo by apache.

the class TableChangeStateIT method findFate.

/**
 * Checks fates in zookeeper looking for transaction associated with a compaction as a double check that the test will be valid because the running compaction
 * does have a fate transaction lock.
 *
 * @return true if corresponding fate transaction found, false otherwise
 */
private boolean findFate(final String tableName) {
    Instance instance = connector.getInstance();
    AdminUtil<String> admin = new AdminUtil<>(false);
    try {
        Table.ID tableId = Tables.getTableId(instance, tableName);
        log.trace("tid: {}", tableId);
        String secret = cluster.getSiteConfiguration().get(Property.INSTANCE_SECRET);
        IZooReaderWriter zk = new ZooReaderWriterFactory().getZooReaderWriter(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut(), secret);
        ZooStore<String> zs = new ZooStore<>(ZooUtil.getRoot(instance) + Constants.ZFATE, zk);
        AdminUtil.FateStatus fateStatus = admin.getStatus(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS + "/" + tableId, null, null);
        for (AdminUtil.TransactionStatus tx : fateStatus.getTransactions()) {
            if (tx.getTop().contains("CompactionDriver") && tx.getDebug().contains("CompactRange")) {
                return true;
            }
        }
    } catch (KeeperException | TableNotFoundException | InterruptedException ex) {
        throw new IllegalStateException(ex);
    }
    // did not find appropriate fate transaction for compaction.
    return Boolean.FALSE;
}
Also used : Table(org.apache.accumulo.core.client.impl.Table) Instance(org.apache.accumulo.core.client.Instance) ZooStore(org.apache.accumulo.fate.ZooStore) ZooReaderWriterFactory(org.apache.accumulo.server.zookeeper.ZooReaderWriterFactory) AdminUtil(org.apache.accumulo.fate.AdminUtil) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with ZooStore

use of org.apache.accumulo.fate.ZooStore in project accumulo by apache.

the class FateCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws ParseException, KeeperException, InterruptedException, IOException {
    Instance instance = shellState.getInstance();
    String[] args = cl.getArgs();
    if (args.length <= 0) {
        throw new ParseException("Must provide a command to execute");
    }
    String cmd = args[0];
    boolean failedCommand = false;
    AdminUtil<FateCommand> admin = new AdminUtil<>(false);
    String path = ZooUtil.getRoot(instance) + Constants.ZFATE;
    String masterPath = ZooUtil.getRoot(instance) + Constants.ZMASTER_LOCK;
    IZooReaderWriter zk = getZooReaderWriter(shellState.getInstance(), cl.getOptionValue(secretOption.getOpt()));
    ZooStore<FateCommand> zs = new ZooStore<>(path, zk);
    if ("fail".equals(cmd)) {
        if (args.length <= 1) {
            throw new ParseException("Must provide transaction ID");
        }
        for (int i = 1; i < args.length; i++) {
            if (!admin.prepFail(zs, zk, masterPath, args[i])) {
                System.out.printf("Could not fail transaction: %s%n", args[i]);
                failedCommand = true;
            }
        }
    } else if ("delete".equals(cmd)) {
        if (args.length <= 1) {
            throw new ParseException("Must provide transaction ID");
        }
        for (int i = 1; i < args.length; i++) {
            if (admin.prepDelete(zs, zk, masterPath, args[i])) {
                admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, args[i]);
            } else {
                System.out.printf("Could not delete transaction: %s%n", args[i]);
                failedCommand = true;
            }
        }
    } else if ("list".equals(cmd) || "print".equals(cmd)) {
        // Parse transaction ID filters for print display
        Set<Long> filterTxid = null;
        if (args.length >= 2) {
            filterTxid = new HashSet<>(args.length);
            for (int i = 1; i < args.length; i++) {
                try {
                    Long val = Long.parseLong(args[i], 16);
                    filterTxid.add(val);
                } catch (NumberFormatException nfe) {
                    // Failed to parse, will exit instead of displaying everything since the intention was to potentially filter some data
                    System.out.printf("Invalid transaction ID format: %s%n", args[i]);
                    return 1;
                }
            }
        }
        // Parse TStatus filters for print display
        EnumSet<TStatus> filterStatus = null;
        if (cl.hasOption(statusOption.getOpt())) {
            filterStatus = EnumSet.noneOf(TStatus.class);
            String[] tstat = cl.getOptionValues(statusOption.getOpt());
            for (int i = 0; i < tstat.length; i++) {
                try {
                    filterStatus.add(TStatus.valueOf(tstat[i]));
                } catch (IllegalArgumentException iae) {
                    System.out.printf("Invalid transaction status name: %s%n", tstat[i]);
                    return 1;
                }
            }
        }
        StringBuilder buf = new StringBuilder(8096);
        Formatter fmt = new Formatter(buf);
        admin.print(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, fmt, filterTxid, filterStatus);
        shellState.printLines(Collections.singletonList(buf.toString()).iterator(), !cl.hasOption(disablePaginationOpt.getOpt()));
    } else if ("dump".equals(cmd)) {
        List<Long> txids;
        if (args.length == 1) {
            txids = zs.list();
        } else {
            txids = new ArrayList<>();
            for (int i = 1; i < args.length; i++) {
                txids.add(Long.parseLong(args[i], 16));
            }
        }
        Gson gson = new GsonBuilder().registerTypeAdapter(ReadOnlyRepo.class, new InterfaceSerializer<>()).registerTypeAdapter(Repo.class, new InterfaceSerializer<>()).registerTypeAdapter(byte[].class, new ByteArraySerializer()).setPrettyPrinting().create();
        List<FateStack> txStacks = new ArrayList<>();
        for (Long txid : txids) {
            List<ReadOnlyRepo<FateCommand>> repoStack = zs.getStack(txid);
            txStacks.add(new FateStack(txid, repoStack));
        }
        System.out.println(gson.toJson(txStacks));
    } else {
        throw new ParseException("Invalid command option");
    }
    return failedCommand ? 1 : 0;
}
Also used : Instance(org.apache.accumulo.core.client.Instance) Formatter(java.util.Formatter) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) AdminUtil(org.apache.accumulo.fate.AdminUtil) TStatus(org.apache.accumulo.fate.ReadOnlyTStore.TStatus) ArrayList(java.util.ArrayList) List(java.util.List) ReadOnlyRepo(org.apache.accumulo.fate.ReadOnlyRepo) GsonBuilder(com.google.gson.GsonBuilder) ZooStore(org.apache.accumulo.fate.ZooStore) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) ParseException(org.apache.commons.cli.ParseException)

Example 3 with ZooStore

use of org.apache.accumulo.fate.ZooStore 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 4 with ZooStore

use of org.apache.accumulo.fate.ZooStore in project accumulo by apache.

the class FunctionalTestUtils method getFateStatus.

private static FateStatus getFateStatus(Instance instance, AccumuloCluster cluster) {
    try {
        AdminUtil<String> admin = new AdminUtil<>(false);
        String secret = cluster.getSiteConfiguration().get(Property.INSTANCE_SECRET);
        IZooReaderWriter zk = new ZooReaderWriterFactory().getZooReaderWriter(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut(), secret);
        ZooStore<String> zs = new ZooStore<>(ZooUtil.getRoot(instance) + Constants.ZFATE, zk);
        FateStatus fateStatus = admin.getStatus(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, null, null);
        return fateStatus;
    } catch (KeeperException | InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : AdminUtil(org.apache.accumulo.fate.AdminUtil) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) ZooStore(org.apache.accumulo.fate.ZooStore) ZooReaderWriterFactory(org.apache.accumulo.server.zookeeper.ZooReaderWriterFactory) FateStatus(org.apache.accumulo.fate.AdminUtil.FateStatus) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

AdminUtil (org.apache.accumulo.fate.AdminUtil)4 ZooStore (org.apache.accumulo.fate.ZooStore)4 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)4 Instance (org.apache.accumulo.core.client.Instance)3 ZooReaderWriterFactory (org.apache.accumulo.server.zookeeper.ZooReaderWriterFactory)2 KeeperException (org.apache.zookeeper.KeeperException)2 JCommander (com.beust.jcommander.JCommander)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ArrayList (java.util.ArrayList)1 Formatter (java.util.Formatter)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Help (org.apache.accumulo.core.cli.Help)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 Table (org.apache.accumulo.core.client.impl.Table)1 FateStatus (org.apache.accumulo.fate.AdminUtil.FateStatus)1 ReadOnlyRepo (org.apache.accumulo.fate.ReadOnlyRepo)1 TStatus (org.apache.accumulo.fate.ReadOnlyTStore.TStatus)1 Master (org.apache.accumulo.master.Master)1