use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class ManagerClientServiceHandler method shutdownTabletServer.
@Override
public void shutdownTabletServer(TInfo info, TCredentials c, String tabletServer, boolean force) throws ThriftSecurityException {
if (!manager.security.canPerformSystemActions(c))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
final TServerInstance doomed = manager.tserverSet.find(tabletServer);
if (!force) {
final TServerConnection server = manager.tserverSet.getConnection(doomed);
if (server == null) {
Manager.log.warn("No server found for name {}", tabletServer);
return;
}
}
long tid = manager.fate.startTransaction();
String msg = "Shutdown tserver " + tabletServer;
manager.fate.seedTransaction(tid, new TraceRepo<>(new ShutdownTServer(doomed, force)), false, msg);
manager.fate.waitForCompletion(tid);
manager.fate.delete(tid);
log.debug("FATE op shutting down " + tabletServer + " finished");
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class ManagerClientServiceHandler method waitForFlush.
@Override
public void waitForFlush(TInfo tinfo, TCredentials c, String tableIdStr, ByteBuffer startRowBB, ByteBuffer endRowBB, long flushID, long maxLoops) throws ThriftSecurityException, ThriftTableOperationException {
TableId tableId = TableId.of(tableIdStr);
NamespaceId namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
if (!manager.security.canFlush(c, tableId, namespaceId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
Text startRow = ByteBufferUtil.toText(startRowBB);
Text endRow = ByteBufferUtil.toText(endRowBB);
if (endRow != null && startRow != null && startRow.compareTo(endRow) >= 0)
throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.BAD_RANGE, "start row must be less than end row");
Set<TServerInstance> serversToFlush = new HashSet<>(manager.tserverSet.getCurrentServers());
for (long l = 0; l < maxLoops; l++) {
for (TServerInstance instance : serversToFlush) {
try {
final TServerConnection server = manager.tserverSet.getConnection(instance);
if (server != null)
server.flush(manager.managerLock, tableId, ByteBufferUtil.toBytes(startRowBB), ByteBufferUtil.toBytes(endRowBB));
} catch (TException ex) {
Manager.log.error(ex.toString());
}
}
if (tableId.equals(RootTable.ID))
// this code does not properly handle the root tablet. See #798
break;
if (l == maxLoops - 1)
break;
sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
serversToFlush.clear();
try (TabletsMetadata tablets = TabletsMetadata.builder(manager.getContext()).forTable(tableId).overlapping(startRow, endRow).fetch(FLUSH_ID, LOCATION, LOGS, PREV_ROW).build()) {
int tabletsToWaitFor = 0;
int tabletCount = 0;
for (TabletMetadata tablet : tablets) {
int logs = tablet.getLogs().size();
// when tablet is not online and has no logs, there is no reason to wait for it
if ((tablet.hasCurrent() || logs > 0) && tablet.getFlushId().orElse(-1) < flushID) {
tabletsToWaitFor++;
if (tablet.hasCurrent())
serversToFlush.add(tablet.getLocation());
}
tabletCount++;
}
if (tabletsToWaitFor == 0)
break;
if (tabletCount == 0 && !manager.getContext().tableNodeExists(tableId))
throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
} catch (TabletDeletedException e) {
Manager.log.debug("Failed to scan {} table to wait for flush {}", MetadataTable.NAME, tableId, e);
}
}
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class QueueSummaries method getNextTserver.
synchronized PrioTserver getNextTserver(String queue) {
Entry<Short, TreeSet<TServerInstance>> entry = getNextTserverEntry(queue);
if (entry == null) {
// no tserver, so remove any last entry if it exists
LAST.remove(queue);
return null;
}
final Short priority = entry.getKey();
final TreeSet<TServerInstance> tservers = entry.getValue();
PrioTserver last = LAST.get(queue);
TServerInstance nextTserver = null;
if (last != null && last.prio == priority) {
TServerInstance higher = tservers.higher(last.tserver);
if (higher == null) {
nextTserver = tservers.first();
} else {
nextTserver = higher;
}
} else {
nextTserver = tservers.first();
}
PrioTserver result = new PrioTserver(nextTserver, priority);
LAST.put(queue, result);
return result;
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class UnloadTabletHandler method run.
@Override
public void run() {
Tablet t = null;
synchronized (server.unopenedTablets) {
if (server.unopenedTablets.contains(extent)) {
server.unopenedTablets.remove(extent);
// enqueueManagerMessage(new TabletUnloadedMessage(extent));
return;
}
}
synchronized (server.openingTablets) {
while (server.openingTablets.contains(extent)) {
try {
log.info("Waiting for tablet {} to finish opening before unloading.", extent);
server.openingTablets.wait();
} catch (InterruptedException e) {
}
}
}
synchronized (server.onlineTablets) {
if (server.onlineTablets.snapshot().containsKey(extent)) {
t = server.onlineTablets.snapshot().get(extent);
}
}
if (t == null) {
// unload request is crossing the successful unloaded message
if (!server.recentlyUnloadedCache.containsKey(extent)) {
log.info("told to unload tablet that was not being served {}", extent);
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOAD_FAILURE_NOT_SERVING, extent));
}
return;
}
try {
t.close(!goalState.equals(TUnloadTabletGoal.DELETED));
} catch (Exception e) {
if ((t.isClosing() || t.isClosed()) && e instanceof IllegalStateException) {
log.debug("Failed to unload tablet {}... it was already closing or closed : {}", extent, e.getMessage());
} else {
log.error("Failed to close tablet {}... Aborting migration", extent, e);
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOAD_ERROR, extent));
}
return;
}
// stop serving tablet - client will get not serving tablet
// exceptions
server.recentlyUnloadedCache.put(extent, System.currentTimeMillis());
server.onlineTablets.remove(extent);
try {
TServerInstance instance = new TServerInstance(server.clientAddress, server.getLock().getSessionId());
TabletLocationState tls = null;
try {
tls = new TabletLocationState(extent, null, instance, null, null, null, false);
} catch (BadLocationStateException e) {
log.error("Unexpected error", e);
}
if (!goalState.equals(TUnloadTabletGoal.SUSPENDED) || extent.isRootTablet() || (extent.isMeta() && !server.getConfiguration().getBoolean(Property.MANAGER_METADATA_SUSPENDABLE))) {
TabletStateStore.unassign(server.getContext(), tls, null);
} else {
TabletStateStore.suspend(server.getContext(), tls, null, requestTimeSkew + NANOSECONDS.toMillis(System.nanoTime()));
}
} catch (DistributedStoreException ex) {
log.warn("Unable to update storage", ex);
} catch (KeeperException e) {
log.warn("Unable determine our zookeeper session information", e);
} catch (InterruptedException e) {
log.warn("Interrupted while getting our zookeeper session information", e);
}
// tell the manager how it went
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOADED, extent));
// roll tablet stats over into tablet server's statsKeeper object as
// historical data
server.statsKeeper.saveMajorMinorTimes(t.getTabletStats());
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class RegexGroupBalanceIT method getCounts.
private Table<String, String, MutableInt> getCounts(AccumuloClient client, String tablename) throws TableNotFoundException {
try (Scanner s = client.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
s.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
TableId tableId = TableId.of(client.tableOperations().tableIdMap().get(tablename));
s.setRange(TabletsSection.getRange(tableId));
Table<String, String, MutableInt> groupLocationCounts = HashBasedTable.create();
for (Entry<Key, Value> entry : s) {
String group = entry.getKey().getRow().toString();
if (group.endsWith("<")) {
group = "03";
} else {
group = group.substring(tableId.canonical().length() + 1).substring(0, 2);
}
String loc = new TServerInstance(entry.getValue(), entry.getKey().getColumnQualifier()).getHostPortSession();
MutableInt count = groupLocationCounts.get(group, loc);
if (count == null) {
count = new MutableInt(0);
groupLocationCounts.put(group, loc, count);
}
count.increment();
}
return groupLocationCounts;
}
}
Aggregations