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();
}
}
}
}
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());
}
}
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");
}
}
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));
}
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));
}
Aggregations