Search in sources :

Example 1 with TStatus

use of org.apache.accumulo.fate.ReadOnlyTStore.TStatus in project accumulo by apache.

the class FateServiceHandler method waitForFateOperation.

@Override
public String waitForFateOperation(TInfo tinfo, TCredentials credentials, long opid) throws ThriftSecurityException, ThriftTableOperationException {
    authenticate(credentials);
    TStatus status = master.fate.waitForCompletion(opid);
    if (status == TStatus.FAILED) {
        Exception e = master.fate.getException(opid);
        if (e instanceof ThriftTableOperationException)
            throw (ThriftTableOperationException) e;
        else if (e instanceof ThriftSecurityException)
            throw (ThriftSecurityException) e;
        else if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException(e);
    }
    String ret = master.fate.getReturn(opid);
    if (ret == null)
        // thrift does not like returning null
        ret = "";
    return ret;
}
Also used : TStatus(org.apache.accumulo.fate.ReadOnlyTStore.TStatus) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)

Example 2 with TStatus

use of org.apache.accumulo.fate.ReadOnlyTStore.TStatus in project accumulo by apache.

the class AdminUtil method prepDelete.

public boolean prepDelete(TStore<T> zs, IZooReaderWriter zk, String path, String txidStr) {
    if (!checkGlobalLock(zk, path)) {
        return false;
    }
    long txid;
    try {
        txid = Long.parseLong(txidStr, 16);
    } catch (NumberFormatException nfe) {
        System.out.printf("Invalid transaction ID format: %s%n", txidStr);
        return false;
    }
    boolean state = false;
    zs.reserve(txid);
    TStatus ts = zs.getStatus(txid);
    switch(ts) {
        case UNKNOWN:
            System.out.printf("Invalid transaction ID: %016x%n", txid);
            break;
        case IN_PROGRESS:
        case NEW:
        case FAILED:
        case FAILED_IN_PROGRESS:
        case SUCCESSFUL:
            System.out.printf("Deleting transaction: %016x (%s)%n", txid, ts);
            zs.delete(txid);
            state = true;
            break;
    }
    zs.unreserve(txid, 0);
    return state;
}
Also used : TStatus(org.apache.accumulo.fate.ReadOnlyTStore.TStatus)

Example 3 with TStatus

use of org.apache.accumulo.fate.ReadOnlyTStore.TStatus in project accumulo by apache.

the class AdminUtil method prepFail.

public boolean prepFail(TStore<T> zs, IZooReaderWriter zk, String path, String txidStr) {
    if (!checkGlobalLock(zk, path)) {
        return false;
    }
    long txid;
    try {
        txid = Long.parseLong(txidStr, 16);
    } catch (NumberFormatException nfe) {
        System.out.printf("Invalid transaction ID format: %s%n", txidStr);
        return false;
    }
    boolean state = false;
    zs.reserve(txid);
    TStatus ts = zs.getStatus(txid);
    switch(ts) {
        case UNKNOWN:
            System.out.printf("Invalid transaction ID: %016x%n", txid);
            break;
        case IN_PROGRESS:
        case NEW:
            System.out.printf("Failing transaction: %016x (%s)%n", txid, ts);
            zs.setStatus(txid, TStatus.FAILED_IN_PROGRESS);
            state = true;
            break;
        case SUCCESSFUL:
            System.out.printf("Transaction already completed: %016x (%s)%n", txid, ts);
            break;
        case FAILED:
        case FAILED_IN_PROGRESS:
            System.out.printf("Transaction already failed: %016x (%s)%n", txid, ts);
            state = true;
            break;
    }
    zs.unreserve(txid, 0);
    return state;
}
Also used : TStatus(org.apache.accumulo.fate.ReadOnlyTStore.TStatus)

Example 4 with TStatus

use of org.apache.accumulo.fate.ReadOnlyTStore.TStatus in project accumulo by apache.

the class AdminUtil method getStatus.

public FateStatus getStatus(ReadOnlyTStore<T> zs, IZooReader zk, String lockPath, Set<Long> filterTxid, EnumSet<TStatus> filterStatus) throws KeeperException, InterruptedException {
    Map<Long, List<String>> heldLocks = new HashMap<>();
    Map<Long, List<String>> waitingLocks = new HashMap<>();
    List<String> lockedIds = zk.getChildren(lockPath);
    for (String id : lockedIds) {
        try {
            List<String> lockNodes = zk.getChildren(lockPath + "/" + id);
            lockNodes = new ArrayList<>(lockNodes);
            Collections.sort(lockNodes);
            int pos = 0;
            boolean sawWriteLock = false;
            for (String node : lockNodes) {
                try {
                    byte[] data = zk.getData(lockPath + "/" + id + "/" + node, null);
                    String[] lda = new String(data, UTF_8).split(":");
                    if (lda[0].charAt(0) == 'W')
                        sawWriteLock = true;
                    Map<Long, List<String>> locks;
                    if (pos == 0) {
                        locks = heldLocks;
                    } else {
                        if (lda[0].charAt(0) == 'R' && !sawWriteLock) {
                            locks = heldLocks;
                        } else {
                            locks = waitingLocks;
                        }
                    }
                    List<String> tables = locks.get(Long.parseLong(lda[1], 16));
                    if (tables == null) {
                        tables = new ArrayList<>();
                        locks.put(Long.parseLong(lda[1], 16), tables);
                    }
                    tables.add(lda[0].charAt(0) + ":" + id);
                } catch (Exception e) {
                    log.error("{}", e.getMessage(), e);
                }
                pos++;
            }
        } catch (Exception e) {
            log.error("Failed to read locks for " + id + " continuing.", e);
        }
    }
    List<Long> transactions = zs.list();
    List<TransactionStatus> statuses = new ArrayList<>(transactions.size());
    for (Long tid : transactions) {
        zs.reserve(tid);
        String debug = (String) zs.getProperty(tid, "debug");
        List<String> hlocks = heldLocks.remove(tid);
        if (hlocks == null)
            hlocks = Collections.emptyList();
        List<String> wlocks = waitingLocks.remove(tid);
        if (wlocks == null)
            wlocks = Collections.emptyList();
        String top = null;
        ReadOnlyRepo<T> repo = zs.top(tid);
        if (repo != null)
            top = repo.getDescription();
        TStatus status = null;
        status = zs.getStatus(tid);
        zs.unreserve(tid, 0);
        if ((filterTxid != null && !filterTxid.contains(tid)) || (filterStatus != null && !filterStatus.contains(status)))
            continue;
        statuses.add(new TransactionStatus(tid, status, debug, hlocks, wlocks, top));
    }
    return new FateStatus(statuses, heldLocks, waitingLocks);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KeeperException(org.apache.zookeeper.KeeperException) TStatus(org.apache.accumulo.fate.ReadOnlyTStore.TStatus) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with TStatus

use of org.apache.accumulo.fate.ReadOnlyTStore.TStatus 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)

Aggregations

TStatus (org.apache.accumulo.fate.ReadOnlyTStore.TStatus)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Formatter (java.util.Formatter)1 HashMap (java.util.HashMap)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Instance (org.apache.accumulo.core.client.Instance)1 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)1 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)1 AdminUtil (org.apache.accumulo.fate.AdminUtil)1 ReadOnlyRepo (org.apache.accumulo.fate.ReadOnlyRepo)1 ZooStore (org.apache.accumulo.fate.ZooStore)1 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)1 ParseException (org.apache.commons.cli.ParseException)1 KeeperException (org.apache.zookeeper.KeeperException)1