use of org.apache.accumulo.server.zookeeper.ZooReaderWriter in project accumulo by apache.
the class GarbageCollectorCommunicatesWithTServersIT method getWalsForTable.
/**
* Fetch all of the WALs referenced by tablets in the metadata table for this table
*/
private Set<String> getWalsForTable(String tableName) throws Exception {
final Connector conn = getConnector();
final String tableId = conn.tableOperations().tableIdMap().get(tableName);
Assert.assertNotNull("Could not determine table ID for " + tableName, tableId);
Instance i = conn.getInstance();
ZooReaderWriter zk = new ZooReaderWriter(i.getZooKeepers(), i.getZooKeepersSessionTimeOut(), "");
WalStateManager wals = new WalStateManager(conn.getInstance(), zk);
Set<String> result = new HashSet<>();
for (Entry<Path, WalState> entry : wals.getAllState().entrySet()) {
log.debug("Reading WALs: {}={}", entry.getKey(), entry.getValue());
result.add(entry.getKey().toString());
}
return result;
}
use of org.apache.accumulo.server.zookeeper.ZooReaderWriter 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.server.zookeeper.ZooReaderWriter in project accumulo by apache.
the class LogService method startLogListener.
/**
* Place the host:port advertisement for the Monitor's Log4j listener in ZooKeeper
*
* @param conf
* configuration for the instance
* @param instanceId
* instanceId for the instance
* @param hostAddress
* Address that monitor process is bound to
*/
public static void startLogListener(AccumuloConfiguration conf, String instanceId, String hostAddress) {
try {
SocketServer server = new SocketServer(conf.getPort(Property.MONITOR_LOG4J_PORT)[0]);
// getLocalPort will return the actual ephemeral port used when '0' was provided.
String logForwardingAddr = hostAddress + ":" + server.getLocalPort();
log.debug("Setting monitor log4j log-forwarding address to: {}", logForwardingAddr);
final String path = ZooUtil.getRoot(instanceId) + Constants.ZMONITOR_LOG4J_ADDR;
final ZooReaderWriter zoo = ZooReaderWriter.getInstance();
// Delete before we try to re-create in case the previous session hasn't yet expired
try {
zoo.delete(path, -1);
} catch (KeeperException e) {
// We don't care if the node is already gone
if (!KeeperException.Code.NONODE.equals(e.code())) {
throw e;
}
}
zoo.putEphemeralData(path, logForwardingAddr.getBytes(UTF_8));
new Daemon(server).start();
} catch (Throwable t) {
log.info("Unable to start/advertise Log4j listener for log-forwarding to monitor", t);
}
}
use of org.apache.accumulo.server.zookeeper.ZooReaderWriter 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.server.zookeeper.ZooReaderWriter in project accumulo by apache.
the class ChangeSecret method verifyAccumuloIsDown.
private static void verifyAccumuloIsDown(Instance inst, String oldPassword) throws Exception {
ZooReader zooReader = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), oldPassword);
String root = ZooUtil.getRoot(inst);
final List<String> ephemerals = new ArrayList<>();
recurse(zooReader, root, new Visitor() {
@Override
public void visit(ZooReader zoo, String path) throws Exception {
Stat stat = zoo.getStatus(path);
if (stat.getEphemeralOwner() != 0)
ephemerals.add(path);
}
});
if (ephemerals.size() > 0) {
System.err.println("The following ephemeral nodes exist, something is still running:");
for (String path : ephemerals) {
System.err.println(path);
}
throw new Exception("Accumulo must be shut down in order to run this tool.");
}
}
Aggregations