use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory in project accumulo by apache.
the class InstanceOperationsImpl method getTabletServers.
@Override
public List<String> getTabletServers() {
Instance instance = context.getInstance();
ZooCache cache = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
List<String> results = new ArrayList<>();
for (String candidate : cache.getChildren(path)) {
List<String> children = cache.getChildren(path + "/" + candidate);
if (children != null && children.size() > 0) {
List<String> copy = new ArrayList<>(children);
Collections.sort(copy);
byte[] data = cache.get(path + "/" + candidate + "/" + copy.get(0));
if (data != null && !"master".equals(new String(data, UTF_8))) {
results.add(candidate);
}
}
}
return results;
}
use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory in project accumulo by apache.
the class TransportCachingIT method testCachedTransport.
@Test
public void testCachedTransport() {
Connector conn = getConnector();
Instance instance = conn.getInstance();
ClientConfiguration clientConf = cluster.getClientConfig();
ClientContext context = new ClientContext(instance, new Credentials(getAdminPrincipal(), getAdminToken()), clientConf);
long rpcTimeout = ConfigurationTypeHelper.getTimeInMillis(Property.GENERAL_RPC_TIMEOUT.getDefaultValue());
// create list of servers
ArrayList<ThriftTransportKey> servers = new ArrayList<>();
// add tservers
ZooCache zc = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
for (String tserver : zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZTSERVERS)) {
String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS + "/" + tserver;
byte[] data = ZooUtil.getLockData(zc, path);
if (data != null) {
String strData = new String(data, UTF_8);
if (!strData.equals("master"))
servers.add(new ThriftTransportKey(new ServerServices(strData).getAddress(Service.TSERV_CLIENT), rpcTimeout, context));
}
}
ThriftTransportPool pool = ThriftTransportPool.getInstance();
TTransport first = null;
while (null == first) {
try {
// Get a transport (cached or not)
first = pool.getAnyTransport(servers, true).getSecond();
} catch (TTransportException e) {
log.warn("Failed to obtain transport to {}", servers);
}
}
assertNotNull(first);
// Return it to unreserve it
pool.returnTransport(first);
TTransport second = null;
while (null == second) {
try {
// Get a cached transport (should be the first)
second = pool.getAnyTransport(servers, true).getSecond();
} catch (TTransportException e) {
log.warn("Failed obtain 2nd transport to {}", servers);
}
}
// We should get the same transport
assertTrue("Expected the first and second to be the same instance", first == second);
// Return the 2nd
pool.returnTransport(second);
TTransport third = null;
while (null == third) {
try {
// Get a non-cached transport
third = pool.getAnyTransport(servers, false).getSecond();
} catch (TTransportException e) {
log.warn("Failed obtain 2nd transport to {}", servers);
}
}
assertFalse("Expected second and third transport to be different instances", second == third);
pool.returnTransport(third);
}
use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory in project accumulo by apache.
the class ReplicationIT method waitForGCLock.
private void waitForGCLock(Connector conn) throws InterruptedException {
// Check if the GC process has the lock before wasting our retry attempts
ZooKeeperInstance zki = (ZooKeeperInstance) conn.getInstance();
ZooCacheFactory zcf = new ZooCacheFactory();
ZooCache zcache = zcf.getZooCache(zki.getZooKeepers(), zki.getZooKeepersSessionTimeOut());
String zkPath = ZooUtil.getRoot(conn.getInstance()) + Constants.ZGC_LOCK;
log.info("Looking for GC lock at {}", zkPath);
byte[] data = ZooLock.getLockData(zcache, zkPath, null);
while (null == data) {
log.info("Waiting for GC ZooKeeper lock to be acquired");
Thread.sleep(1000);
data = ZooLock.getLockData(zcache, zkPath, null);
}
}
use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory in project accumulo by apache.
the class ZooKeeperInstanceTest method testAllZooKeepersAreUsed.
@Test
public void testAllZooKeepersAreUsed() {
final String zookeepers = "zk1,zk2,zk3", instanceName = "accumulo";
ZooCacheFactory factory = createMock(ZooCacheFactory.class);
EasyMock.reset(zc);
expect(factory.getZooCache(zookeepers, 30000)).andReturn(zc).anyTimes();
expect(zc.get(Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName)).andReturn(IID_STRING.getBytes(UTF_8));
expect(zc.get(Constants.ZROOT + "/" + IID_STRING)).andReturn("yup".getBytes());
replay(zc, factory);
ClientConfiguration cfg = ClientConfiguration.loadDefault().withInstance(instanceName).withZkHosts(zookeepers);
ZooKeeperInstance zki = new ZooKeeperInstance(cfg, factory);
assertEquals(zookeepers, zki.getZooKeepers());
assertEquals(instanceName, zki.getInstanceName());
}
use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory in project accumulo by apache.
the class Admin method stopTabletServer.
private static void stopTabletServer(final ClientContext context, List<String> servers, final boolean force) throws AccumuloException, AccumuloSecurityException {
if (context.getInstance().getMasterLocations().size() == 0) {
log.info("No masters running. Not attempting safe unload of tserver.");
return;
}
final Instance instance = context.getInstance();
final String zTServerRoot = getTServersZkPath(instance);
final ZooCache zc = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
for (String server : servers) {
for (int port : context.getConfiguration().getPort(Property.TSERV_CLIENTPORT)) {
HostAndPort address = AddressUtil.parseAddress(server, port);
final String finalServer = qualifyWithZooKeeperSessionId(zTServerRoot, zc, address.toString());
log.info("Stopping server {}", finalServer);
MasterClient.executeVoid(context, new ClientExec<MasterClientService.Client>() {
@Override
public void execute(MasterClientService.Client client) throws Exception {
client.shutdownTabletServer(Tracer.traceInfo(), context.rpcCreds(), finalServer, force);
}
});
}
}
}
Aggregations