Search in sources :

Example 51 with IZooReaderWriter

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

the class ShutdownTServer method call.

@Override
public Repo<Master> call(long tid, Master master) throws Exception {
    // suppress assignment of tablets to the server
    if (force) {
        String path = ZooUtil.getRoot(master.getInstance()) + Constants.ZTSERVERS + "/" + server.getLocation();
        ZooLock.deleteLock(path);
        path = ZooUtil.getRoot(master.getInstance()) + Constants.ZDEADTSERVERS + "/" + server.getLocation();
        IZooReaderWriter zoo = ZooReaderWriter.getInstance();
        zoo.putPersistentData(path, "forced down".getBytes(UTF_8), NodeExistsPolicy.OVERWRITE);
    }
    return null;
}
Also used : IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter)

Example 52 with IZooReaderWriter

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

the class RenameTable method call.

@Override
public Repo<Master> call(long tid, Master master) throws Exception {
    Instance instance = master.getInstance();
    Pair<String, String> qualifiedOldTableName = Tables.qualify(oldTableName);
    Pair<String, String> qualifiedNewTableName = Tables.qualify(newTableName);
    // ensure no attempt is made to rename across namespaces
    if (newTableName.contains(".") && !namespaceId.equals(Namespaces.getNamespaceId(instance, qualifiedNewTableName.getFirst())))
        throw new AcceptableThriftTableOperationException(tableId.canonicalID(), oldTableName, TableOperation.RENAME, TableOperationExceptionType.INVALID_NAME, "Namespace in new table name does not match the old table name");
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    Utils.tableNameLock.lock();
    try {
        Utils.checkTableDoesNotExist(instance, newTableName, tableId, TableOperation.RENAME);
        final String newName = qualifiedNewTableName.getSecond();
        final String oldName = qualifiedOldTableName.getSecond();
        final String tap = ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_NAME;
        zoo.mutate(tap, null, null, new Mutator() {

            @Override
            public byte[] mutate(byte[] current) throws Exception {
                final String currentName = new String(current, UTF_8);
                if (currentName.equals(newName))
                    // assume in this case the operation is running again, so we are done
                    return null;
                if (!currentName.equals(oldName)) {
                    throw new AcceptableThriftTableOperationException(null, oldTableName, TableOperation.RENAME, TableOperationExceptionType.NOTFOUND, "Name changed while processing");
                }
                return newName.getBytes(UTF_8);
            }
        });
        Tables.clearCache(instance);
    } finally {
        Utils.tableNameLock.unlock();
        Utils.unreserveTable(tableId, tid, true);
        Utils.unreserveNamespace(namespaceId, tid, false);
    }
    LoggerFactory.getLogger(RenameTable.class).debug("Renamed table {} {} {}", tableId, oldTableName, newTableName);
    return null;
}
Also used : Instance(org.apache.accumulo.core.client.Instance) Mutator(org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)

Example 53 with IZooReaderWriter

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

the class Utils method reserveTable.

public static long reserveTable(Table.ID tableId, long tid, boolean writeLock, boolean tableMustExist, TableOperation op) throws Exception {
    if (getLock(tableId, tid, writeLock).tryLock()) {
        if (tableMustExist) {
            Instance instance = HdfsZooInstance.getInstance();
            IZooReaderWriter zk = ZooReaderWriter.getInstance();
            if (!zk.exists(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId))
                throw new AcceptableThriftTableOperationException(tableId.canonicalID(), "", op, TableOperationExceptionType.NOTFOUND, "Table does not exist");
        }
        log.info("table {} ({}) locked for {} operation: {}", tableId, Long.toHexString(tid), (writeLock ? "write" : "read"), op);
        return 0;
    } else
        return 100;
}
Also used : Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)

Example 54 with IZooReaderWriter

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

the class Utils method reserveNamespace.

public static long reserveNamespace(Namespace.ID namespaceId, long id, boolean writeLock, boolean mustExist, TableOperation op) throws Exception {
    if (getLock(namespaceId, id, writeLock).tryLock()) {
        if (mustExist) {
            Instance instance = HdfsZooInstance.getInstance();
            IZooReaderWriter zk = ZooReaderWriter.getInstance();
            if (!zk.exists(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + namespaceId))
                throw new AcceptableThriftTableOperationException(namespaceId.canonicalID(), "", op, TableOperationExceptionType.NAMESPACE_NOTFOUND, "Namespace does not exist");
        }
        log.info("namespace {} ({}) locked for {} operation: {}", namespaceId, Long.toHexString(id), (writeLock ? "write" : "read"), op);
        return 0;
    } else
        return 100;
}
Also used : Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)

Example 55 with IZooReaderWriter

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

the class Utils method reserveHdfsDirectory.

public static long reserveHdfsDirectory(String directory, long tid) throws KeeperException, InterruptedException {
    Instance instance = HdfsZooInstance.getInstance();
    String resvPath = ZooUtil.getRoot(instance) + Constants.ZHDFS_RESERVATIONS + "/" + Base64.getEncoder().encodeToString(directory.getBytes(UTF_8));
    IZooReaderWriter zk = ZooReaderWriter.getInstance();
    if (ZooReservation.attempt(zk, resvPath, String.format("%016x", tid), "")) {
        return 0;
    } else
        return 50;
}
Also used : Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) 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