Search in sources :

Example 6 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TableOperationsImpl method locate.

@Override
public Locations locate(String tableName, Collection<Range> ranges) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    EXISTING_TABLE_NAME.validate(tableName);
    requireNonNull(ranges, "ranges must be non null");
    TableId tableId = context.getTableId(tableName);
    TabletLocator locator = TabletLocator.getLocator(context, tableId);
    List<Range> rangeList = null;
    if (ranges instanceof List) {
        rangeList = (List<Range>) ranges;
    } else {
        rangeList = new ArrayList<>(ranges);
    }
    Map<String, Map<KeyExtent, List<Range>>> binnedRanges = new HashMap<>();
    locator.invalidateCache();
    Retry retry = Retry.builder().infiniteRetries().retryAfter(100, MILLISECONDS).incrementBy(100, MILLISECONDS).maxWait(2, SECONDS).backOffFactor(1.5).logInterval(3, MINUTES).createRetry();
    while (!locator.binRanges(context, rangeList, binnedRanges).isEmpty()) {
        context.requireTableExists(tableId, tableName);
        context.requireNotOffline(tableId, tableName);
        binnedRanges.clear();
        try {
            retry.waitForNextAttempt();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        locator.invalidateCache();
    }
    return new LocationsImpl(binnedRanges);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) HashMap(java.util.HashMap) Range(org.apache.accumulo.core.data.Range) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Retry(org.apache.accumulo.fate.util.Retry) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 7 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TableOperationsImpl method offline.

@Override
public void offline(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
    EXISTING_TABLE_NAME.validate(tableName);
    TableId tableId = context.getTableId(tableName);
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.canonical().getBytes(UTF_8)));
    Map<String, String> opts = new HashMap<>();
    try {
        doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_OFFLINE, args, opts);
    } catch (TableExistsException e) {
        // should not happen
        throw new AssertionError(e);
    }
    if (wait)
        waitForTableStateTransition(tableId, TableState.OFFLINE);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) HashMap(java.util.HashMap) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ByteBuffer(java.nio.ByteBuffer)

Example 8 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TableOperationsImpl method cancelCompaction.

@Override
public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
    EXISTING_TABLE_NAME.validate(tableName);
    TableId tableId = context.getTableId(tableName);
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.canonical().getBytes(UTF_8)));
    Map<String, String> opts = new HashMap<>();
    try {
        doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_CANCEL_COMPACT, args, opts);
    } catch (TableExistsException e) {
        // should not happen
        throw new AssertionError(e);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) HashMap(java.util.HashMap) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ByteBuffer(java.nio.ByteBuffer)

Example 9 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TableOperationsImpl method isOnline.

@Override
public boolean isOnline(String tableName) throws AccumuloException, TableNotFoundException {
    EXISTING_TABLE_NAME.validate(tableName);
    TableId tableId = context.getTableId(tableName);
    TableState expectedState = context.getTableState(tableId, true);
    return expectedState == TableState.ONLINE;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableState(org.apache.accumulo.core.manager.state.tables.TableState)

Example 10 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TableOperationsImpl method online.

@Override
public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
    EXISTING_TABLE_NAME.validate(tableName);
    TableId tableId = context.getTableId(tableName);
    /**
     * ACCUMULO-4574 if table is already online return without executing fate operation.
     */
    if (isOnline(tableName)) {
        if (wait)
            waitForTableStateTransition(tableId, TableState.ONLINE);
        return;
    }
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.canonical().getBytes(UTF_8)));
    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 : TableId(org.apache.accumulo.core.data.TableId) HashMap(java.util.HashMap) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TableId (org.apache.accumulo.core.data.TableId)169 Text (org.apache.hadoop.io.Text)64 HashMap (java.util.HashMap)55 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)55 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)43 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)41 Map (java.util.Map)37 Key (org.apache.accumulo.core.data.Key)36 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)34 HashSet (java.util.HashSet)31 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)31 Value (org.apache.accumulo.core.data.Value)31 IOException (java.io.IOException)28 Scanner (org.apache.accumulo.core.client.Scanner)28 AccumuloException (org.apache.accumulo.core.client.AccumuloException)27 Mutation (org.apache.accumulo.core.data.Mutation)27 List (java.util.List)26 Range (org.apache.accumulo.core.data.Range)24 BatchWriter (org.apache.accumulo.core.client.BatchWriter)23