Search in sources :

Example 11 with ZooReader

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

the class ThriftServerBindsBeforeZooKeeperLockIT method testGarbageCollectorPorts.

@Test
public void testGarbageCollectorPorts() throws Exception {
    final MiniAccumuloClusterImpl cluster = (MiniAccumuloClusterImpl) getCluster();
    final ZooKeeperInstance inst = new ZooKeeperInstance(cluster.getClientConfig());
    // Wait for the Master to grab its lock
    while (true) {
        final ZooReader reader = new ZooReader(inst.getZooKeepers(), 30000);
        try {
            List<String> locks = reader.getChildren(Constants.ZROOT + "/" + inst.getInstanceID() + Constants.ZGC_LOCK);
            if (locks.size() > 0) {
                break;
            }
        } catch (Exception e) {
            LOG.debug("Failed to find active gc location, retrying", e);
            Thread.sleep(1000);
        }
    }
    LOG.debug("Found active gc");
    while (true) {
        int freePort = PortUtils.getRandomFreePort();
        Process master = null;
        try {
            LOG.debug("Starting standby gc on {}", freePort);
            master = startProcess(cluster, ServerType.GARBAGE_COLLECTOR, freePort);
            while (true) {
                Socket s = null;
                try {
                    s = new Socket("localhost", freePort);
                    if (s.isConnected()) {
                        // Pass
                        return;
                    }
                } catch (Exception e) {
                    LOG.debug("Caught exception trying to connect to GC", e);
                } finally {
                    if (null != s) {
                        s.close();
                    }
                }
                // Wait before trying again
                Thread.sleep(1000);
                // died trying to bind it. Pick a new port and restart it in that case.
                if (!master.isAlive()) {
                    freePort = PortUtils.getRandomFreePort();
                    LOG.debug("GC died, restarting it listening on {}", freePort);
                    master = startProcess(cluster, ServerType.GARBAGE_COLLECTOR, freePort);
                }
            }
        } finally {
            if (null != master) {
                master.destroyForcibly();
            }
        }
    }
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) IOException(java.io.IOException) Socket(java.net.Socket) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) Test(org.junit.Test)

Example 12 with ZooReader

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

the class MultiTserverReplicationIT method masterReplicationServicePortsAreAdvertised.

@Test
public void masterReplicationServicePortsAreAdvertised() throws Exception {
    // Wait for the cluster to be up
    Connector conn = getConnector();
    Instance inst = conn.getInstance();
    // Wait for a tserver to come up to fulfill this request
    conn.tableOperations().create("foo");
    try (Scanner s = conn.createScanner("foo", Authorizations.EMPTY)) {
        Assert.assertEquals(0, Iterables.size(s));
        ZooReader zreader = new ZooReader(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut());
        // Should have one master instance
        Assert.assertEquals(1, inst.getMasterLocations().size());
        // Get the master thrift service addr
        String masterAddr = Iterables.getOnlyElement(inst.getMasterLocations());
        // Get the master replication coordinator addr
        String replCoordAddr = new String(zreader.getData(ZooUtil.getRoot(inst) + Constants.ZMASTER_REPLICATION_COORDINATOR_ADDR, null), UTF_8);
        // They shouldn't be the same
        Assert.assertNotEquals(masterAddr, replCoordAddr);
        // Neither should be zero as the port
        Assert.assertNotEquals(0, HostAndPort.fromString(masterAddr).getPort());
        Assert.assertNotEquals(0, HostAndPort.fromString(replCoordAddr).getPort());
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) Instance(org.apache.accumulo.core.client.Instance) Test(org.junit.Test)

Example 13 with ZooReader

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

the class ListInstances method listInstances.

static synchronized void listInstances(String keepers, boolean printAll, boolean printErrors) {
    errors = 0;
    System.out.println("INFO : Using ZooKeepers " + keepers);
    ZooReader rdr = new ZooReader(keepers, ZOOKEEPER_TIMER_MILLIS);
    ZooCache cache = new ZooCache(keepers, ZOOKEEPER_TIMER_MILLIS);
    TreeMap<String, UUID> instanceNames = getInstanceNames(rdr, printErrors);
    System.out.println();
    printHeader();
    for (Entry<String, UUID> entry : instanceNames.entrySet()) {
        printInstanceInfo(cache, entry.getKey(), entry.getValue(), printErrors);
    }
    TreeSet<UUID> instancedIds = getInstanceIDs(rdr, printErrors);
    instancedIds.removeAll(instanceNames.values());
    if (printAll) {
        for (UUID uuid : instancedIds) {
            printInstanceInfo(cache, null, uuid, printErrors);
        }
    } else if (instancedIds.size() > 0) {
        System.out.println();
        System.out.println("INFO : " + instancedIds.size() + " unamed instances were not printed, run with --print-all to see all instances");
    } else {
        System.out.println();
    }
    if (!printErrors && errors > 0) {
        System.err.println("WARN : There were " + errors + " errors, run with --print-errors to see more info");
    }
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) UUID(java.util.UUID) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 14 with ZooReader

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

the class MasterReplicationCoordinatorTest method invalidOffset.

@Test(expected = IllegalArgumentException.class)
public void invalidOffset() {
    Master master = EasyMock.createMock(Master.class);
    ZooReader reader = EasyMock.createMock(ZooReader.class);
    Instance inst = EasyMock.createMock(Instance.class);
    EasyMock.expect(master.getInstance()).andReturn(inst);
    EasyMock.expect(inst.getInstanceID()).andReturn("1234");
    EasyMock.replay(master, reader, inst);
    MasterReplicationCoordinator coordinator = new MasterReplicationCoordinator(master, reader);
    TServerInstance inst1 = new TServerInstance(HostAndPort.fromParts("host1", 1234), "session");
    Assert.assertEquals(inst1, coordinator.getRandomTServer(Collections.singleton(inst1), 1));
}
Also used : Master(org.apache.accumulo.master.Master) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) Instance(org.apache.accumulo.core.client.Instance) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) Test(org.junit.Test)

Example 15 with ZooReader

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

the class MasterReplicationCoordinatorTest method randomServerFromMany.

@Test
public void randomServerFromMany() {
    Master master = EasyMock.createMock(Master.class);
    ZooReader reader = EasyMock.createMock(ZooReader.class);
    Instance inst = EasyMock.createMock(Instance.class);
    EasyMock.expect(master.getInstance()).andReturn(inst).anyTimes();
    EasyMock.expect(inst.getInstanceID()).andReturn("1234").anyTimes();
    EasyMock.replay(master, reader, inst);
    MasterReplicationCoordinator coordinator = new MasterReplicationCoordinator(master, reader);
    EasyMock.verify(master, reader, inst);
    TreeSet<TServerInstance> instances = new TreeSet<>();
    TServerInstance inst1 = new TServerInstance(HostAndPort.fromParts("host1", 1234), "session");
    instances.add(inst1);
    TServerInstance inst2 = new TServerInstance(HostAndPort.fromParts("host2", 1234), "session");
    instances.add(inst2);
    Assert.assertEquals(inst1, coordinator.getRandomTServer(instances, 0));
    Assert.assertEquals(inst2, coordinator.getRandomTServer(instances, 1));
}
Also used : Master(org.apache.accumulo.master.Master) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) Instance(org.apache.accumulo.core.client.Instance) TreeSet(java.util.TreeSet) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) Test(org.junit.Test)

Aggregations

ZooReader (org.apache.accumulo.fate.zookeeper.ZooReader)17 Test (org.junit.Test)11 Connector (org.apache.accumulo.core.client.Connector)6 Instance (org.apache.accumulo.core.client.Instance)6 IOException (java.io.IOException)5 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)4 ZooCache (org.apache.accumulo.fate.zookeeper.ZooCache)4 File (java.io.File)3 ClusterControl (org.apache.accumulo.cluster.ClusterControl)3 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)3 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)3 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)3 Master (org.apache.accumulo.master.Master)3 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)3 Configuration (org.apache.hadoop.conf.Configuration)3 Path (org.apache.hadoop.fs.Path)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 Socket (java.net.Socket)2 ArrayList (java.util.ArrayList)2