use of org.apache.accumulo.server.manager.state.MetaDataTableScanner in project accumulo by apache.
the class FindOfflineTablets method findOffline.
static int findOffline(ServerContext context, String tableName) throws TableNotFoundException {
final AtomicBoolean scanning = new AtomicBoolean(false);
LiveTServerSet tservers = new LiveTServerSet(context, new Listener() {
@Override
public void update(LiveTServerSet current, Set<TServerInstance> deleted, Set<TServerInstance> added) {
if (!deleted.isEmpty() && scanning.get())
log.warn("Tablet servers deleted while scanning: {}", deleted);
if (!added.isEmpty() && scanning.get())
log.warn("Tablet servers added while scanning: {}", added);
}
});
tservers.startListeningForTabletServerChanges();
scanning.set(true);
Iterator<TabletLocationState> zooScanner = TabletStateStore.getStoreForLevel(DataLevel.ROOT, context).iterator();
int offline = 0;
System.out.println("Scanning zookeeper");
if ((offline = checkTablets(context, zooScanner, tservers)) > 0)
return offline;
if (RootTable.NAME.equals(tableName))
return 0;
System.out.println("Scanning " + RootTable.NAME);
Iterator<TabletLocationState> rootScanner = new MetaDataTableScanner(context, TabletsSection.getRange(), RootTable.NAME);
if ((offline = checkTablets(context, rootScanner, tservers)) > 0)
return offline;
if (MetadataTable.NAME.equals(tableName))
return 0;
System.out.println("Scanning " + MetadataTable.NAME);
Range range = TabletsSection.getRange();
if (tableName != null) {
TableId tableId = context.getTableId(tableName);
range = new KeyExtent(tableId, null, null).toMetaRange();
}
try (MetaDataTableScanner metaScanner = new MetaDataTableScanner(context, range, MetadataTable.NAME)) {
return checkTablets(context, metaScanner, tservers);
}
}
use of org.apache.accumulo.server.manager.state.MetaDataTableScanner in project accumulo by apache.
the class TablesResource method getParticipatingTabletServers.
/**
* Generates a list of participating tservers for a table
*
* @param tableIdStr
* Table ID to find participating tservers
* @return List of participating tservers
*/
@Path("{tableId}")
@GET
public TabletServers getParticipatingTabletServers(@PathParam("tableId") @NotNull @Pattern(regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableIdStr) {
String rootTabletLocation = monitor.getContext().getRootTabletLocation();
TableId tableId = TableId.of(tableIdStr);
ManagerMonitorInfo mmi = monitor.getMmi();
// fail fast if unable to get monitor info
if (mmi == null) {
return new TabletServers();
}
TabletServers tabletServers = new TabletServers(mmi.tServerInfo.size());
if (tableIdStr.isBlank()) {
return tabletServers;
}
TreeSet<String> locs = new TreeSet<>();
if (RootTable.ID.equals(tableId)) {
locs.add(rootTabletLocation);
} else {
String systemTableName = MetadataTable.ID.equals(tableId) ? RootTable.NAME : MetadataTable.NAME;
MetaDataTableScanner scanner = new MetaDataTableScanner(monitor.getContext(), new Range(TabletsSection.encodeRow(tableId, new Text()), TabletsSection.encodeRow(tableId, null)), systemTableName);
while (scanner.hasNext()) {
TabletLocationState state = scanner.next();
if (state.current != null) {
try {
locs.add(state.current.getHostPort());
} catch (Exception ex) {
scanner.close();
return tabletServers;
}
}
}
scanner.close();
}
List<TabletServerStatus> tservers = new ArrayList<>();
for (TabletServerStatus tss : mmi.tServerInfo) {
try {
if (tss.name != null && locs.contains(tss.name)) {
tservers.add(tss);
}
} catch (Exception ex) {
return tabletServers;
}
}
// Adds tservers to the list
for (TabletServerStatus status : tservers) {
if (status == null) {
status = NO_STATUS;
}
TableInfo summary = status.tableMap.get(tableId.canonical());
if (summary == null) {
continue;
}
TabletServer tabletServerInfo = new TabletServer();
tabletServerInfo.server.updateTabletServerInfo(monitor, status, summary);
tabletServers.addTablet(tabletServerInfo);
}
return tabletServers;
}
use of org.apache.accumulo.server.manager.state.MetaDataTableScanner in project accumulo by apache.
the class NullTserver method main.
public static void main(String[] args) throws Exception {
Opts opts = new Opts();
opts.parseArgs(NullTserver.class.getName(), args);
// modify metadata
int zkTimeOut = (int) DefaultConfiguration.getInstance().getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT);
var siteConfig = SiteConfiguration.auto();
ServerContext context = ServerContext.override(siteConfig, opts.iname, opts.keepers, zkTimeOut);
TransactionWatcher watcher = new TransactionWatcher(context);
ThriftClientHandler tch = new ThriftClientHandler(context, watcher);
Processor<Iface> processor = new Processor<>(tch);
TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, processor, "NullTServer", "null tserver", 2, ThreadPools.DEFAULT_TIMEOUT_MILLISECS, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", opts.port));
HostAndPort addr = HostAndPort.fromParts(InetAddress.getLocalHost().getHostName(), opts.port);
TableId tableId = context.getTableId(opts.tableName);
// read the locations for the table
Range tableRange = new KeyExtent(tableId, null, null).toMetaRange();
List<Assignment> assignments = new ArrayList<>();
try (var s = new MetaDataTableScanner(context, tableRange, MetadataTable.NAME)) {
long randomSessionID = opts.port;
TServerInstance instance = new TServerInstance(addr, randomSessionID);
while (s.hasNext()) {
TabletLocationState next = s.next();
assignments.add(new Assignment(next.extent, instance));
}
}
// point them to this server
TabletStateStore store = TabletStateStore.getStoreForLevel(DataLevel.USER, context);
store.setLocations(assignments);
while (true) {
sleepUninterruptibly(10, TimeUnit.SECONDS);
}
}
Aggregations