use of org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection in project accumulo by apache.
the class ShutdownTServerTest method testSingleShutdown.
@Test
public void testSingleShutdown() throws Exception {
HostAndPort hap = HostAndPort.fromParts("localhost", 1234);
final TServerInstance tserver = new TServerInstance(hap, "fake");
final boolean force = false;
final ShutdownTServer op = new ShutdownTServer(tserver, force);
final Manager manager = EasyMock.createMock(Manager.class);
final long tid = 1L;
final TServerConnection tserverCnxn = EasyMock.createMock(TServerConnection.class);
final TabletServerStatus status = new TabletServerStatus();
status.tableMap = new HashMap<>();
// Put in a table info record, don't care what
status.tableMap.put("a_table", new TableInfo());
manager.shutdownTServer(tserver);
EasyMock.expectLastCall().once();
EasyMock.expect(manager.onlineTabletServers()).andReturn(Collections.singleton(tserver));
EasyMock.expect(manager.getConnection(tserver)).andReturn(tserverCnxn);
EasyMock.expect(tserverCnxn.getTableMap(false)).andReturn(status);
EasyMock.replay(tserverCnxn, manager);
// FATE op is not ready
long wait = op.isReady(tid, manager);
assertTrue("Expected wait to be greater than 0", wait > 0);
EasyMock.verify(tserverCnxn, manager);
// Reset the mocks
EasyMock.reset(tserverCnxn, manager);
// reset the table map to the empty set to simulate all tablets unloaded
status.tableMap = new HashMap<>();
manager.shutdownTServer(tserver);
EasyMock.expectLastCall().once();
EasyMock.expect(manager.onlineTabletServers()).andReturn(Collections.singleton(tserver));
EasyMock.expect(manager.getConnection(tserver)).andReturn(tserverCnxn);
EasyMock.expect(tserverCnxn.getTableMap(false)).andReturn(status);
EasyMock.expect(manager.getManagerLock()).andReturn(null);
tserverCnxn.halt(null);
EasyMock.expectLastCall().once();
EasyMock.replay(tserverCnxn, manager);
// FATE op is not ready
wait = op.isReady(tid, manager);
assertTrue("Expected wait to be 0", wait == 0);
Repo<Manager> op2 = op.call(tid, manager);
assertNull("Expected no follow on step", op2);
EasyMock.verify(tserverCnxn, manager);
}
use of org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection in project accumulo by apache.
the class ShutdownTServer method isReady.
@Override
public long isReady(long tid, Manager manager) {
TServerInstance server = new TServerInstance(hostAndPort, serverSession);
// suppress assignment of tablets to the server
if (force) {
return 0;
}
// Inform the manager that we want this server to shutdown
manager.shutdownTServer(server);
if (manager.onlineTabletServers().contains(server)) {
TServerConnection connection = manager.getConnection(server);
if (connection != null) {
try {
TabletServerStatus status = connection.getTableMap(false);
if (status.tableMap != null && status.tableMap.isEmpty()) {
log.info("tablet server hosts no tablets {}", server);
connection.halt(manager.getManagerLock());
log.info("tablet server asked to halt {}", server);
return 0;
}
} catch (TTransportException ex) {
// expected
} catch (Exception ex) {
log.error("Error talking to tablet server {}: ", server, ex);
}
// tserver to ack the request and stop itself.
return 1000;
}
}
return 0;
}
use of org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection 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.server.manager.LiveTServerSet.TServerConnection 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.server.manager.LiveTServerSet.TServerConnection in project accumulo by apache.
the class CompactionCoordinator method getTabletServerConnection.
/**
* Return the Thrift client for the TServer
*
* @param tserver
* tserver instance
* @return thrift client
* @throws TTransportException
* thrift error
*/
protected TabletClientService.Client getTabletServerConnection(TServerInstance tserver) throws TTransportException {
TServerConnection connection = tserverSet.getConnection(tserver);
ServerContext serverContext = getContext();
TTransport transport = serverContext.getTransportPool().getTransport(connection.getAddress(), 0, serverContext);
return ThriftUtil.createClient(new TabletClientService.Client.Factory(), transport);
}
Aggregations