Search in sources :

Example 6 with ZooReaderWriter

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

the class GarbageCollectorCommunicatesWithTServersIT method getWalsForTable.

/**
 * Fetch all of the WALs referenced by tablets in the metadata table for this table
 */
private Set<String> getWalsForTable(String tableName) throws Exception {
    final Connector conn = getConnector();
    final String tableId = conn.tableOperations().tableIdMap().get(tableName);
    Assert.assertNotNull("Could not determine table ID for " + tableName, tableId);
    Instance i = conn.getInstance();
    ZooReaderWriter zk = new ZooReaderWriter(i.getZooKeepers(), i.getZooKeepersSessionTimeOut(), "");
    WalStateManager wals = new WalStateManager(conn.getInstance(), zk);
    Set<String> result = new HashSet<>();
    for (Entry<Path, WalState> entry : wals.getAllState().entrySet()) {
        log.debug("Reading WALs: {}={}", entry.getKey(), entry.getValue());
        result.add(entry.getKey().toString());
    }
    return result;
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) 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) HashSet(java.util.HashSet)

Example 7 with ZooReaderWriter

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

the class ZombieTServer method main.

public static void main(String[] args) throws Exception {
    Random random = new Random(System.currentTimeMillis() % 1000);
    int port = random.nextInt(30000) + 2000;
    Instance instance = HdfsZooInstance.getInstance();
    AccumuloServerContext context = new AccumuloServerContext(instance, new ServerConfigurationFactory(instance));
    TransactionWatcher watcher = new TransactionWatcher();
    final ThriftClientHandler tch = new ThriftClientHandler(context, watcher);
    Processor<Iface> processor = new Processor<>(tch);
    ServerAddress serverPort = TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, processor, "ZombieTServer", "walking dead", 2, 1, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", port));
    String addressString = serverPort.address.toString();
    String zPath = ZooUtil.getRoot(context.getInstance()) + Constants.ZTSERVERS + "/" + addressString;
    ZooReaderWriter zoo = ZooReaderWriter.getInstance();
    zoo.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP);
    ZooLock zlock = new ZooLock(zPath);
    LockWatcher lw = new LockWatcher() {

        @Override
        public void lostLock(final LockLossReason reason) {
            try {
                tch.halt(Tracer.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }

        @Override
        public void unableToMonitorLockNode(Throwable e) {
            try {
                tch.halt(Tracer.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }
    };
    byte[] lockContent = new ServerServices(addressString, Service.TSERV_CLIENT).toString().getBytes(UTF_8);
    if (zlock.tryLock(lw, lockContent)) {
        log.debug("Obtained tablet server lock {}", zlock.getLockPath());
    }
    // modify metadata
    synchronized (tch) {
        while (!tch.halted) {
            tch.wait();
        }
    }
    System.exit(0);
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Processor(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor) ServerServices(org.apache.accumulo.core.util.ServerServices) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) TException(org.apache.thrift.TException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) Iface(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface) TransactionWatcher(org.apache.accumulo.server.zookeeper.TransactionWatcher) Random(java.util.Random) LockWatcher(org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher) LockLossReason(org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason) ZooLock(org.apache.accumulo.server.zookeeper.ZooLock)

Example 8 with ZooReaderWriter

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

the class LogService method startLogListener.

/**
 * Place the host:port advertisement for the Monitor's Log4j listener in ZooKeeper
 *
 * @param conf
 *          configuration for the instance
 * @param instanceId
 *          instanceId for the instance
 * @param hostAddress
 *          Address that monitor process is bound to
 */
public static void startLogListener(AccumuloConfiguration conf, String instanceId, String hostAddress) {
    try {
        SocketServer server = new SocketServer(conf.getPort(Property.MONITOR_LOG4J_PORT)[0]);
        // getLocalPort will return the actual ephemeral port used when '0' was provided.
        String logForwardingAddr = hostAddress + ":" + server.getLocalPort();
        log.debug("Setting monitor log4j log-forwarding address to: {}", logForwardingAddr);
        final String path = ZooUtil.getRoot(instanceId) + Constants.ZMONITOR_LOG4J_ADDR;
        final ZooReaderWriter zoo = ZooReaderWriter.getInstance();
        // Delete before we try to re-create in case the previous session hasn't yet expired
        try {
            zoo.delete(path, -1);
        } catch (KeeperException e) {
            // We don't care if the node is already gone
            if (!KeeperException.Code.NONODE.equals(e.code())) {
                throw e;
            }
        }
        zoo.putEphemeralData(path, logForwardingAddr.getBytes(UTF_8));
        new Daemon(server).start();
    } catch (Throwable t) {
        log.info("Unable to start/advertise Log4j listener for log-forwarding to monitor", t);
    }
}
Also used : Daemon(org.apache.accumulo.core.util.Daemon) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) KeeperException(org.apache.zookeeper.KeeperException)

Example 9 with ZooReaderWriter

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

the class Monitor method fetchGcStatus.

private static GCStatus fetchGcStatus() {
    GCStatus result = null;
    HostAndPort address = null;
    try {
        // Read the gc location from its lock
        ZooReaderWriter zk = ZooReaderWriter.getInstance();
        String path = ZooUtil.getRoot(instance) + Constants.ZGC_LOCK;
        List<String> locks = zk.getChildren(path, null);
        if (locks != null && locks.size() > 0) {
            Collections.sort(locks);
            address = new ServerServices(new String(zk.getData(path + "/" + locks.get(0), null), UTF_8)).getAddress(Service.GC_CLIENT);
            GCMonitorService.Client client = ThriftUtil.getClient(new GCMonitorService.Client.Factory(), address, new AccumuloServerContext(instance, config));
            try {
                result = client.getStatus(Tracer.traceInfo(), getContext().rpcCreds());
            } finally {
                ThriftUtil.returnClient(client);
            }
        }
    } catch (Exception ex) {
        log.warn("Unable to contact the garbage collector at " + address, ex);
    }
    return result;
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) ServerServices(org.apache.accumulo.core.util.ServerServices) AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) GCStatus(org.apache.accumulo.core.gc.thrift.GCStatus) GCMonitorService(org.apache.accumulo.core.gc.thrift.GCMonitorService) MasterClient(org.apache.accumulo.core.client.impl.MasterClient) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException)

Example 10 with ZooReaderWriter

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

the class ChangeSecret method verifyAccumuloIsDown.

private static void verifyAccumuloIsDown(Instance inst, String oldPassword) throws Exception {
    ZooReader zooReader = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), oldPassword);
    String root = ZooUtil.getRoot(inst);
    final List<String> ephemerals = new ArrayList<>();
    recurse(zooReader, root, new Visitor() {

        @Override
        public void visit(ZooReader zoo, String path) throws Exception {
            Stat stat = zoo.getStatus(path);
            if (stat.getEphemeralOwner() != 0)
                ephemerals.add(path);
        }
    });
    if (ephemerals.size() > 0) {
        System.err.println("The following ephemeral nodes exist, something is still running:");
        for (String path : ephemerals) {
            System.err.println(path);
        }
        throw new Exception("Accumulo must be shut down in order to run this tool.");
    }
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) Stat(org.apache.zookeeper.data.Stat) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

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