use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class Monitor method fetchCompactions.
private void fetchCompactions() {
ServerContext context = getContext();
for (String server : context.instanceOperations().getTabletServers()) {
final HostAndPort parsedServer = HostAndPort.fromString(server);
Client tserver = null;
try {
tserver = ThriftUtil.getTServerClient(parsedServer, context);
var compacts = tserver.getActiveCompactions(null, context.rpcCreds());
allCompactions.put(parsedServer, new CompactionStats(compacts));
compactsFetchedNanos = System.nanoTime();
} catch (Exception ex) {
log.debug("Failed to get active compactions from {}", server, ex);
} finally {
ThriftUtil.returnClient(tserver, context);
}
}
// Age off old compaction information
var entryIter = allCompactions.entrySet().iterator();
// clock time used for fetched for date friendly display
long now = System.currentTimeMillis();
while (entryIter.hasNext()) {
var entry = entryIter.next();
if (now - entry.getValue().fetched > ageOffEntriesMillis) {
entryIter.remove();
}
}
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class Monitor method fetchScans.
private void fetchScans() {
ServerContext context = getContext();
for (String server : context.instanceOperations().getTabletServers()) {
final HostAndPort parsedServer = HostAndPort.fromString(server);
Client tserver = null;
try {
tserver = ThriftUtil.getTServerClient(parsedServer, context);
List<ActiveScan> scans = tserver.getActiveScans(null, context.rpcCreds());
allScans.put(parsedServer, new ScanStats(scans));
scansFetchedNanos = System.nanoTime();
} catch (Exception ex) {
log.error("Failed to get active scans from {}", server, ex);
} finally {
ThriftUtil.returnClient(tserver, context);
}
}
// Age off old scan information
Iterator<Entry<HostAndPort, ScanStats>> entryIter = allScans.entrySet().iterator();
// clock time used for fetched for date friendly display
long now = System.currentTimeMillis();
while (entryIter.hasNext()) {
Entry<HostAndPort, ScanStats> entry = entryIter.next();
if (now - entry.getValue().fetched > ageOffEntriesMillis) {
entryIter.remove();
}
}
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class Monitor method getMonitorLock.
/**
* Get the monitor lock in ZooKeeper
*/
private void getMonitorLock() throws KeeperException, InterruptedException {
ServerContext context = getContext();
final String zRoot = context.getZooKeeperRoot();
final String monitorPath = zRoot + Constants.ZMONITOR;
final var monitorLockPath = ServiceLock.path(zRoot + Constants.ZMONITOR_LOCK);
// Ensure that everything is kosher with ZK as this has changed.
ZooReaderWriter zoo = context.getZooReaderWriter();
if (zoo.exists(monitorPath)) {
byte[] data = zoo.getData(monitorPath);
// If the node isn't empty, it's from a previous install (has hostname:port for HTTP server)
if (data.length != 0) {
// Recursively delete from that parent node
zoo.recursiveDelete(monitorPath, NodeMissingPolicy.SKIP);
// And then make the nodes that we expect for the incoming ephemeral nodes
zoo.putPersistentData(monitorPath, new byte[0], NodeExistsPolicy.FAIL);
zoo.putPersistentData(monitorLockPath.toString(), new byte[0], NodeExistsPolicy.FAIL);
} else if (!zoo.exists(monitorLockPath.toString())) {
// monitor node in ZK exists and is empty as we expect
// but the monitor/lock node does not
zoo.putPersistentData(monitorLockPath.toString(), new byte[0], NodeExistsPolicy.FAIL);
}
} else {
// 1.5.0 and earlier
zoo.putPersistentData(zRoot + Constants.ZMONITOR, new byte[0], NodeExistsPolicy.FAIL);
if (!zoo.exists(monitorLockPath.toString())) {
// Somehow the monitor node exists but not monitor/lock
zoo.putPersistentData(monitorLockPath.toString(), new byte[0], NodeExistsPolicy.FAIL);
}
}
// Get a ZooLock for the monitor
UUID zooLockUUID = UUID.randomUUID();
while (true) {
MoniterLockWatcher monitorLockWatcher = new MoniterLockWatcher();
monitorLock = new ServiceLock(zoo.getZooKeeper(), monitorLockPath, zooLockUUID);
monitorLock.lock(monitorLockWatcher, new byte[0]);
monitorLockWatcher.waitForChange();
if (monitorLockWatcher.acquiredLock) {
break;
}
if (!monitorLockWatcher.failedToAcquireLock) {
throw new IllegalStateException("monitor lock in unknown state");
}
monitorLock.tryToCancelAsyncLockOrUnlock();
sleepUninterruptibly(context.getConfiguration().getTimeInMillis(Property.MONITOR_LOCK_CHECK_INTERVAL), TimeUnit.MILLISECONDS);
}
log.info("Got Monitor lock.");
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class FateAdmin method main.
public static void main(String[] args) throws Exception {
Help opts = new Help();
JCommander jc = new JCommander(opts);
jc.setProgramName(FateAdmin.class.getName());
LinkedHashMap<String, TxOpts> txOpts = new LinkedHashMap<>(2);
txOpts.put("fail", new FailOpts());
txOpts.put("delete", new DeleteOpts());
for (Entry<String, TxOpts> entry : txOpts.entrySet()) {
jc.addCommand(entry.getKey(), entry.getValue());
}
jc.addCommand("print", new PrintOpts());
jc.parse(args);
if (opts.help || jc.getParsedCommand() == null) {
jc.usage();
System.exit(1);
}
System.err.printf("This tool has been deprecated%nFATE administration now" + " available within 'accumulo shell'%n$ fate fail <txid>... | delete" + " <txid>... | print [<txid>...]%n%n");
AdminUtil<Manager> admin = new AdminUtil<>();
try (var context = new ServerContext(SiteConfiguration.auto())) {
final String zkRoot = context.getZooKeeperRoot();
String path = zkRoot + Constants.ZFATE;
var zLockManagerPath = ServiceLock.path(zkRoot + Constants.ZMANAGER_LOCK);
ZooReaderWriter zk = context.getZooReaderWriter();
ZooStore<Manager> zs = new ZooStore<>(path, zk);
if (jc.getParsedCommand().equals("fail")) {
for (String txid : txOpts.get(jc.getParsedCommand()).txids) {
if (!admin.prepFail(zs, zk, zLockManagerPath, txid)) {
System.exit(1);
}
}
} else if (jc.getParsedCommand().equals("delete")) {
for (String txid : txOpts.get(jc.getParsedCommand()).txids) {
if (!admin.prepDelete(zs, zk, zLockManagerPath, txid)) {
System.exit(1);
}
admin.deleteLocks(zk, zkRoot + Constants.ZTABLE_LOCKS, txid);
}
} else if (jc.getParsedCommand().equals("print")) {
admin.print(new ReadOnlyStore<>(zs), zk, zkRoot + Constants.ZTABLE_LOCKS);
}
}
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class ManagerReplicationCoordinatorTest method randomServerFromMany.
@Test
public void randomServerFromMany() {
Manager manager = EasyMock.createMock(Manager.class);
ZooReader reader = EasyMock.createMock(ZooReader.class);
ServerContext context = EasyMock.createMock(ServerContext.class);
EasyMock.expect(context.getConfiguration()).andReturn(config).anyTimes();
EasyMock.expect(context.getInstanceID()).andReturn(InstanceId.of("1234")).anyTimes();
EasyMock.expect(context.getZooReaderWriter()).andReturn(null).anyTimes();
EasyMock.expect(manager.getInstanceID()).andReturn(InstanceId.of("1234")).anyTimes();
EasyMock.expect(manager.getContext()).andReturn(context).anyTimes();
EasyMock.replay(manager, context, reader);
ManagerReplicationCoordinator coordinator = new ManagerReplicationCoordinator(manager, reader);
EasyMock.verify(manager, reader);
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);
assertEquals(inst1, coordinator.getRandomTServer(instances, 0));
assertEquals(inst2, coordinator.getRandomTServer(instances, 1));
}
Aggregations