Search in sources :

Example 41 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class StatusMaker method run.

public void run() {
    Span span = Trace.start("replicationStatusMaker");
    try {
        // Read from a source table (typically accumulo.metadata)
        final Scanner s;
        try {
            s = conn.createScanner(sourceTableName, Authorizations.EMPTY);
        } catch (TableNotFoundException e) {
            throw new RuntimeException(e);
        }
        // Only pull replication records
        s.fetchColumnFamily(ReplicationSection.COLF);
        s.setRange(ReplicationSection.getRange());
        Text file = new Text();
        for (Entry<Key, Value> entry : s) {
            // Get a writer to the replication table
            if (null == replicationWriter) {
                // Ensures table is online
                try {
                    ReplicationTable.setOnline(conn);
                    replicationWriter = ReplicationTable.getBatchWriter(conn);
                } catch (ReplicationTableOfflineException | AccumuloSecurityException | AccumuloException e) {
                    log.warn("Replication table did not come online");
                    replicationWriter = null;
                    return;
                }
            }
            // Extract the useful bits from the status key
            MetadataSchema.ReplicationSection.getFile(entry.getKey(), file);
            Table.ID tableId = MetadataSchema.ReplicationSection.getTableId(entry.getKey());
            Status status;
            try {
                status = Status.parseFrom(entry.getValue().get());
            } catch (InvalidProtocolBufferException e) {
                log.warn("Could not deserialize protobuf for {}", file);
                continue;
            }
            log.debug("Creating replication status record for {} on table {} with {}.", file, tableId, ProtobufUtil.toString(status));
            Span workSpan = Trace.start("createStatusMutations");
            try {
                // Create entries in the replication table from the metadata table
                if (!addStatusRecord(file, tableId, entry.getValue())) {
                    continue;
                }
            } finally {
                workSpan.stop();
            }
            if (status.getClosed()) {
                Span orderSpan = Trace.start("recordStatusOrder");
                try {
                    if (!addOrderRecord(file, tableId, status, entry.getValue())) {
                        continue;
                    }
                } finally {
                    orderSpan.stop();
                }
                Span deleteSpan = Trace.start("deleteClosedStatus");
                try {
                    deleteStatusRecord(entry.getKey());
                } finally {
                    deleteSpan.stop();
                }
            }
        }
    } finally {
        span.stop();
    }
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) Scanner(org.apache.accumulo.core.client.Scanner) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Text(org.apache.hadoop.io.Text) Span(org.apache.accumulo.core.trace.Span) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ReplicationTableOfflineException(org.apache.accumulo.core.replication.ReplicationTableOfflineException) Key(org.apache.accumulo.core.data.Key)

Example 42 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class TableOperationsImpl method compact.

@Override
public void compact(String tableName, CompactionConfig config) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
    checkArgument(tableName != null, "tableName is null");
    ByteBuffer EMPTY = ByteBuffer.allocate(0);
    // Ensure compaction iterators exist on a tabletserver
    final String skviName = SortedKeyValueIterator.class.getName();
    for (IteratorSetting setting : config.getIterators()) {
        String iteratorClass = setting.getIteratorClass();
        if (!testClassLoad(tableName, iteratorClass, skviName)) {
            throw new AccumuloException("TabletServer could not load iterator class " + iteratorClass);
        }
    }
    // Make sure the specified compaction strategy exists on a tabletserver
    final String compactionStrategyName = config.getCompactionStrategy().getClassName();
    if (!CompactionStrategyConfigUtil.DEFAULT_STRATEGY.getClassName().equals(compactionStrategyName)) {
        if (!testClassLoad(tableName, compactionStrategyName, "org.apache.accumulo.tserver.compaction.CompactionStrategy")) {
            throw new AccumuloException("TabletServer could not load CompactionStrategy class " + compactionStrategyName);
        }
    }
    Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
    Text start = config.getStartRow();
    Text end = config.getEndRow();
    if (config.getFlush())
        _flush(tableId, start, end, true);
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getUtf8()), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY : TextUtil.getByteBuffer(end), ByteBuffer.wrap(IteratorUtil.encodeIteratorSettings(config.getIterators())), ByteBuffer.wrap(CompactionStrategyConfigUtil.encode(config.getCompactionStrategy())));
    Map<String, String> opts = new HashMap<>();
    try {
        doFateOperation(FateOperation.TABLE_COMPACT, args, opts, tableName, config.getWait());
    } catch (TableExistsException | NamespaceExistsException e) {
        // should not happen
        throw new AssertionError(e);
    } catch (NamespaceNotFoundException e) {
        throw new TableNotFoundException(null, tableName, "Namespace not found", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) ByteBuffer(java.nio.ByteBuffer) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Example 43 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class TableOperationsImpl method importTable.

@Override
public void importTable(String tableName, String importDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {
    checkArgument(tableName != null, "tableName is null");
    checkArgument(importDir != null, "importDir is null");
    try {
        importDir = checkPath(importDir, "Table", "").toString();
    } catch (IOException e) {
        throw new AccumuloException(e);
    }
    try {
        FileSystem fs = new Path(importDir).getFileSystem(CachedConfiguration.getInstance());
        Map<String, String> props = getExportedProps(fs, new Path(importDir, Constants.EXPORT_FILE));
        for (Entry<String, String> entry : props.entrySet()) {
            if (Property.isClassProperty(entry.getKey()) && !entry.getValue().contains(Constants.CORE_PACKAGE_NAME)) {
                LoggerFactory.getLogger(this.getClass()).info("Imported table sets '{}' to '{}'.  Ensure this class is on Accumulo classpath.", entry.getKey(), entry.getValue());
            }
        }
    } catch (IOException ioe) {
        LoggerFactory.getLogger(this.getClass()).warn("Failed to check if imported table references external java classes : {}", ioe.getMessage());
    }
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(UTF_8)), ByteBuffer.wrap(importDir.getBytes(UTF_8)));
    Map<String, String> opts = Collections.emptyMap();
    try {
        doTableFateOperation(tableName, AccumuloException.class, FateOperation.TABLE_IMPORT, args, opts);
    } catch (TableNotFoundException e) {
        // should not happen
        throw new AssertionError(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 44 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class TableOperationsImpl method addSplits.

private void addSplits(String tableName, SortedSet<Text> partitionKeys, Table.ID tableId) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, AccumuloServerException {
    TabletLocator tabLocator = TabletLocator.getLocator(context, tableId);
    for (Text split : partitionKeys) {
        boolean successful = false;
        int attempt = 0;
        long locationFailures = 0;
        while (!successful) {
            if (attempt > 0)
                sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            attempt++;
            TabletLocation tl = tabLocator.locateTablet(context, split, false, false);
            if (tl == null) {
                if (!Tables.exists(context.getInstance(), tableId))
                    throw new TableNotFoundException(tableId.canonicalID(), tableName, null);
                else if (Tables.getTableState(context.getInstance(), tableId) == TableState.OFFLINE)
                    throw new TableOfflineException(context.getInstance(), tableId.canonicalID());
                continue;
            }
            HostAndPort address = HostAndPort.fromString(tl.tablet_location);
            try {
                TabletClientService.Client client = ThriftUtil.getTServerClient(address, context);
                try {
                    OpTimer timer = null;
                    if (log.isTraceEnabled()) {
                        log.trace("tid={} Splitting tablet {} on {} at {}", Thread.currentThread().getId(), tl.tablet_extent, address, split);
                        timer = new OpTimer().start();
                    }
                    client.splitTablet(Tracer.traceInfo(), context.rpcCreds(), tl.tablet_extent.toThrift(), TextUtil.getByteBuffer(split));
                    // just split it, might as well invalidate it in the cache
                    tabLocator.invalidateCache(tl.tablet_extent);
                    if (timer != null) {
                        timer.stop();
                        log.trace("Split tablet in {}", String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
                    }
                } finally {
                    ThriftUtil.returnClient(client);
                }
            } catch (TApplicationException tae) {
                throw new AccumuloServerException(address.toString(), tae);
            } catch (TTransportException e) {
                tabLocator.invalidateCache(context.getInstance(), tl.tablet_location);
                continue;
            } catch (ThriftSecurityException e) {
                Tables.clearCache(context.getInstance());
                if (!Tables.exists(context.getInstance(), tableId))
                    throw new TableNotFoundException(tableId.canonicalID(), tableName, null);
                throw new AccumuloSecurityException(e.user, e.code, e);
            } catch (NotServingTabletException e) {
                // Do not silently spin when we repeatedly fail to get the location for a tablet
                locationFailures++;
                if (5 == locationFailures || 0 == locationFailures % 50) {
                    log.warn("Having difficulty locating hosting tabletserver for split {} on table {}. Seen {} failures.", split, tableName, locationFailures);
                }
                tabLocator.invalidateCache(tl.tablet_extent);
                continue;
            } catch (TException e) {
                tabLocator.invalidateCache(context.getInstance(), tl.tablet_location);
                continue;
            }
            successful = true;
        }
    }
}
Also used : TException(org.apache.thrift.TException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) TTransportException(org.apache.thrift.transport.TTransportException) Text(org.apache.hadoop.io.Text) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) Constraint(org.apache.accumulo.core.constraints.Constraint) TApplicationException(org.apache.thrift.TApplicationException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) TabletLocation(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation) OpTimer(org.apache.accumulo.core.util.OpTimer) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService)

Example 45 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class TableOperationsImpl method waitForTableStateTransition.

private void waitForTableStateTransition(Table.ID tableId, TableState expectedState) throws AccumuloException, TableNotFoundException, AccumuloSecurityException {
    Text startRow = null;
    Text lastRow = null;
    while (true) {
        if (Tables.getTableState(context.getInstance(), tableId) != expectedState) {
            Tables.clearCache(context.getInstance());
            TableState currentState = Tables.getTableState(context.getInstance(), tableId);
            if (currentState != expectedState) {
                if (!Tables.exists(context.getInstance(), tableId))
                    throw new TableDeletedException(tableId.canonicalID());
                if (currentState == TableState.DELETING)
                    throw new TableNotFoundException(tableId.canonicalID(), "", "Table is being deleted.");
                throw new AccumuloException("Unexpected table state " + tableId + " " + Tables.getTableState(context.getInstance(), tableId) + " != " + expectedState);
            }
        }
        Range range;
        if (startRow == null || lastRow == null)
            range = new KeyExtent(tableId, null, null).toMetadataRange();
        else
            range = new Range(startRow, lastRow);
        String metaTable = MetadataTable.NAME;
        if (tableId.equals(MetadataTable.ID))
            metaTable = RootTable.NAME;
        Scanner scanner = createMetadataScanner(metaTable, range);
        RowIterator rowIter = new RowIterator(scanner);
        KeyExtent lastExtent = null;
        int total = 0;
        int waitFor = 0;
        int holes = 0;
        Text continueRow = null;
        MapCounter<String> serverCounts = new MapCounter<>();
        while (rowIter.hasNext()) {
            Iterator<Entry<Key, Value>> row = rowIter.next();
            total++;
            KeyExtent extent = null;
            String future = null;
            String current = null;
            while (row.hasNext()) {
                Entry<Key, Value> entry = row.next();
                Key key = entry.getKey();
                if (key.getColumnFamily().equals(TabletsSection.FutureLocationColumnFamily.NAME))
                    future = entry.getValue().toString();
                if (key.getColumnFamily().equals(TabletsSection.CurrentLocationColumnFamily.NAME))
                    current = entry.getValue().toString();
                if (TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.hasColumns(key))
                    extent = new KeyExtent(key.getRow(), entry.getValue());
            }
            if ((expectedState == TableState.ONLINE && current == null) || (expectedState == TableState.OFFLINE && (future != null || current != null))) {
                if (continueRow == null)
                    continueRow = extent.getMetadataEntry();
                waitFor++;
                lastRow = extent.getMetadataEntry();
                if (current != null)
                    serverCounts.increment(current, 1);
                if (future != null)
                    serverCounts.increment(future, 1);
            }
            if (!extent.getTableId().equals(tableId)) {
                throw new AccumuloException("Saw unexpected table Id " + tableId + " " + extent);
            }
            if (lastExtent != null && !extent.isPreviousExtent(lastExtent)) {
                holes++;
            }
            lastExtent = extent;
        }
        if (continueRow != null) {
            startRow = continueRow;
        }
        if (holes > 0 || total == 0) {
            startRow = null;
            lastRow = null;
        }
        if (waitFor > 0 || holes > 0 || total == 0) {
            long waitTime;
            long maxPerServer = 0;
            if (serverCounts.size() > 0) {
                maxPerServer = Collections.max(serverCounts.values());
                waitTime = maxPerServer * 10;
            } else
                waitTime = waitFor * 10;
            waitTime = Math.max(100, waitTime);
            waitTime = Math.min(5000, waitTime);
            log.trace("Waiting for {}({}) tablets, startRow = {} lastRow = {}, holes={} sleeping:{}ms", waitFor, maxPerServer, startRow, lastRow, holes, waitTime);
            sleepUninterruptibly(waitTime, TimeUnit.MILLISECONDS);
        } else {
            break;
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) Text(org.apache.hadoop.io.Text) TRowRange(org.apache.accumulo.core.data.thrift.TRowRange) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) Constraint(org.apache.accumulo.core.constraints.Constraint) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) RowIterator(org.apache.accumulo.core.client.RowIterator) MapCounter(org.apache.accumulo.core.util.MapCounter) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Aggregations

TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)160 AccumuloException (org.apache.accumulo.core.client.AccumuloException)100 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)89 Text (org.apache.hadoop.io.Text)51 Value (org.apache.accumulo.core.data.Value)46 Key (org.apache.accumulo.core.data.Key)42 Scanner (org.apache.accumulo.core.client.Scanner)36 IOException (java.io.IOException)34 BatchWriter (org.apache.accumulo.core.client.BatchWriter)31 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)31 Connector (org.apache.accumulo.core.client.Connector)30 Mutation (org.apache.accumulo.core.data.Mutation)29 Range (org.apache.accumulo.core.data.Range)28 Authorizations (org.apache.accumulo.core.security.Authorizations)26 ArrayList (java.util.ArrayList)25 Entry (java.util.Map.Entry)25 TableExistsException (org.apache.accumulo.core.client.TableExistsException)25 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)23 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)23 HashMap (java.util.HashMap)19