Search in sources :

Example 11 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class FateIT method testTransactionStatus.

@Test(timeout = 30000)
public void testTransactionStatus() throws Exception {
    ZooReaderWriter zk = new ZooReaderWriter(szk.getConn(), 30000, "secret");
    zk.mkdirs(ZK_ROOT + Constants.ZFATE);
    zk.mkdirs(ZK_ROOT + Constants.ZTABLE_LOCKS);
    zk.mkdirs(ZK_ROOT + Constants.ZNAMESPACES + "/" + NS.canonical());
    zk.mkdirs(ZK_ROOT + Constants.ZTABLE_STATE + "/" + TID.canonical());
    zk.mkdirs(ZK_ROOT + Constants.ZTABLES + "/" + TID.canonical());
    ZooStore<Manager> zooStore = new ZooStore<Manager>(ZK_ROOT + Constants.ZFATE, zk);
    final AgeOffStore<Manager> store = new AgeOffStore<Manager>(zooStore, 1000 * 60 * 60 * 8, System::currentTimeMillis);
    Manager manager = createMock(Manager.class);
    ServerContext sctx = createMock(ServerContext.class);
    expect(manager.getContext()).andReturn(sctx).anyTimes();
    expect(sctx.getZooKeeperRoot()).andReturn(ZK_ROOT).anyTimes();
    expect(sctx.getZooReaderWriter()).andReturn(zk).anyTimes();
    replay(manager, sctx);
    Fate<Manager> fate = new Fate<Manager>(manager, store, TraceRepo::toLogString);
    try {
        ConfigurationCopy config = new ConfigurationCopy();
        config.set(Property.GENERAL_SIMPLETIMER_THREADPOOL_SIZE, "2");
        config.set(Property.MANAGER_FATE_THREADPOOL_SIZE, "1");
        fate.startTransactionRunners(config);
        // Wait for the transaction runner to be scheduled.
        UtilWaitThread.sleep(3000);
        callStarted = new CountDownLatch(1);
        finishCall = new CountDownLatch(1);
        long txid = fate.startTransaction();
        assertEquals(TStatus.NEW, getTxStatus(zk, txid));
        fate.seedTransaction(txid, new TestOperation(NS, TID), true, "Test Op");
        assertEquals(TStatus.SUBMITTED, getTxStatus(zk, txid));
        // wait for call() to be called
        callStarted.await();
        assertEquals(TStatus.IN_PROGRESS, getTxStatus(zk, txid));
        // tell the op to exit the method
        finishCall.countDown();
        // Check that it transitions to SUCCESSFUL
        TStatus s = getTxStatus(zk, txid);
        while (s != TStatus.SUCCESSFUL) {
            s = getTxStatus(zk, txid);
            Thread.sleep(10);
        }
        // Check that it gets removed
        boolean errorSeen = false;
        while (!errorSeen) {
            try {
                s = getTxStatus(zk, txid);
                Thread.sleep(10);
            } catch (KeeperException e) {
                if (e.code() == KeeperException.Code.NONODE) {
                    errorSeen = true;
                } else {
                    fail("Unexpected error thrown: " + e.getMessage());
                }
            }
        }
    } finally {
        fate.shutdown();
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooStore(org.apache.accumulo.fate.ZooStore) TraceRepo(org.apache.accumulo.manager.tableOps.TraceRepo) Manager(org.apache.accumulo.manager.Manager) CountDownLatch(java.util.concurrent.CountDownLatch) Fate(org.apache.accumulo.fate.Fate) ServerContext(org.apache.accumulo.server.ServerContext) TStatus(org.apache.accumulo.fate.ReadOnlyTStore.TStatus) AgeOffStore(org.apache.accumulo.fate.AgeOffStore) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 12 with ServerContext

use of org.apache.accumulo.server.ServerContext 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 ServerContext context = getServerContext();
    final String tableId = context.tableOperations().tableIdMap().get(tableName);
    assertNotNull("Could not determine table ID for " + tableName, tableId);
    WalStateManager wals = new WalStateManager(context);
    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;
}
Also used : Path(org.apache.hadoop.fs.Path) ServerContext(org.apache.accumulo.server.ServerContext) WalStateManager(org.apache.accumulo.server.log.WalStateManager) WalState(org.apache.accumulo.server.log.WalStateManager.WalState) HashSet(java.util.HashSet)

Example 13 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class ReplicationIT method replicationEntriesPrecludeWalDeletion.

@Test
public void replicationEntriesPrecludeWalDeletion() throws Exception {
    final ServerContext context = getServerContext();
    try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
        String table1 = "table1", table2 = "table2", table3 = "table3";
        final Multimap<String, TableId> logs = HashMultimap.create();
        final AtomicBoolean keepRunning = new AtomicBoolean(true);
        Thread t = new Thread(() -> {
            // when that happens
            while (keepRunning.get()) {
                try {
                    logs.putAll(getAllLogs(client, context));
                } catch (Exception e) {
                    log.error("Error getting logs", e);
                }
            }
        });
        t.start();
        HashMap<String, String> replicate_props = new HashMap<>();
        replicate_props.put(Property.TABLE_REPLICATION.getKey(), "true");
        replicate_props.put(Property.TABLE_REPLICATION_TARGET.getKey() + "cluster1", "1");
        client.tableOperations().create(table1, new NewTableConfiguration().setProperties(replicate_props));
        Thread.sleep(2000);
        // Write some data to table1
        writeSomeData(client, table1, 200, 500);
        client.tableOperations().create(table2, new NewTableConfiguration().setProperties(replicate_props));
        Thread.sleep(2000);
        writeSomeData(client, table2, 200, 500);
        client.tableOperations().create(table3, new NewTableConfiguration().setProperties(replicate_props));
        Thread.sleep(2000);
        writeSomeData(client, table3, 200, 500);
        // Force a write to metadata for the data written
        for (String table : Arrays.asList(table1, table2, table3)) {
            client.tableOperations().flush(table, null, null, true);
        }
        keepRunning.set(false);
        t.join(5000);
        // The manager is only running every second to create records in the replication table from
        // the
        // metadata table
        // Sleep a sufficient amount of time to ensure that we get the straggling WALs that might have
        // been created at the end
        Thread.sleep(5000);
        Set<String> replFiles = getReferencesToFilesToBeReplicated(client);
        // We might have a WAL that was use solely for the replication table
        // We want to remove that from our list as it should not appear in the replication table
        String replicationTableId = client.tableOperations().tableIdMap().get(ReplicationTable.NAME);
        Iterator<Entry<String, TableId>> observedLogs = logs.entries().iterator();
        while (observedLogs.hasNext()) {
            Entry<String, TableId> observedLog = observedLogs.next();
            if (replicationTableId.equals(observedLog.getValue().canonical())) {
                log.info("Removing {} because its tableId is for the replication table", observedLog);
                observedLogs.remove();
            }
        }
        // We should have *some* reference to each log that was seen in the metadata table
        // They might not yet all be closed though (might be newfile)
        assertTrue("Metadata log distribution: " + logs + "replFiles " + replFiles, logs.keySet().containsAll(replFiles));
        assertTrue("Difference between replication entries and current logs is bigger than one", logs.keySet().size() - replFiles.size() <= 1);
        final Configuration conf = new Configuration();
        for (String replFile : replFiles) {
            Path p = new Path(replFile);
            FileSystem fs = p.getFileSystem(conf);
            if (!fs.exists(p)) {
                // double-check: the garbage collector can be fast
                Set<String> currentSet = getReferencesToFilesToBeReplicated(client);
                log.info("Current references {}", currentSet);
                log.info("Looking for reference to {}", replFile);
                log.info("Contains? {}", currentSet.contains(replFile));
                assertTrue("File does not exist anymore, it was likely incorrectly garbage collected: " + p, !currentSet.contains(replFile));
            }
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) HashMap(java.util.HashMap) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) URISyntaxException(java.net.URISyntaxException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ReplicationTableOfflineException(org.apache.accumulo.core.replication.ReplicationTableOfflineException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) NoSuchElementException(java.util.NoSuchElementException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Entry(java.util.Map.Entry) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) ServerContext(org.apache.accumulo.server.ServerContext) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) FileSystem(org.apache.hadoop.fs.FileSystem) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) Test(org.junit.Test)

Example 14 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class TabletServerLocks method main.

public static void main(String[] args) throws Exception {
    try (var context = new ServerContext(SiteConfiguration.auto())) {
        String tserverPath = context.getZooKeeperRoot() + Constants.ZTSERVERS;
        Opts opts = new Opts();
        opts.parseArgs(TabletServerLocks.class.getName(), args);
        ZooCache cache = context.getZooCache();
        ZooReaderWriter zoo = context.getZooReaderWriter();
        if (opts.list) {
            List<String> tabletServers = zoo.getChildren(tserverPath);
            for (String tabletServer : tabletServers) {
                var zLockPath = ServiceLock.path(tserverPath + "/" + tabletServer);
                byte[] lockData = ServiceLock.getLockData(cache, zLockPath, null);
                String holder = null;
                if (lockData != null) {
                    holder = new String(lockData, UTF_8);
                }
                System.out.printf("%32s %16s%n", tabletServer, holder);
            }
        } else if (opts.delete != null) {
            ServiceLock.deleteLock(zoo, ServiceLock.path(tserverPath + "/" + args[1]));
        } else {
            System.out.println("Usage : " + TabletServerLocks.class.getName() + " -list|-delete <tserver lock>");
        }
    }
}
Also used : ServerContext(org.apache.accumulo.server.ServerContext) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 15 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class FindOfflineTablets method main.

public static void main(String[] args) throws Exception {
    ServerUtilOpts opts = new ServerUtilOpts();
    opts.parseArgs(FindOfflineTablets.class.getName(), args);
    Span span = TraceUtil.startSpan(FindOfflineTablets.class, "main");
    try (Scope scope = span.makeCurrent()) {
        ServerContext context = opts.getServerContext();
        findOffline(context, null);
    } finally {
        span.end();
    }
}
Also used : Scope(io.opentelemetry.context.Scope) ServerContext(org.apache.accumulo.server.ServerContext) ServerUtilOpts(org.apache.accumulo.server.cli.ServerUtilOpts) Span(io.opentelemetry.api.trace.Span)

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