use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class CacheTestReader method main.
public static void main(String[] args) throws Exception {
String rootDir = args[0];
String reportDir = args[1];
String keepers = args[2];
int numData = CacheTestWriter.NUM_DATA;
File myfile = new File(reportDir + "/" + UUID.randomUUID());
myfile.deleteOnExit();
ZooCache zc = new ZooCache(keepers, 30000);
while (true) {
if (myfile.exists() && !myfile.delete()) {
LoggerFactory.getLogger(CacheTestReader.class).warn("Unable to delete {}", myfile);
}
if (zc.get(rootDir + "/die") != null) {
return;
}
Map<String, String> readData = new TreeMap<>();
for (int i = 0; i < numData; i++) {
byte[] v = zc.get(rootDir + "/data" + i);
if (v != null)
readData.put(rootDir + "/data" + i, new String(v, UTF_8));
}
byte[] v = zc.get(rootDir + "/dataS");
if (v != null)
readData.put(rootDir + "/dataS", new String(v, UTF_8));
List<String> children = zc.getChildren(rootDir + "/dir");
if (children != null)
for (String child : children) {
readData.put(rootDir + "/dir/" + child, "");
}
FileOutputStream fos = new FileOutputStream(myfile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(readData);
fos.close();
oos.close();
sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
}
}
use of org.apache.accumulo.fate.zookeeper.ZooCache 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.ZooCache 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.ZooCache 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);
}
});
}
}
}
use of org.apache.accumulo.fate.zookeeper.ZooCache 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");
}
}
Aggregations