Search in sources :

Example 1 with TableOfflineException

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

the class ReplicationIT method getAllLogs.

private Multimap<String, Table.ID> getAllLogs(Connector conn) throws Exception {
    Multimap<String, Table.ID> logs = getLogs(conn);
    try (Scanner scanner = conn.createScanner(ReplicationTable.NAME, Authorizations.EMPTY)) {
        StatusSection.limit(scanner);
        Text buff = new Text();
        for (Entry<Key, Value> entry : scanner) {
            if (Thread.interrupted()) {
                Thread.currentThread().interrupt();
                return logs;
            }
            StatusSection.getFile(entry.getKey(), buff);
            String file = buff.toString();
            Table.ID tableId = StatusSection.getTableId(entry.getKey());
            logs.put(file, tableId);
        }
    } catch (TableOfflineException e) {
        log.debug("Replication table isn't online yet");
    }
    return logs;
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) ReplicationTableOfflineException(org.apache.accumulo.core.replication.ReplicationTableOfflineException) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) UUID(java.util.UUID) Key(org.apache.accumulo.core.data.Key)

Example 2 with TableOfflineException

use of org.apache.accumulo.core.client.TableOfflineException 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 3 with TableOfflineException

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

the class TableOperationsImpl method summaries.

@Override
public SummaryRetriever summaries(String tableName) {
    return new SummaryRetriever() {

        private Text startRow = null;

        private Text endRow = null;

        private List<TSummarizerConfiguration> summariesToFetch = Collections.emptyList();

        private String summarizerClassRegex;

        private boolean flush = false;

        @Override
        public SummaryRetriever startRow(Text startRow) {
            Objects.requireNonNull(startRow);
            if (endRow != null) {
                Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
            }
            this.startRow = startRow;
            return this;
        }

        @Override
        public SummaryRetriever startRow(CharSequence startRow) {
            return startRow(new Text(startRow.toString()));
        }

        @Override
        public List<Summary> retrieve() throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
            Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
            if (Tables.getTableState(context.getInstance(), tableId) == TableState.OFFLINE)
                throw new TableOfflineException(context.getInstance(), tableId.canonicalID());
            TRowRange range = new TRowRange(TextUtil.getByteBuffer(startRow), TextUtil.getByteBuffer(endRow));
            TSummaryRequest request = new TSummaryRequest(tableId.canonicalID(), range, summariesToFetch, summarizerClassRegex);
            if (flush) {
                _flush(tableId, startRow, endRow, true);
            }
            TSummaries ret = ServerClient.execute(context, new TabletClientService.Client.Factory(), client -> {
                TSummaries tsr = client.startGetSummaries(Tracer.traceInfo(), context.rpcCreds(), request);
                while (!tsr.finished) {
                    tsr = client.contiuneGetSummaries(Tracer.traceInfo(), tsr.sessionId);
                }
                return tsr;
            });
            return new SummaryCollection(ret).getSummaries();
        }

        @Override
        public SummaryRetriever endRow(Text endRow) {
            Objects.requireNonNull(endRow);
            if (startRow != null) {
                Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
            }
            this.endRow = endRow;
            return this;
        }

        @Override
        public SummaryRetriever endRow(CharSequence endRow) {
            return endRow(new Text(endRow.toString()));
        }

        @Override
        public SummaryRetriever withConfiguration(Collection<SummarizerConfiguration> configs) {
            Objects.requireNonNull(configs);
            summariesToFetch = configs.stream().map(SummarizerConfigurationUtil::toThrift).collect(Collectors.toList());
            return this;
        }

        @Override
        public SummaryRetriever withConfiguration(SummarizerConfiguration... config) {
            Objects.requireNonNull(config);
            return withConfiguration(Arrays.asList(config));
        }

        @Override
        public SummaryRetriever withMatchingConfiguration(String regex) {
            Objects.requireNonNull(regex);
            // Do a sanity check here to make sure that regex compiles, instead of having it fail on a tserver.
            Pattern.compile(regex);
            this.summarizerClassRegex = regex;
            return this;
        }

        @Override
        public SummaryRetriever flush(boolean b) {
            this.flush = b;
            return this;
        }
    };
}
Also used : RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) Text(org.apache.hadoop.io.Text) SummarizerConfigurationUtil(org.apache.accumulo.core.summary.SummarizerConfigurationUtil) SummaryRetriever(org.apache.accumulo.core.client.admin.SummaryRetriever) TSummaryRequest(org.apache.accumulo.core.data.thrift.TSummaryRequest) TSummaries(org.apache.accumulo.core.data.thrift.TSummaries) Summary(org.apache.accumulo.core.client.summary.Summary) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) TRowRange(org.apache.accumulo.core.data.thrift.TRowRange) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.data.thrift.TSummarizerConfiguration)

Example 4 with TableOfflineException

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

the class TableOperationsImpl method doFateOperation.

String doFateOperation(FateOperation op, List<ByteBuffer> args, Map<String, String> opts, String tableOrNamespaceName, boolean wait) throws AccumuloSecurityException, TableExistsException, TableNotFoundException, AccumuloException, NamespaceExistsException, NamespaceNotFoundException {
    Long opid = null;
    try {
        opid = beginFateOperation();
        executeFateOperation(opid, op, args, opts, !wait);
        if (!wait) {
            opid = null;
            return null;
        }
        String ret = waitForFateOperation(opid);
        return ret;
    } catch (ThriftSecurityException e) {
        switch(e.getCode()) {
            case TABLE_DOESNT_EXIST:
                throw new TableNotFoundException(null, tableOrNamespaceName, "Target table does not exist");
            case NAMESPACE_DOESNT_EXIST:
                throw new NamespaceNotFoundException(null, tableOrNamespaceName, "Target namespace does not exist");
            default:
                String tableInfo = Tables.getPrintableTableInfoFromName(context.getInstance(), tableOrNamespaceName);
                throw new AccumuloSecurityException(e.user, e.code, tableInfo, e);
        }
    } catch (ThriftTableOperationException e) {
        switch(e.getType()) {
            case EXISTS:
                throw new TableExistsException(e);
            case NOTFOUND:
                throw new TableNotFoundException(e);
            case NAMESPACE_EXISTS:
                throw new NamespaceExistsException(e);
            case NAMESPACE_NOTFOUND:
                throw new NamespaceNotFoundException(e);
            case OFFLINE:
                throw new TableOfflineException(context.getInstance(), Tables.getTableId(context.getInstance(), tableOrNamespaceName).canonicalID());
            default:
                throw new AccumuloException(e.description, e);
        }
    } catch (Exception e) {
        throw new AccumuloException(e.getMessage(), e);
    } finally {
        Tables.clearCache(context.getInstance());
        // always finish table op, even when exception
        if (opid != null)
            try {
                finishFateOperation(opid);
            } catch (Exception e) {
                log.warn("Exception thrown while finishing fate table operation", e);
            }
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftNotActiveServiceException(org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) TTransportException(org.apache.thrift.transport.TTransportException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) FileNotFoundException(java.io.FileNotFoundException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TApplicationException(org.apache.thrift.TApplicationException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 5 with TableOfflineException

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

the class TabletServerBatchReaderIterator method binRanges.

private void binRanges(TabletLocator tabletLocator, List<Range> ranges, Map<String, Map<KeyExtent, List<Range>>> binnedRanges) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    int lastFailureSize = Integer.MAX_VALUE;
    while (true) {
        binnedRanges.clear();
        List<Range> failures = tabletLocator.binRanges(context, ranges, binnedRanges);
        if (failures.size() > 0) {
            // need to always do the check when failures occur
            if (failures.size() >= lastFailureSize)
                if (!Tables.exists(instance, tableId))
                    throw new TableDeletedException(tableId.canonicalID());
                else if (Tables.getTableState(instance, tableId) == TableState.OFFLINE)
                    throw new TableOfflineException(instance, tableId.canonicalID());
            lastFailureSize = failures.size();
            if (log.isTraceEnabled())
                log.trace("Failed to bin {} ranges, tablet locations were null, retrying in 100ms", failures.size());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        } else {
            break;
        }
    }
    // truncate the ranges to within the tablets... this makes it easier to know what work
    // needs to be redone when failures occurs and tablets have merged or split
    Map<String, Map<KeyExtent, List<Range>>> binnedRanges2 = new HashMap<>();
    for (Entry<String, Map<KeyExtent, List<Range>>> entry : binnedRanges.entrySet()) {
        Map<KeyExtent, List<Range>> tabletMap = new HashMap<>();
        binnedRanges2.put(entry.getKey(), tabletMap);
        for (Entry<KeyExtent, List<Range>> tabletRanges : entry.getValue().entrySet()) {
            Range tabletRange = tabletRanges.getKey().toDataRange();
            List<Range> clippedRanges = new ArrayList<>();
            tabletMap.put(tabletRanges.getKey(), clippedRanges);
            for (Range range : tabletRanges.getValue()) clippedRanges.add(tabletRange.clip(range));
        }
    }
    binnedRanges.clear();
    binnedRanges.putAll(binnedRanges2);
}
Also used : TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

TableOfflineException (org.apache.accumulo.core.client.TableOfflineException)18 ArrayList (java.util.ArrayList)12 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)10 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)10 Range (org.apache.accumulo.core.data.Range)9 HashMap (java.util.HashMap)8 TableDeletedException (org.apache.accumulo.core.client.TableDeletedException)8 Text (org.apache.hadoop.io.Text)8 List (java.util.List)7 Map (java.util.Map)6 MetadataTable (org.apache.accumulo.core.metadata.MetadataTable)6 LinkedList (java.util.LinkedList)5 Connector (org.apache.accumulo.core.client.Connector)5 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)5 RootTable (org.apache.accumulo.core.metadata.RootTable)5 IOException (java.io.IOException)4 Table (org.apache.accumulo.core.client.impl.Table)4 TApplicationException (org.apache.thrift.TApplicationException)4 TException (org.apache.thrift.TException)4