Search in sources :

Example 71 with ServerContext

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();
        }
    }
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) ServerContext(org.apache.accumulo.server.ServerContext) ManagerClient(org.apache.accumulo.core.clientImpl.ManagerClient) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException)

Example 72 with ServerContext

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();
        }
    }
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) Entry(java.util.Map.Entry) ServerContext(org.apache.accumulo.server.ServerContext) ActiveScan(org.apache.accumulo.core.tabletserver.thrift.ActiveScan) ManagerClient(org.apache.accumulo.core.clientImpl.ManagerClient) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException)

Example 73 with ServerContext

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.");
}
Also used : ServerContext(org.apache.accumulo.server.ServerContext) ServiceLock(org.apache.accumulo.fate.zookeeper.ServiceLock) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) UUID(java.util.UUID)

Example 74 with ServerContext

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);
        }
    }
}
Also used : Help(org.apache.accumulo.core.cli.Help) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooStore(org.apache.accumulo.fate.ZooStore) Manager(org.apache.accumulo.manager.Manager) LinkedHashMap(java.util.LinkedHashMap) AdminUtil(org.apache.accumulo.fate.AdminUtil) ServerContext(org.apache.accumulo.server.ServerContext) JCommander(com.beust.jcommander.JCommander)

Example 75 with ServerContext

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));
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) ServerContext(org.apache.accumulo.server.ServerContext) TreeSet(java.util.TreeSet) Manager(org.apache.accumulo.manager.Manager) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Test(org.junit.Test)

Aggregations

ServerContext (org.apache.accumulo.server.ServerContext)87 Test (org.junit.Test)41 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)18 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)15 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)15 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)15 HostAndPort (org.apache.accumulo.core.util.HostAndPort)15 Path (org.apache.hadoop.fs.Path)15 ArrayList (java.util.ArrayList)14 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)14 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)13 KeeperException (org.apache.zookeeper.KeeperException)13 ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)12 TableId (org.apache.accumulo.core.data.TableId)11 LiveTServerSet (org.apache.accumulo.server.manager.LiveTServerSet)11 Value (org.apache.accumulo.core.data.Value)10 IOException (java.io.IOException)9 UUID (java.util.UUID)9 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)9 Client (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)9