Search in sources :

Example 1 with MetaDataTableScanner

use of org.apache.accumulo.server.master.state.MetaDataTableScanner in project accumulo by apache.

the class FindOfflineTablets method findOffline.

static int findOffline(ClientContext context, String tableName) throws AccumuloException, 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;
    try {
        zooScanner = new ZooTabletStateStore().iterator();
    } catch (DistributedStoreException e) {
        throw new AccumuloException(e);
    }
    int offline = 0;
    System.out.println("Scanning zookeeper");
    if ((offline = checkTablets(zooScanner, tservers)) > 0)
        return offline;
    if (RootTable.NAME.equals(tableName))
        return 0;
    System.out.println("Scanning " + RootTable.NAME);
    Iterator<TabletLocationState> rootScanner = new MetaDataTableScanner(context, MetadataSchema.TabletsSection.getRange(), RootTable.NAME);
    if ((offline = checkTablets(rootScanner, tservers)) > 0)
        return offline;
    if (MetadataTable.NAME.equals(tableName))
        return 0;
    System.out.println("Scanning " + MetadataTable.NAME);
    Range range = MetadataSchema.TabletsSection.getRange();
    if (tableName != null) {
        Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
        range = new KeyExtent(tableId, null, null).toMetadataRange();
    }
    try (MetaDataTableScanner metaScanner = new MetaDataTableScanner(context, range, MetadataTable.NAME)) {
        return checkTablets(metaScanner, tservers);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) Listener(org.apache.accumulo.server.master.LiveTServerSet.Listener) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) DistributedStoreException(org.apache.accumulo.server.master.state.DistributedStoreException) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) LiveTServerSet(org.apache.accumulo.server.master.LiveTServerSet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MetaDataTableScanner(org.apache.accumulo.server.master.state.MetaDataTableScanner) TabletLocationState(org.apache.accumulo.server.master.state.TabletLocationState) ZooTabletStateStore(org.apache.accumulo.server.master.state.ZooTabletStateStore)

Example 2 with MetaDataTableScanner

use of org.apache.accumulo.server.master.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) {
    Instance instance = Monitor.getContext().getInstance();
    Table.ID tableId = Table.ID.of(tableIdStr);
    TabletServers tabletServers = new TabletServers(Monitor.getMmi().tServerInfo.size());
    if (StringUtils.isBlank(tableIdStr)) {
        return tabletServers;
    }
    TreeSet<String> locs = new TreeSet<>();
    if (RootTable.ID.equals(tableId)) {
        locs.add(instance.getRootTabletLocation());
    } else {
        String systemTableName = MetadataTable.ID.equals(tableId) ? RootTable.NAME : MetadataTable.NAME;
        MetaDataTableScanner scanner = new MetaDataTableScanner(Monitor.getContext(), new Range(KeyExtent.getMetadataEntry(tableId, new Text()), KeyExtent.getMetadataEntry(tableId, null)), systemTableName);
        while (scanner.hasNext()) {
            TabletLocationState state = scanner.next();
            if (state.current != null) {
                try {
                    locs.add(state.current.hostPort());
                } catch (Exception ex) {
                    scanner.close();
                    return tabletServers;
                }
            }
        }
        scanner.close();
    }
    List<TabletServerStatus> tservers = new ArrayList<>();
    if (Monitor.getMmi() != null) {
        for (TabletServerStatus tss : Monitor.getMmi().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 = TableInfoUtil.summarizeTableStats(status);
        if (tableId != null)
            summary = status.tableMap.get(tableId.canonicalID());
        if (summary == null)
            continue;
        TabletServer tabletServerInfo = new TabletServer();
        tabletServerInfo.updateTabletServerInfo(status, summary);
        tabletServers.addTablet(tabletServerInfo);
    }
    return tabletServers;
}
Also used : MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) 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.master.state.MetaDataTableScanner) TabletServer(org.apache.accumulo.monitor.rest.tservers.TabletServer) TabletLocationState(org.apache.accumulo.server.master.state.TabletLocationState) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with MetaDataTableScanner

use of org.apache.accumulo.server.master.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
    ZooKeeperInstance zki = new ZooKeeperInstance(ClientConfiguration.create().withInstance(opts.iname).withZkHosts(opts.keepers));
    Instance inst = HdfsZooInstance.getInstance();
    AccumuloServerContext context = new AccumuloServerContext(inst, new ServerConfigurationFactory(zki));
    TransactionWatcher watcher = new TransactionWatcher();
    ThriftClientHandler tch = new ThriftClientHandler(new AccumuloServerContext(inst, new ServerConfigurationFactory(inst)), watcher);
    Processor<Iface> processor = new Processor<>(tch);
    TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, processor, "NullTServer", "null tserver", 2, 1, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", opts.port));
    HostAndPort addr = HostAndPort.fromParts(InetAddress.getLocalHost().getHostName(), opts.port);
    Table.ID tableId = Tables.getTableId(zki, opts.tableName);
    // read the locations for the table
    Range tableRange = new KeyExtent(tableId, null, null).toMetadataRange();
    List<Assignment> assignments = new ArrayList<>();
    try (MetaDataTableScanner s = new MetaDataTableScanner(context, tableRange)) {
        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
    MetaDataStateStore store = new MetaDataStateStore(context);
    store.setLocations(assignments);
    while (true) {
        sleepUninterruptibly(10, TimeUnit.SECONDS);
    }
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Processor(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor) Table(org.apache.accumulo.core.client.impl.Table) Instance(org.apache.accumulo.core.client.Instance) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ArrayList(java.util.ArrayList) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) TRowRange(org.apache.accumulo.core.data.thrift.TRowRange) TRange(org.apache.accumulo.core.data.thrift.TRange) Range(org.apache.accumulo.core.data.Range) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) Assignment(org.apache.accumulo.server.master.state.Assignment) MetaDataStateStore(org.apache.accumulo.server.master.state.MetaDataStateStore) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Iface(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface) TransactionWatcher(org.apache.accumulo.server.zookeeper.TransactionWatcher) MetaDataTableScanner(org.apache.accumulo.server.master.state.MetaDataTableScanner) TabletLocationState(org.apache.accumulo.server.master.state.TabletLocationState)

Example 4 with MetaDataTableScanner

use of org.apache.accumulo.server.master.state.MetaDataTableScanner in project accumulo by apache.

the class MasterAssignmentIT method getTabletLocationState.

private TabletLocationState getTabletLocationState(Connector c, String tableId) throws FileNotFoundException, ConfigurationException {
    Credentials creds = new Credentials(getAdminPrincipal(), getAdminToken());
    ClientContext context = new ClientContext(c.getInstance(), creds, getCluster().getClientConfig());
    try (MetaDataTableScanner s = new MetaDataTableScanner(context, new Range(KeyExtent.getMetadataEntry(Table.ID.of(tableId), null)))) {
        TabletLocationState tlState = s.next();
        return tlState;
    }
}
Also used : MetaDataTableScanner(org.apache.accumulo.server.master.state.MetaDataTableScanner) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) TabletLocationState(org.apache.accumulo.server.master.state.TabletLocationState) Range(org.apache.accumulo.core.data.Range) Credentials(org.apache.accumulo.core.client.impl.Credentials)

Aggregations

Range (org.apache.accumulo.core.data.Range)4 MetaDataTableScanner (org.apache.accumulo.server.master.state.MetaDataTableScanner)4 TabletLocationState (org.apache.accumulo.server.master.state.TabletLocationState)4 Table (org.apache.accumulo.core.client.impl.Table)3 ArrayList (java.util.ArrayList)2 Instance (org.apache.accumulo.core.client.Instance)2 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)2 MetadataTable (org.apache.accumulo.core.metadata.MetadataTable)2 RootTable (org.apache.accumulo.core.metadata.RootTable)2 HdfsZooInstance (org.apache.accumulo.server.client.HdfsZooInstance)2 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)2 TreeSet (java.util.TreeSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)1 ClientContext (org.apache.accumulo.core.client.impl.ClientContext)1 Credentials (org.apache.accumulo.core.client.impl.Credentials)1 TKeyExtent (org.apache.accumulo.core.data.thrift.TKeyExtent)1