Search in sources :

Example 16 with ZooReaderWriter

use of org.apache.accumulo.server.zookeeper.ZooReaderWriter in project accumulo by apache.

the class UnusedWALIT method test.

@Test(timeout = 2 * 60 * 1000)
public void test() throws Exception {
    // don't want this bad boy cleaning up walog entries
    getCluster().getClusterControl().stop(ServerType.GARBAGE_COLLECTOR);
    // make two tables
    String[] tableNames = getUniqueNames(2);
    String bigTable = tableNames[0];
    String lilTable = tableNames[1];
    Connector c = getConnector();
    c.tableOperations().create(bigTable);
    c.tableOperations().create(lilTable);
    Instance i = c.getInstance();
    zk = new ZooReaderWriter(i.getZooKeepers(), i.getZooKeepersSessionTimeOut(), "");
    // put some data in a log that should be replayed for both tables
    writeSomeData(c, bigTable, 0, 10, 0, 10);
    scanSomeData(c, bigTable, 0, 10, 0, 10);
    writeSomeData(c, lilTable, 0, 1, 0, 1);
    scanSomeData(c, lilTable, 0, 1, 0, 1);
    assertEquals(2, getWALCount(i, zk));
    // roll the logs by pushing data into bigTable
    writeSomeData(c, bigTable, 0, 3000, 0, 1000);
    assertEquals(3, getWALCount(i, zk));
    // put some data in the latest log
    writeSomeData(c, lilTable, 1, 10, 0, 10);
    scanSomeData(c, lilTable, 1, 10, 0, 10);
    // bounce the tserver
    getCluster().getClusterControl().stop(ServerType.TABLET_SERVER);
    getCluster().getClusterControl().start(ServerType.TABLET_SERVER);
    // wait for the metadata table to be online
    Iterators.size(c.createScanner(MetadataTable.NAME, Authorizations.EMPTY).iterator());
    // check our two sets of data in different logs
    scanSomeData(c, lilTable, 0, 1, 0, 1);
    scanSomeData(c, lilTable, 1, 10, 0, 10);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Instance(org.apache.accumulo.core.client.Instance) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) Test(org.junit.Test)

Example 17 with ZooReaderWriter

use of org.apache.accumulo.server.zookeeper.ZooReaderWriter in project accumulo by apache.

the class ZKPermHandler method hasNamespacePermission.

@Override
public boolean hasNamespacePermission(String user, Namespace.ID namespace, NamespacePermission permission) throws NamespaceNotFoundException {
    byte[] serializedPerms;
    final ZooReaderWriter zrw = ZooReaderWriter.getInstance();
    try {
        String path = ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace;
        zrw.sync(path);
        serializedPerms = zrw.getData(path, null);
    } catch (KeeperException e) {
        if (e.code() == Code.NONODE) {
            // maybe the namespace was just deleted?
            try {
                // check for existence:
                zrw.getData(ZKNamespacePath + "/" + namespace, null);
                // it's there, you don't have permission
                return false;
            } catch (InterruptedException ex) {
                log.warn("Unhandled InterruptedException, failing closed for namespace permission check", e);
                return false;
            } catch (KeeperException ex) {
                // not there, throw an informative exception
                if (e.code() == Code.NONODE) {
                    throw new NamespaceNotFoundException(namespace.canonicalID(), null, "while checking permissions");
                }
                log.warn("Unhandled InterruptedException, failing closed for table permission check", e);
            }
            return false;
        }
        log.warn("Unhandled KeeperException, failing closed for table permission check", e);
        return false;
    } catch (InterruptedException e) {
        log.warn("Unhandled InterruptedException, failing closed for table permission check", e);
        return false;
    }
    if (serializedPerms != null) {
        return ZKSecurityTool.convertNamespacePermissions(serializedPerms).contains(permission);
    }
    return false;
}
Also used : ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) KeeperException(org.apache.zookeeper.KeeperException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 18 with ZooReaderWriter

use of org.apache.accumulo.server.zookeeper.ZooReaderWriter in project accumulo by apache.

the class ZKPermHandler method hasTablePermission.

@Override
public boolean hasTablePermission(String user, String table, TablePermission permission) throws TableNotFoundException {
    byte[] serializedPerms;
    final ZooReaderWriter zrw = ZooReaderWriter.getInstance();
    try {
        String path = ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table;
        zrw.sync(path);
        serializedPerms = zrw.getData(path, null);
    } catch (KeeperException e) {
        if (e.code() == Code.NONODE) {
            // maybe the table was just deleted?
            try {
                // check for existence:
                zrw.getData(ZKTablePath + "/" + table, null);
                // it's there, you don't have permission
                return false;
            } catch (InterruptedException ex) {
                log.warn("Unhandled InterruptedException, failing closed for table permission check", e);
                return false;
            } catch (KeeperException ex) {
                // not there, throw an informative exception
                if (e.code() == Code.NONODE) {
                    throw new TableNotFoundException(null, table, "while checking permissions");
                }
                log.warn("Unhandled InterruptedException, failing closed for table permission check", e);
            }
            return false;
        }
        log.warn("Unhandled KeeperException, failing closed for table permission check", e);
        return false;
    } catch (InterruptedException e) {
        log.warn("Unhandled InterruptedException, failing closed for table permission check", e);
        return false;
    }
    if (serializedPerms != null) {
        return ZKSecurityTool.convertTablePermissions(serializedPerms).contains(permission);
    }
    return false;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) KeeperException(org.apache.zookeeper.KeeperException)

Example 19 with ZooReaderWriter

use of org.apache.accumulo.server.zookeeper.ZooReaderWriter in project accumulo by apache.

the class Monitor method getMonitorLock.

/**
 * Get the monitor lock in ZooKeeper
 */
private void getMonitorLock() throws KeeperException, InterruptedException {
    final String zRoot = ZooUtil.getRoot(instance);
    final String monitorPath = zRoot + Constants.ZMONITOR;
    final String monitorLockPath = zRoot + Constants.ZMONITOR_LOCK;
    // Ensure that everything is kosher with ZK as this has changed.
    ZooReaderWriter zoo = ZooReaderWriter.getInstance();
    if (zoo.exists(monitorPath)) {
        byte[] data = zoo.getData(monitorPath, null);
        // If the node isn't empty, it's from a previous install (has hostname:port for HTTP server)
        if (0 != data.length) {
            // Recursively delete from that parent node
            zoo.recursiveDelete(monitorPath, NodeMissingPolicy.SKIP);
            // And then make the nodes that we expect for the incoming ephemeral nodes
            zoo.putPersistentData(monitorPath, new byte[0], NodeExistsPolicy.FAIL);
            zoo.putPersistentData(monitorLockPath, new byte[0], NodeExistsPolicy.FAIL);
        } else if (!zoo.exists(monitorLockPath)) {
            // monitor node in ZK exists and is empty as we expect
            // but the monitor/lock node does not
            zoo.putPersistentData(monitorLockPath, new byte[0], NodeExistsPolicy.FAIL);
        }
    } else {
        // 1.5.0 and earlier
        zoo.putPersistentData(zRoot + Constants.ZMONITOR, new byte[0], NodeExistsPolicy.FAIL);
        if (!zoo.exists(monitorLockPath)) {
            // Somehow the monitor node exists but not monitor/lock
            zoo.putPersistentData(monitorLockPath, new byte[0], NodeExistsPolicy.FAIL);
        }
    }
    // Get a ZooLock for the monitor
    while (true) {
        MoniterLockWatcher monitorLockWatcher = new MoniterLockWatcher();
        monitorLock = new ZooLock(monitorLockPath);
        monitorLock.lockAsync(monitorLockWatcher, new byte[0]);
        monitorLockWatcher.waitForChange();
        if (monitorLockWatcher.acquiredLock) {
            break;
        }
        if (!monitorLockWatcher.failedToAcquireLock) {
            throw new IllegalStateException("monitor lock in unknown state");
        }
        monitorLock.tryToCancelAsyncLockOrUnlock();
        sleepUninterruptibly(getContext().getConfiguration().getTimeInMillis(Property.MONITOR_LOCK_CHECK_INTERVAL), TimeUnit.MILLISECONDS);
    }
    log.info("Got Monitor lock.");
}
Also used : ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) ZooLock(org.apache.accumulo.server.zookeeper.ZooLock)

Example 20 with ZooReaderWriter

use of org.apache.accumulo.server.zookeeper.ZooReaderWriter in project accumulo by apache.

the class WALSunnyDayIT method _getWals.

private Map<String, Boolean> _getWals(Connector c) throws Exception {
    Map<String, Boolean> result = new HashMap<>();
    Instance i = c.getInstance();
    ZooReaderWriter zk = new ZooReaderWriter(i.getZooKeepers(), i.getZooKeepersSessionTimeOut(), "");
    WalStateManager wals = new WalStateManager(c.getInstance(), zk);
    for (Entry<Path, WalState> entry : wals.getAllState().entrySet()) {
        // WALs are in use if they are not unreferenced
        result.put(entry.getKey().toString(), entry.getValue() != WalState.UNREFERENCED);
    }
    return result;
}
Also used : Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) Instance(org.apache.accumulo.core.client.Instance) WalStateManager(org.apache.accumulo.server.log.WalStateManager) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) WalState(org.apache.accumulo.server.log.WalStateManager.WalState)

Aggregations

ZooReaderWriter (org.apache.accumulo.server.zookeeper.ZooReaderWriter)20 Instance (org.apache.accumulo.core.client.Instance)8 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)6 Connector (org.apache.accumulo.core.client.Connector)5 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)5 WalStateManager (org.apache.accumulo.server.log.WalStateManager)5 WalState (org.apache.accumulo.server.log.WalStateManager.WalState)5 Path (org.apache.hadoop.fs.Path)5 KeeperException (org.apache.zookeeper.KeeperException)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 Scanner (org.apache.accumulo.core.client.Scanner)3 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)3 HashSet (java.util.HashSet)2 List (java.util.List)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 Key (org.apache.accumulo.core.data.Key)2 Value (org.apache.accumulo.core.data.Value)2 ServerServices (org.apache.accumulo.core.util.ServerServices)2