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();
}
}
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;
}
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));
}
}
}
}
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>");
}
}
}
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();
}
}
Aggregations