Search in sources :

Example 1 with MetaDataTableScanner

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);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Listener(org.apache.accumulo.server.manager.LiveTServerSet.Listener) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) LiveTServerSet(org.apache.accumulo.server.manager.LiveTServerSet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MetaDataTableScanner(org.apache.accumulo.server.manager.state.MetaDataTableScanner) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState)

Example 2 with MetaDataTableScanner

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;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TabletServers(org.apache.accumulo.monitor.rest.tservers.TabletServers) TreeSet(java.util.TreeSet) MetaDataTableScanner(org.apache.accumulo.server.manager.state.MetaDataTableScanner) TabletServer(org.apache.accumulo.monitor.rest.tservers.TabletServer) ManagerMonitorInfo(org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 3 with MetaDataTableScanner

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);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Processor(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor) ArrayList(java.util.ArrayList) TabletStateStore(org.apache.accumulo.server.manager.state.TabletStateStore) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) Range(org.apache.accumulo.core.data.Range) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Assignment(org.apache.accumulo.server.manager.state.Assignment) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Iface(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface) TransactionWatcher(org.apache.accumulo.server.zookeeper.TransactionWatcher) ServerContext(org.apache.accumulo.server.ServerContext) MetaDataTableScanner(org.apache.accumulo.server.manager.state.MetaDataTableScanner) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState)

Aggregations

Range (org.apache.accumulo.core.data.Range)3 TableId (org.apache.accumulo.core.data.TableId)3 TabletLocationState (org.apache.accumulo.core.metadata.TabletLocationState)3 MetaDataTableScanner (org.apache.accumulo.server.manager.state.MetaDataTableScanner)3 ArrayList (java.util.ArrayList)2 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)2 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)2 GET (jakarta.ws.rs.GET)1 Path (jakarta.ws.rs.Path)1 TreeSet (java.util.TreeSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)1 TRange (org.apache.accumulo.core.dataImpl.thrift.TRange)1 TRowRange (org.apache.accumulo.core.dataImpl.thrift.TRowRange)1 ManagerMonitorInfo (org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo)1 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)1 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)1 Iface (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface)1 Processor (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor)1 HostAndPort (org.apache.accumulo.core.util.HostAndPort)1