use of org.apache.accumulo.core.util.ServerServices 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);
}
use of org.apache.accumulo.core.util.ServerServices in project accumulo by apache.
the class LiveTServerSet method checkServer.
private synchronized void checkServer(final Set<TServerInstance> updates, final Set<TServerInstance> doomed, final String path, final String zPath) throws TException, InterruptedException, KeeperException {
TServerInfo info = current.get(zPath);
final String lockPath = path + "/" + zPath;
ZcStat stat = new ZcStat();
byte[] lockData = ZooLock.getLockData(getZooCache(), lockPath, stat);
if (lockData == null) {
if (info != null) {
doomed.add(info.instance);
current.remove(zPath);
currentInstances.remove(info.instance);
}
Long firstSeen = locklessServers.get(zPath);
if (firstSeen == null) {
locklessServers.put(zPath, System.currentTimeMillis());
} else if (System.currentTimeMillis() - firstSeen > 10 * 60 * 1000) {
deleteServerNode(path + "/" + zPath);
locklessServers.remove(zPath);
}
} else {
locklessServers.remove(zPath);
ServerServices services = new ServerServices(new String(lockData, UTF_8));
HostAndPort client = services.getAddress(ServerServices.Service.TSERV_CLIENT);
TServerInstance instance = new TServerInstance(client, stat.getEphemeralOwner());
if (info == null) {
updates.add(instance);
TServerInfo tServerInfo = new TServerInfo(instance, new TServerConnection(client));
current.put(zPath, tServerInfo);
currentInstances.put(instance, tServerInfo);
} else if (!info.instance.equals(instance)) {
doomed.add(info.instance);
updates.add(instance);
TServerInfo tServerInfo = new TServerInfo(instance, new TServerConnection(client));
current.put(zPath, tServerInfo);
currentInstances.remove(info.instance);
currentInstances.put(instance, tServerInfo);
}
}
}
use of org.apache.accumulo.core.util.ServerServices 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;
}
use of org.apache.accumulo.core.util.ServerServices in project accumulo by apache.
the class SimpleGarbageCollector method getZooLock.
private void getZooLock(HostAndPort addr) throws KeeperException, InterruptedException {
String path = ZooUtil.getRoot(getInstance()) + Constants.ZGC_LOCK;
LockWatcher lockWatcher = new LockWatcher() {
@Override
public void lostLock(LockLossReason reason) {
Halt.halt("GC lock in zookeeper lost (reason = " + reason + "), exiting!", 1);
}
@Override
public void unableToMonitorLockNode(final Throwable e) {
// ACCUMULO-3651 Level changed to error and FATAL added to message for slf4j compatibility
Halt.halt(-1, new Runnable() {
@Override
public void run() {
log.error("FATAL: No longer able to monitor lock node ", e);
}
});
}
};
while (true) {
lock = new ZooLock(path);
if (lock.tryLock(lockWatcher, new ServerServices(addr.toString(), Service.GC_CLIENT).toString().getBytes())) {
log.debug("Got GC ZooKeeper lock");
return;
}
log.debug("Failed to get GC ZooKeeper lock, will retry");
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
}
use of org.apache.accumulo.core.util.ServerServices 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);
}
Aggregations