Search in sources :

Example 11 with Manager

use of org.apache.accumulo.manager.Manager 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 12 with Manager

use of org.apache.accumulo.manager.Manager in project accumulo by apache.

the class CompactRange method call.

@Override
public Repo<Manager> call(final long tid, Manager env) throws Exception {
    String zTablePath = Constants.ZROOT + "/" + env.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
    ZooReaderWriter zoo = env.getContext().getZooReaderWriter();
    byte[] cid;
    try {
        cid = zoo.mutateExisting(zTablePath, currentValue -> {
            String cvs = new String(currentValue, UTF_8);
            String[] tokens = cvs.split(",");
            long flushID = Long.parseLong(tokens[0]) + 1;
            String txidString = String.format("%016x", tid);
            for (int i = 1; i < tokens.length; i++) {
                if (tokens[i].startsWith(txidString))
                    // skip self
                    continue;
                log.debug("txidString : {}", txidString);
                log.debug("tokens[{}] : {}", i, tokens[i]);
                throw new AcceptableThriftTableOperationException(tableId.canonical(), null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Another compaction with iterators and/or a compaction strategy is running");
            }
            StringBuilder encodedIterators = new StringBuilder();
            if (config != null) {
                Hex hex = new Hex();
                encodedIterators.append(",");
                encodedIterators.append(txidString);
                encodedIterators.append("=");
                encodedIterators.append(new String(hex.encode(config), UTF_8));
            }
            return (Long.toString(flushID) + encodedIterators).getBytes(UTF_8);
        });
        return new CompactionDriver(Long.parseLong(new String(cid, UTF_8).split(",")[0]), namespaceId, tableId, startRow, endRow);
    } catch (NoNodeException nne) {
        throw new AcceptableThriftTableOperationException(tableId.canonical(), null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null);
    }
}
Also used : UserCompactionUtils.isDefault(org.apache.accumulo.core.clientImpl.UserCompactionUtils.isDefault) TableId(org.apache.accumulo.core.data.TableId) AcceptableThriftTableOperationException(org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException) Logger(org.slf4j.Logger) UTF_8(java.nio.charset.StandardCharsets.UTF_8) LoggerFactory(org.slf4j.LoggerFactory) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Hex(org.apache.commons.codec.binary.Hex) Constants(org.apache.accumulo.core.Constants) TextUtil(org.apache.accumulo.core.util.TextUtil) Repo(org.apache.accumulo.fate.Repo) TableOperation(org.apache.accumulo.core.clientImpl.thrift.TableOperation) Manager(org.apache.accumulo.manager.Manager) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) Utils(org.apache.accumulo.manager.tableOps.Utils) CompactionStrategyConfigUtil(org.apache.accumulo.core.clientImpl.CompactionStrategyConfigUtil) TableOperationExceptionType(org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType) NamespaceId(org.apache.accumulo.core.data.NamespaceId) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) UserCompactionUtils(org.apache.accumulo.core.clientImpl.UserCompactionUtils) ManagerRepo(org.apache.accumulo.manager.tableOps.ManagerRepo) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) Hex(org.apache.commons.codec.binary.Hex) AcceptableThriftTableOperationException(org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException)

Example 13 with Manager

use of org.apache.accumulo.manager.Manager 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)

Example 14 with Manager

use of org.apache.accumulo.manager.Manager in project accumulo by apache.

the class CompactionDriverTest method testTableBeingDeleted.

@Test
public void testTableBeingDeleted() throws Exception {
    final InstanceId instance = InstanceId.of(UUID.randomUUID());
    final long compactId = 123;
    final long cancelId = 122;
    final NamespaceId namespaceId = NamespaceId.of("14");
    final TableId tableId = TableId.of("43");
    final byte[] startRow = new byte[0];
    final byte[] endRow = new byte[0];
    Manager manager = EasyMock.createNiceMock(Manager.class);
    ServerContext ctx = EasyMock.createNiceMock(ServerContext.class);
    ZooReaderWriter zrw = EasyMock.createNiceMock(ZooReaderWriter.class);
    EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes();
    EasyMock.expect(manager.getContext()).andReturn(ctx);
    EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw);
    final String zCancelID = CompactionDriver.createCompactionCancellationPath(instance, tableId);
    EasyMock.expect(zrw.getData(zCancelID)).andReturn(Long.toString(cancelId).getBytes());
    String deleteMarkerPath = PreDeleteTable.createDeleteMarkerPath(instance, tableId);
    EasyMock.expect(zrw.exists(deleteMarkerPath)).andReturn(true);
    EasyMock.replay(manager, ctx, zrw);
    final CompactionDriver driver = new CompactionDriver(compactId, namespaceId, tableId, startRow, endRow);
    final long tableIdLong = Long.parseLong(tableId.toString());
    var e = assertThrows(AcceptableThriftTableOperationException.class, () -> driver.isReady(tableIdLong, manager));
    assertTrue(e.getTableId().equals(tableId.toString()));
    assertTrue(e.getOp().equals(TableOperation.COMPACT));
    assertTrue(e.getType().equals(TableOperationExceptionType.OTHER));
    assertTrue(e.getDescription().equals(TableOperationsImpl.TABLE_DELETED_MSG));
    EasyMock.verify(manager, ctx, zrw);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ServerContext(org.apache.accumulo.server.ServerContext) InstanceId(org.apache.accumulo.core.data.InstanceId) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) NamespaceId(org.apache.accumulo.core.data.NamespaceId) Manager(org.apache.accumulo.manager.Manager) Test(org.junit.Test)

Example 15 with Manager

use of org.apache.accumulo.manager.Manager in project accumulo by apache.

the class ReplicationMetricsTest method testAddReplicationQueueTimeMetrics.

@Test
public void testAddReplicationQueueTimeMetrics() throws Exception {
    Manager manager = EasyMock.createMock(Manager.class);
    ServerContext context = EasyMock.createMock(ServerContext.class);
    VolumeManager fileSystem = EasyMock.createMock(VolumeManager.class);
    ReplicationUtil util = EasyMock.createMock(ReplicationUtil.class);
    MeterRegistry meterRegistry = EasyMock.createMock(MeterRegistry.class);
    Timer timer = EasyMock.createMock(Timer.class);
    Path path1 = new Path("hdfs://localhost:9000/accumulo/wal/file1");
    Path path2 = new Path("hdfs://localhost:9000/accumulo/wal/file2");
    // First call will initialize the map of paths to modification time
    EasyMock.expect(manager.getContext()).andReturn(context).anyTimes();
    EasyMock.expect(meterRegistry.timer("replicationQueue")).andReturn(timer).anyTimes();
    EasyMock.expect(meterRegistry.gauge(EasyMock.eq("filesPendingReplication"), EasyMock.anyObject(AtomicLong.class))).andReturn(new AtomicLong(0)).anyTimes();
    EasyMock.expect(meterRegistry.gauge(EasyMock.eq("numPeers"), EasyMock.anyObject(AtomicInteger.class))).andReturn(new AtomicInteger(0)).anyTimes();
    EasyMock.expect(meterRegistry.gauge(EasyMock.eq("maxReplicationThreads"), EasyMock.anyObject(AtomicInteger.class))).andReturn(new AtomicInteger(0)).anyTimes();
    EasyMock.expect(util.getPendingReplicationPaths()).andReturn(Set.of(path1, path2));
    EasyMock.expect(manager.getVolumeManager()).andReturn(fileSystem);
    EasyMock.expect(fileSystem.getFileStatus(path1)).andReturn(createStatus(100));
    EasyMock.expect(manager.getVolumeManager()).andReturn(fileSystem);
    EasyMock.expect(fileSystem.getFileStatus(path2)).andReturn(createStatus(200));
    // Second call will recognize the missing path1 and add the latency stat
    EasyMock.expect(util.getPendingReplicationPaths()).andReturn(Set.of(path2));
    timer.record(EasyMock.isA(Duration.class));
    EasyMock.expectLastCall();
    EasyMock.replay(manager, fileSystem, util, meterRegistry, timer);
    ReplicationMetrics metrics = new ReplicationMetricsTestMetrics(manager);
    // Inject our mock objects
    replaceField(metrics, "replicationUtil", util);
    replaceField(metrics, "replicationQueueTimer", timer);
    // Two calls to this will initialize the map and then add metrics
    metrics.addReplicationQueueTimeMetrics();
    metrics.addReplicationQueueTimeMetrics();
    EasyMock.verify(manager, fileSystem, util, meterRegistry, timer);
}
Also used : Path(org.apache.hadoop.fs.Path) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) ServerContext(org.apache.accumulo.server.ServerContext) Timer(io.micrometer.core.instrument.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReplicationUtil(org.apache.accumulo.server.replication.ReplicationUtil) Duration(java.time.Duration) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) Manager(org.apache.accumulo.manager.Manager) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.Test)

Aggregations

Manager (org.apache.accumulo.manager.Manager)15 ServerContext (org.apache.accumulo.server.ServerContext)10 Test (org.junit.Test)9 TableId (org.apache.accumulo.core.data.TableId)5 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)5 Path (org.apache.hadoop.fs.Path)5 AcceptableThriftTableOperationException (org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException)4 TableOperation (org.apache.accumulo.core.clientImpl.thrift.TableOperation)4 TableOperationExceptionType (org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType)4 NamespaceId (org.apache.accumulo.core.data.NamespaceId)4 Repo (org.apache.accumulo.fate.Repo)4 ManagerRepo (org.apache.accumulo.manager.tableOps.ManagerRepo)4 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 IOException (java.io.IOException)3 Set (java.util.Set)3 Constants (org.apache.accumulo.core.Constants)3 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)3 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2