Search in sources :

Example 6 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class Master method displayUnassigned.

// The number of unassigned tablets that should be assigned: displayed on the monitor page
int displayUnassigned() {
    int result = 0;
    switch(getMasterState()) {
        case NORMAL:
            // Count offline tablets for online tables
            for (TabletGroupWatcher watcher : watchers) {
                TableManager manager = TableManager.getInstance();
                for (Entry<Table.ID, TableCounts> entry : watcher.getStats().entrySet()) {
                    Table.ID tableId = entry.getKey();
                    TableCounts counts = entry.getValue();
                    TableState tableState = manager.getTableState(tableId);
                    if (tableState != null && tableState.equals(TableState.ONLINE)) {
                        result += counts.unassigned() + counts.assignedToDeadServers() + counts.assigned() + counts.suspended();
                    }
                }
            }
            break;
        case SAFE_MODE:
            // Count offline tablets for the metadata table
            for (TabletGroupWatcher watcher : watchers) {
                TableCounts counts = watcher.getStats(MetadataTable.ID);
                result += counts.unassigned() + counts.suspended();
            }
            break;
        case UNLOAD_METADATA_TABLETS:
        case UNLOAD_ROOT_TABLET:
            for (TabletGroupWatcher watcher : watchers) {
                TableCounts counts = watcher.getStats(MetadataTable.ID);
                result += counts.unassigned() + counts.suspended();
            }
            break;
        default:
            break;
    }
    return result;
}
Also used : RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TableManager(org.apache.accumulo.server.tables.TableManager) TableCounts(org.apache.accumulo.master.state.TableCounts) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Example 7 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class ChangeTableState method call.

@Override
public Repo<Master> call(long tid, Master env) throws Exception {
    TableState ts = TableState.ONLINE;
    if (top == TableOperation.OFFLINE)
        ts = TableState.OFFLINE;
    TableManager.getInstance().transitionTableState(tableId, ts);
    Utils.unreserveNamespace(namespaceId, tid, false);
    Utils.unreserveTable(tableId, tid, true);
    LoggerFactory.getLogger(ChangeTableState.class).debug("Changed table state {} {}", tableId, ts);
    env.getEventCoordinator().event("Set table state of %s to %s", tableId, ts);
    return null;
}
Also used : TableState(org.apache.accumulo.core.master.state.tables.TableState)

Example 8 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class RandomizeVolumes method randomize.

public static int randomize(Connector c, String tableName) throws IOException, AccumuloSecurityException, AccumuloException, TableNotFoundException {
    final VolumeManager vm = VolumeManagerImpl.get();
    if (vm.getVolumes().size() < 2) {
        log.error("There are not enough volumes configured");
        return 1;
    }
    String tblStr = c.tableOperations().tableIdMap().get(tableName);
    if (null == tblStr) {
        log.error("Could not determine the table ID for table {}", tableName);
        return 2;
    }
    Table.ID tableId = Table.ID.of(tblStr);
    TableState tableState = TableManager.getInstance().getTableState(tableId);
    if (TableState.OFFLINE != tableState) {
        log.info("Taking {} offline", tableName);
        c.tableOperations().offline(tableName, true);
        log.info("{} offline", tableName);
    }
    SimpleThreadPool pool = new SimpleThreadPool(50, "directory maker");
    log.info("Rewriting entries for {}", tableName);
    Scanner scanner = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
    DIRECTORY_COLUMN.fetch(scanner);
    scanner.setRange(TabletsSection.getRange(tableId));
    BatchWriter writer = c.createBatchWriter(MetadataTable.NAME, null);
    int count = 0;
    for (Entry<Key, Value> entry : scanner) {
        String oldLocation = entry.getValue().toString();
        String directory;
        if (oldLocation.contains(":")) {
            String[] parts = oldLocation.split(Path.SEPARATOR);
            Table.ID tableIdEntry = Table.ID.of(parts[parts.length - 2]);
            if (!tableIdEntry.equals(tableId)) {
                log.error("Unexpected table id found: {}, expected {}; skipping", tableIdEntry, tableId);
                continue;
            }
            directory = parts[parts.length - 1];
        } else {
            directory = oldLocation.substring(Path.SEPARATOR.length());
        }
        Key key = entry.getKey();
        Mutation m = new Mutation(key.getRow());
        VolumeChooserEnvironment chooserEnv = new VolumeChooserEnvironment(tableId);
        final String newLocation = vm.choose(chooserEnv, ServerConstants.getBaseUris()) + Path.SEPARATOR + ServerConstants.TABLE_DIR + Path.SEPARATOR + tableId + Path.SEPARATOR + directory;
        m.put(key.getColumnFamily(), key.getColumnQualifier(), new Value(newLocation.getBytes(UTF_8)));
        if (log.isTraceEnabled()) {
            log.trace("Replacing {} with {}", oldLocation, newLocation);
        }
        writer.addMutation(m);
        pool.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    vm.mkdirs(new Path(newLocation));
                } catch (IOException ex) {
                // nevermind
                }
            }
        });
        count++;
    }
    writer.close();
    pool.shutdown();
    while (!pool.isTerminated()) {
        log.trace("Waiting for mkdir() calls to finish");
        try {
            pool.awaitTermination(5, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            break;
        }
    }
    log.info("Updated {} entries for table {}", count, tableName);
    if (TableState.OFFLINE != tableState) {
        c.tableOperations().online(tableName, true);
        log.info("table {} back online", tableName);
    }
    return 0;
}
Also used : Path(org.apache.hadoop.fs.Path) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) Scanner(org.apache.accumulo.core.client.Scanner) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Table(org.apache.accumulo.core.client.impl.Table) ClientOnRequiredTable(org.apache.accumulo.core.cli.ClientOnRequiredTable) IOException(java.io.IOException) VolumeChooserEnvironment(org.apache.accumulo.server.fs.VolumeChooserEnvironment) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) SimpleThreadPool(org.apache.accumulo.core.util.SimpleThreadPool) Key(org.apache.accumulo.core.data.Key) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Example 9 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class TableChangeStateIT method getTableState.

/**
 * Returns the current table state (ONLINE, OFFLINE,...) of named table.
 *
 * @param tableName
 *          the table name
 * @return the current table state
 * @throws TableNotFoundException
 *           if table does not exist
 */
private TableState getTableState(String tableName) throws TableNotFoundException {
    Table.ID tableId = Tables.getTableId(connector.getInstance(), tableName);
    TableState tstate = Tables.getTableState(connector.getInstance(), tableId);
    log.trace("tableName: '{}': tableId {}, current state: {}", tableName, tableId, tstate);
    return tstate;
}
Also used : Table(org.apache.accumulo.core.client.impl.Table) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Example 10 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class TableOperationsImpl method online.

@Override
public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
    checkArgument(tableName != null, "tableName is null");
    Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
    /**
     * ACCUMULO-4574 if table is already online return without executing fate operation.
     */
    TableState expectedState = Tables.getTableState(context.getInstance(), tableId, true);
    if (expectedState == TableState.ONLINE) {
        if (wait)
            waitForTableStateTransition(tableId, TableState.ONLINE);
        return;
    }
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getUtf8()));
    Map<String, String> opts = new HashMap<>();
    try {
        doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_ONLINE, args, opts);
    } catch (TableExistsException e) {
        // should not happen
        throw new AssertionError(e);
    }
    if (wait)
        waitForTableStateTransition(tableId, TableState.ONLINE);
}
Also used : RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) HashMap(java.util.HashMap) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ByteBuffer(java.nio.ByteBuffer) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Aggregations

TableState (org.apache.accumulo.core.master.state.tables.TableState)10 Table (org.apache.accumulo.core.client.impl.Table)5 MetadataTable (org.apache.accumulo.core.metadata.MetadataTable)5 RootTable (org.apache.accumulo.core.metadata.RootTable)4 TableManager (org.apache.accumulo.server.tables.TableManager)3 Scanner (org.apache.accumulo.core.client.Scanner)2 Key (org.apache.accumulo.core.data.Key)2 Value (org.apache.accumulo.core.data.Value)2 ReplicationTable (org.apache.accumulo.core.replication.ReplicationTable)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ZipEntry (java.util.zip.ZipEntry)1 GET (javax.ws.rs.GET)1 ClientOnRequiredTable (org.apache.accumulo.core.cli.ClientOnRequiredTable)1