Search in sources :

Example 36 with IZooReaderWriter

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

the class MasterClientServiceHandler method initiateFlush.

@Override
public long initiateFlush(TInfo tinfo, TCredentials c, String tableIdStr) throws ThriftSecurityException, ThriftTableOperationException {
    Table.ID tableId = Table.ID.of(tableIdStr);
    Namespace.ID namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
    master.security.canFlush(c, tableId, namespaceId);
    String zTablePath = Constants.ZROOT + "/" + master.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_FLUSH_ID;
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    byte[] fid;
    try {
        fid = zoo.mutate(zTablePath, null, null, new Mutator() {

            @Override
            public byte[] mutate(byte[] currentValue) throws Exception {
                long flushID = Long.parseLong(new String(currentValue));
                flushID++;
                return ("" + flushID).getBytes();
            }
        });
    } catch (NoNodeException nne) {
        throw new ThriftTableOperationException(tableId.canonicalID(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
    } catch (Exception e) {
        Master.log.warn("{}", e.getMessage(), e);
        throw new ThriftTableOperationException(tableId.canonicalID(), null, TableOperation.FLUSH, TableOperationExceptionType.OTHER, null);
    }
    return Long.parseLong(new String(fid));
}
Also used : MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Mutator(org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) Namespace(org.apache.accumulo.core.client.impl.Namespace) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TabletDeletedException(org.apache.accumulo.server.util.TabletIterator.TabletDeletedException) KeeperException(org.apache.zookeeper.KeeperException) TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)

Example 37 with IZooReaderWriter

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

the class CancelCompactions method call.

@Override
public Repo<Master> call(long tid, Master environment) throws Exception {
    String zCompactID = Constants.ZROOT + "/" + environment.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
    String zCancelID = Constants.ZROOT + "/" + environment.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_CANCEL_ID;
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    byte[] currentValue = zoo.getData(zCompactID, null);
    String cvs = new String(currentValue, UTF_8);
    String[] tokens = cvs.split(",");
    final long flushID = Long.parseLong(tokens[0]);
    zoo.mutate(zCancelID, null, null, new Mutator() {

        @Override
        public byte[] mutate(byte[] currentValue) throws Exception {
            long cid = Long.parseLong(new String(currentValue, UTF_8));
            if (cid < flushID)
                return Long.toString(flushID).getBytes(UTF_8);
            else
                return Long.toString(cid).getBytes(UTF_8);
        }
    });
    return new FinishCancelCompaction(namespaceId, tableId);
}
Also used : Mutator(org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter)

Example 38 with IZooReaderWriter

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

the class DatafileManager method bringMajorCompactionOnline.

void bringMajorCompactionOnline(Set<FileRef> oldDatafiles, FileRef tmpDatafile, FileRef newDatafile, Long compactionId, DataFileValue dfv) throws IOException {
    final KeyExtent extent = tablet.getExtent();
    long t1, t2;
    if (!extent.isRootTablet()) {
        if (tablet.getTabletServer().getFileSystem().exists(newDatafile.path())) {
            log.error("Target map file already exist " + newDatafile, new Exception());
            throw new IllegalStateException("Target map file already exist " + newDatafile);
        }
        // rename before putting in metadata table, so files in metadata table should
        // always exist
        rename(tablet.getTabletServer().getFileSystem(), tmpDatafile.path(), newDatafile.path());
        if (dfv.getNumEntries() == 0) {
            tablet.getTabletServer().getFileSystem().deleteRecursively(newDatafile.path());
        }
    }
    TServerInstance lastLocation = null;
    synchronized (tablet) {
        t1 = System.currentTimeMillis();
        IZooReaderWriter zoo = ZooReaderWriter.getInstance();
        tablet.incrementDataSourceDeletions();
        if (extent.isRootTablet()) {
            waitForScansToFinish(oldDatafiles, true, Long.MAX_VALUE);
            try {
                if (!zoo.isLockHeld(tablet.getTabletServer().getLock().getLockID())) {
                    throw new IllegalStateException();
                }
            } catch (Exception e) {
                throw new IllegalStateException("Can not bring major compaction online, lock not held", e);
            }
            // mark files as ready for deletion, but
            // do not delete them until we successfully
            // rename the compacted map file, in case
            // the system goes down
            RootFiles.replaceFiles(tablet.getTableConfiguration(), tablet.getTabletServer().getFileSystem(), tablet.getLocation(), oldDatafiles, tmpDatafile, newDatafile);
        }
        // atomically remove old files and add new file
        for (FileRef oldDatafile : oldDatafiles) {
            if (!datafileSizes.containsKey(oldDatafile)) {
                log.error("file does not exist in set {}", oldDatafile);
            }
            datafileSizes.remove(oldDatafile);
            majorCompactingFiles.remove(oldDatafile);
        }
        if (datafileSizes.containsKey(newDatafile)) {
            log.error("Adding file that is already in set {}", newDatafile);
        }
        if (dfv.getNumEntries() > 0) {
            datafileSizes.put(newDatafile, dfv);
        }
        // could be used by a follow on compaction in a multipass compaction
        majorCompactingFiles.add(newDatafile);
        tablet.computeNumEntries();
        lastLocation = tablet.resetLastLocation();
        tablet.setLastCompactionID(compactionId);
        t2 = System.currentTimeMillis();
    }
    if (!extent.isRootTablet()) {
        Set<FileRef> filesInUseByScans = waitForScansToFinish(oldDatafiles, false, 10000);
        if (filesInUseByScans.size() > 0)
            log.debug("Adding scan refs to metadata {} {}", extent, filesInUseByScans);
        MasterMetadataUtil.replaceDatafiles(tablet.getTabletServer(), extent, oldDatafiles, filesInUseByScans, newDatafile, compactionId, dfv, tablet.getTabletServer().getClientAddressString(), lastLocation, tablet.getTabletServer().getLock());
        removeFilesAfterScan(filesInUseByScans);
    }
    log.debug(String.format("MajC finish lock %.2f secs", (t2 - t1) / 1000.0));
    log.debug("TABLET_HIST {} MajC  --> {}", oldDatafiles, newDatafile);
}
Also used : FileRef(org.apache.accumulo.server.fs.FileRef) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) IOException(java.io.IOException) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance)

Example 39 with IZooReaderWriter

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

Example 40 with IZooReaderWriter

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

the class CacheTestClean method main.

public static void main(String[] args) throws Exception {
    String rootDir = args[0];
    File reportDir = new File(args[1]);
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    if (zoo.exists(rootDir)) {
        zoo.recursiveDelete(rootDir, NodeMissingPolicy.FAIL);
    }
    FileUtils.deleteQuietly(reportDir);
    if (!reportDir.mkdirs()) {
        throw new IOException("Unable to (re-)create " + reportDir);
    }
}
Also used : IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) IOException(java.io.IOException) File(java.io.File)

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