Search in sources :

Example 11 with TableOfflineException

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

the class ReplicationResource method getReplicationInformation.

/**
 * Generates the replication table as a JSON object
 *
 * @return Replication list
 */
@GET
public List<ReplicationInformation> getReplicationInformation() throws AccumuloException, AccumuloSecurityException {
    final Connector conn = Monitor.getContext().getConnector();
    final TableOperations tops = conn.tableOperations();
    final Map<String, String> properties = conn.instanceOperations().getSystemConfiguration();
    final Map<String, String> peers = new HashMap<>();
    final String definedPeersPrefix = Property.REPLICATION_PEERS.getKey();
    final ReplicaSystemFactory replicaSystemFactory = new ReplicaSystemFactory();
    // Get the defined peers and what ReplicaSystem impl they're using
    for (Entry<String, String> property : properties.entrySet()) {
        String key = property.getKey();
        // Filter out cruft that we don't want
        if (key.startsWith(definedPeersPrefix) && !key.startsWith(Property.REPLICATION_PEER_USER.getKey()) && !key.startsWith(Property.REPLICATION_PEER_PASSWORD.getKey())) {
            String peerName = property.getKey().substring(definedPeersPrefix.length());
            ReplicaSystem replica;
            try {
                replica = replicaSystemFactory.get(property.getValue());
            } catch (Exception e) {
                log.warn("Could not instantiate ReplicaSystem for {} with configuration {}", property.getKey(), property.getValue(), e);
                continue;
            }
            peers.put(peerName, replica.getClass().getName());
        }
    }
    final String targetPrefix = Property.TABLE_REPLICATION_TARGET.getKey();
    // The total set of configured targets
    Set<ReplicationTarget> allConfiguredTargets = new HashSet<>();
    // Number of files per target we have to replicate
    Map<ReplicationTarget, Long> targetCounts = new HashMap<>();
    Map<String, Table.ID> tableNameToId = Tables.getNameToIdMap(conn.getInstance());
    Map<Table.ID, String> tableIdToName = invert(tableNameToId);
    for (String table : tops.list()) {
        if (MetadataTable.NAME.equals(table) || RootTable.NAME.equals(table)) {
            continue;
        }
        Table.ID localId = tableNameToId.get(table);
        if (null == localId) {
            log.trace("Could not determine ID for {}", table);
            continue;
        }
        Iterable<Entry<String, String>> propertiesForTable;
        try {
            propertiesForTable = tops.getProperties(table);
        } catch (TableNotFoundException e) {
            log.warn("Could not fetch properties for {}", table, e);
            continue;
        }
        for (Entry<String, String> prop : propertiesForTable) {
            if (prop.getKey().startsWith(targetPrefix)) {
                String peerName = prop.getKey().substring(targetPrefix.length());
                String remoteIdentifier = prop.getValue();
                ReplicationTarget target = new ReplicationTarget(peerName, remoteIdentifier, localId);
                allConfiguredTargets.add(target);
            }
        }
    }
    // Read over the queued work
    BatchScanner bs;
    try {
        bs = conn.createBatchScanner(ReplicationTable.NAME, Authorizations.EMPTY, 4);
    } catch (TableOfflineException | TableNotFoundException e) {
        log.error("Could not read replication table", e);
        return Collections.emptyList();
    }
    bs.setRanges(Collections.singleton(new Range()));
    WorkSection.limit(bs);
    try {
        Text buffer = new Text();
        for (Entry<Key, Value> entry : bs) {
            Key k = entry.getKey();
            k.getColumnQualifier(buffer);
            ReplicationTarget target = ReplicationTarget.from(buffer);
            // TODO ACCUMULO-2835 once explicit lengths are tracked, we can give size-based estimates instead of just file-based
            Long count = targetCounts.get(target);
            if (null == count) {
                targetCounts.put(target, 1l);
            } else {
                targetCounts.put(target, count + 1);
            }
        }
    } finally {
        bs.close();
    }
    List<ReplicationInformation> replicationInformation = new ArrayList<>();
    for (ReplicationTarget configuredTarget : allConfiguredTargets) {
        String tableName = tableIdToName.get(configuredTarget.getSourceTableId());
        if (null == tableName) {
            log.trace("Could not determine table name from id {}", configuredTarget.getSourceTableId());
            continue;
        }
        String replicaSystemClass = peers.get(configuredTarget.getPeerName());
        if (null == replicaSystemClass) {
            log.trace("Could not determine configured ReplicaSystem for {}", configuredTarget.getPeerName());
            continue;
        }
        Long numFiles = targetCounts.get(configuredTarget);
        replicationInformation.add(new ReplicationInformation(tableName, configuredTarget.getPeerName(), configuredTarget.getRemoteIdentifier(), replicaSystemClass, (null == numFiles) ? 0 : numFiles));
    }
    return replicationInformation;
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) HashMap(java.util.HashMap) BatchScanner(org.apache.accumulo.core.client.BatchScanner) ArrayList(java.util.ArrayList) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) ReplicaSystem(org.apache.accumulo.server.replication.ReplicaSystem) ReplicaSystemFactory(org.apache.accumulo.server.replication.ReplicaSystemFactory) HashSet(java.util.HashSet) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ReplicationTarget(org.apache.accumulo.core.replication.ReplicationTarget) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) GET(javax.ws.rs.GET)

Example 12 with TableOfflineException

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

the class LocatorIT method testBasic.

@Test
public void testBasic() throws Exception {
    Connector conn = getConnector();
    String tableName = getUniqueNames(1)[0];
    conn.tableOperations().create(tableName);
    Range r1 = new Range("m");
    Range r2 = new Range("o", "x");
    String tableId = conn.tableOperations().tableIdMap().get(tableName);
    TabletId t1 = newTabletId(tableId, null, null);
    TabletId t2 = newTabletId(tableId, "r", null);
    TabletId t3 = newTabletId(tableId, null, "r");
    ArrayList<Range> ranges = new ArrayList<>();
    HashSet<String> tservers = new HashSet<>(conn.instanceOperations().getTabletServers());
    ranges.add(r1);
    Locations ret = conn.tableOperations().locate(tableName, ranges);
    assertContains(ret, tservers, ImmutableMap.of(r1, ImmutableSet.of(t1)), ImmutableMap.of(t1, ImmutableSet.of(r1)));
    ranges.add(r2);
    ret = conn.tableOperations().locate(tableName, ranges);
    assertContains(ret, tservers, ImmutableMap.of(r1, ImmutableSet.of(t1), r2, ImmutableSet.of(t1)), ImmutableMap.of(t1, ImmutableSet.of(r1, r2)));
    TreeSet<Text> splits = new TreeSet<>();
    splits.add(new Text("r"));
    conn.tableOperations().addSplits(tableName, splits);
    ret = conn.tableOperations().locate(tableName, ranges);
    assertContains(ret, tservers, ImmutableMap.of(r1, ImmutableSet.of(t2), r2, ImmutableSet.of(t2, t3)), ImmutableMap.of(t2, ImmutableSet.of(r1, r2), t3, ImmutableSet.of(r2)));
    conn.tableOperations().offline(tableName, true);
    try {
        conn.tableOperations().locate(tableName, ranges);
        Assert.fail();
    } catch (TableOfflineException e) {
    // expected
    }
    conn.tableOperations().delete(tableName);
    try {
        conn.tableOperations().locate(tableName, ranges);
        Assert.fail();
    } catch (TableNotFoundException e) {
    // expected
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) ArrayList(java.util.ArrayList) Locations(org.apache.accumulo.core.client.admin.Locations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) TabletId(org.apache.accumulo.core.data.TabletId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with TableOfflineException

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

the class SummaryIT method testExceptions.

@Test
public void testExceptions() throws Exception {
    Connector c = getConnector();
    try {
        c.tableOperations().summaries("foo").retrieve();
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        c.tableOperations().addSummarizers("foo", SummarizerConfiguration.builder(VisibilitySummarizer.class).build());
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        c.tableOperations().listSummarizers("foo");
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    try {
        c.tableOperations().removeSummarizers("foo", sc -> true);
        Assert.fail();
    } catch (TableNotFoundException e) {
    }
    SummarizerConfiguration sc1 = SummarizerConfiguration.builder(FamilySummarizer.class).setPropertyId("p1").build();
    SummarizerConfiguration sc2 = SummarizerConfiguration.builder(VisibilitySummarizer.class).setPropertyId("p1").build();
    c.tableOperations().create("foo");
    c.tableOperations().addSummarizers("foo", sc1);
    c.tableOperations().addSummarizers("foo", sc1);
    try {
        // adding second summarizer with same id should fail
        c.tableOperations().addSummarizers("foo", sc2);
        Assert.fail();
    } catch (IllegalArgumentException e) {
    }
    c.tableOperations().removeSummarizers("foo", sc -> true);
    Assert.assertEquals(0, c.tableOperations().listSummarizers("foo").size());
    try {
        // adding two summarizers at the same time with same id should fail
        c.tableOperations().addSummarizers("foo", sc1, sc2);
        Assert.fail();
    } catch (IllegalArgumentException e) {
    }
    Assert.assertEquals(0, c.tableOperations().listSummarizers("foo").size());
    c.tableOperations().offline("foo", true);
    try {
        c.tableOperations().summaries("foo").retrieve();
        Assert.fail();
    } catch (TableOfflineException e) {
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Test(org.junit.Test)

Example 14 with TableOfflineException

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

the class TableOperationsImpl method addSplits.

@Override
public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
    Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
    List<Text> splits = new ArrayList<>(partitionKeys);
    // should be sorted because we copied from a sorted set, but that makes assumptions about
    // how the copy was done so resort to be sure.
    Collections.sort(splits);
    CountDownLatch latch = new CountDownLatch(splits.size());
    AtomicReference<Throwable> exception = new AtomicReference<>(null);
    ExecutorService executor = Executors.newFixedThreadPool(16, new NamingThreadFactory("addSplits"));
    try {
        executor.execute(new SplitTask(new SplitEnv(tableName, tableId, executor, latch, exception), splits));
        while (!latch.await(100, TimeUnit.MILLISECONDS)) {
            if (exception.get() != null) {
                executor.shutdownNow();
                Throwable excep = exception.get();
                // user would only have the stack trace for the background thread.
                if (excep instanceof TableNotFoundException) {
                    TableNotFoundException tnfe = (TableNotFoundException) excep;
                    throw new TableNotFoundException(tableId.canonicalID(), tableName, "Table not found by background thread", tnfe);
                } else if (excep instanceof TableOfflineException) {
                    log.debug("TableOfflineException occurred in background thread. Throwing new exception", excep);
                    throw new TableOfflineException(context.getInstance(), tableId.canonicalID());
                } else if (excep instanceof AccumuloSecurityException) {
                    // base == background accumulo security exception
                    AccumuloSecurityException base = (AccumuloSecurityException) excep;
                    throw new AccumuloSecurityException(base.getUser(), base.asThriftException().getCode(), base.getTableInfo(), excep);
                } else if (excep instanceof AccumuloServerException) {
                    throw new AccumuloServerException((AccumuloServerException) excep);
                } else if (excep instanceof Error) {
                    throw new Error(excep);
                } else {
                    throw new AccumuloException(excep);
                }
            }
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } finally {
        executor.shutdown();
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) NamingThreadFactory(org.apache.accumulo.core.util.NamingThreadFactory) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 15 with TableOfflineException

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

the class ThriftScanner method scan.

public static List<KeyValue> scan(ClientContext context, ScanState scanState, int timeOut) throws ScanTimedOutException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
    TabletLocation loc = null;
    Instance instance = context.getInstance();
    long startTime = System.currentTimeMillis();
    String lastError = null;
    String error = null;
    int tooManyFilesCount = 0;
    long sleepMillis = 100;
    final long maxSleepTime = context.getConfiguration().getTimeInMillis(Property.GENERAL_MAX_SCANNER_RETRY_PERIOD);
    List<KeyValue> results = null;
    Span span = Trace.start("scan");
    try {
        while (results == null && !scanState.finished) {
            if (Thread.currentThread().isInterrupted()) {
                throw new AccumuloException("Thread interrupted");
            }
            if ((System.currentTimeMillis() - startTime) / 1000.0 > timeOut)
                throw new ScanTimedOutException();
            while (loc == null) {
                long currentTime = System.currentTimeMillis();
                if ((currentTime - startTime) / 1000.0 > timeOut)
                    throw new ScanTimedOutException();
                Span locateSpan = Trace.start("scan:locateTablet");
                try {
                    loc = TabletLocator.getLocator(context, scanState.tableId).locateTablet(context, scanState.startRow, scanState.skipStartRow, false);
                    if (loc == null) {
                        if (!Tables.exists(instance, scanState.tableId))
                            throw new TableDeletedException(scanState.tableId.canonicalID());
                        else if (Tables.getTableState(instance, scanState.tableId) == TableState.OFFLINE)
                            throw new TableOfflineException(instance, scanState.tableId.canonicalID());
                        error = "Failed to locate tablet for table : " + scanState.tableId + " row : " + scanState.startRow;
                        if (!error.equals(lastError))
                            log.debug("{}", error);
                        else if (log.isTraceEnabled())
                            log.trace("{}", error);
                        lastError = error;
                        sleepMillis = pause(sleepMillis, maxSleepTime);
                    } else {
                        // when a tablet splits we do want to continue scanning the low child
                        // of the split if we are already passed it
                        Range dataRange = loc.tablet_extent.toDataRange();
                        if (scanState.range.getStartKey() != null && dataRange.afterEndKey(scanState.range.getStartKey())) {
                            // go to the next tablet
                            scanState.startRow = loc.tablet_extent.getEndRow();
                            scanState.skipStartRow = true;
                            loc = null;
                        } else if (scanState.range.getEndKey() != null && dataRange.beforeStartKey(scanState.range.getEndKey())) {
                            // should not happen
                            throw new RuntimeException("Unexpected tablet, extent : " + loc.tablet_extent + "  range : " + scanState.range + " startRow : " + scanState.startRow);
                        }
                    }
                } catch (AccumuloServerException e) {
                    log.debug("Scan failed, server side exception : {}", e.getMessage());
                    throw e;
                } catch (AccumuloException e) {
                    error = "exception from tablet loc " + e.getMessage();
                    if (!error.equals(lastError))
                        log.debug("{}", error);
                    else if (log.isTraceEnabled())
                        log.trace("{}", error);
                    lastError = error;
                    sleepMillis = pause(sleepMillis, maxSleepTime);
                } finally {
                    locateSpan.stop();
                }
            }
            Span scanLocation = Trace.start("scan:location");
            scanLocation.data("tserver", loc.tablet_location);
            try {
                results = scan(loc, scanState, context);
            } catch (AccumuloSecurityException e) {
                Tables.clearCache(instance);
                if (!Tables.exists(instance, scanState.tableId))
                    throw new TableDeletedException(scanState.tableId.canonicalID());
                e.setTableInfo(Tables.getPrintableTableInfoFromId(instance, scanState.tableId));
                throw e;
            } catch (TApplicationException tae) {
                throw new AccumuloServerException(loc.tablet_location, tae);
            } catch (TSampleNotPresentException tsnpe) {
                String message = "Table " + Tables.getPrintableTableInfoFromId(instance, scanState.tableId) + " does not have sampling configured or built";
                throw new SampleNotPresentException(message, tsnpe);
            } catch (NotServingTabletException e) {
                error = "Scan failed, not serving tablet " + loc;
                if (!error.equals(lastError))
                    log.debug("{}", error);
                else if (log.isTraceEnabled())
                    log.trace("{}", error);
                lastError = error;
                TabletLocator.getLocator(context, scanState.tableId).invalidateCache(loc.tablet_extent);
                loc = null;
                // no need to try the current scan id somewhere else
                scanState.scanID = null;
                if (scanState.isolated)
                    throw new IsolationException();
                sleepMillis = pause(sleepMillis, maxSleepTime);
            } catch (NoSuchScanIDException e) {
                error = "Scan failed, no such scan id " + scanState.scanID + " " + loc;
                if (!error.equals(lastError))
                    log.debug("{}", error);
                else if (log.isTraceEnabled())
                    log.trace("{}", error);
                lastError = error;
                if (scanState.isolated)
                    throw new IsolationException();
                scanState.scanID = null;
            } catch (TooManyFilesException e) {
                error = "Tablet has too many files " + loc + " retrying...";
                if (!error.equals(lastError)) {
                    log.debug("{}", error);
                    tooManyFilesCount = 0;
                } else {
                    tooManyFilesCount++;
                    if (tooManyFilesCount == 300)
                        log.warn("{}", error);
                    else if (log.isTraceEnabled())
                        log.trace("{}", error);
                }
                lastError = error;
                // not sure what state the scan session on the server side is
                // in after this occurs, so lets be cautious and start a new
                // scan session
                scanState.scanID = null;
                if (scanState.isolated)
                    throw new IsolationException();
                sleepMillis = pause(sleepMillis, maxSleepTime);
            } catch (TException e) {
                TabletLocator.getLocator(context, scanState.tableId).invalidateCache(context.getInstance(), loc.tablet_location);
                error = "Scan failed, thrift error " + e.getClass().getName() + "  " + e.getMessage() + " " + loc;
                if (!error.equals(lastError))
                    log.debug("{}", error);
                else if (log.isTraceEnabled())
                    log.trace("{}", error);
                lastError = error;
                loc = null;
                // do not want to continue using the same scan id, if a timeout occurred could cause a batch to be skipped
                // because a thread on the server side may still be processing the timed out continue scan
                scanState.scanID = null;
                if (scanState.isolated)
                    throw new IsolationException();
                sleepMillis = pause(sleepMillis, maxSleepTime);
            } finally {
                scanLocation.stop();
            }
        }
        if (results != null && results.size() == 0 && scanState.finished) {
            results = null;
        }
        return results;
    } catch (InterruptedException ex) {
        throw new AccumuloException(ex);
    } finally {
        span.stop();
    }
}
Also used : TException(org.apache.thrift.TException) TKeyValue(org.apache.accumulo.core.data.thrift.TKeyValue) KeyValue(org.apache.accumulo.core.data.KeyValue) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) Instance(org.apache.accumulo.core.client.Instance) TooManyFilesException(org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException) Span(org.apache.accumulo.core.trace.Span) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) TabletLocation(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) Range(org.apache.accumulo.core.data.Range) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TApplicationException(org.apache.thrift.TApplicationException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException)

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