Search in sources :

Example 61 with TableNotFoundException

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

the class SecurityOperation method initializeSecurity.

public void initializeSecurity(TCredentials credentials, String rootPrincipal, byte[] token) throws AccumuloSecurityException, ThriftSecurityException {
    if (!isSystemUser(credentials))
        throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    authenticator.initializeSecurity(credentials, rootPrincipal, token);
    authorizor.initializeSecurity(credentials, rootPrincipal);
    permHandle.initializeSecurity(credentials, rootPrincipal);
    try {
        permHandle.grantTablePermission(rootPrincipal, MetadataTable.ID.canonicalID(), TablePermission.ALTER_TABLE);
    } catch (TableNotFoundException e) {
        // Shouldn't happen
        throw new RuntimeException(e);
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 62 with TableNotFoundException

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

the class LargestFirstMemoryManager method getMemoryManagementActions.

@Override
public MemoryManagementActions getMemoryManagementActions(List<TabletState> tablets) {
    if (maxMemory < 0)
        throw new IllegalStateException("need to initialize " + LargestFirstMemoryManager.class.getName());
    final Instance instance = HdfsZooInstance.getInstance();
    final int maxMinCs = maxConcurrentMincs * numWaitingMultiplier;
    mincIdleThresholds.clear();
    final MemoryManagementActions result = new MemoryManagementActions();
    result.tabletsToMinorCompact = new ArrayList<>();
    LargestMap largestMemTablets = new LargestMap(maxMinCs);
    final LargestMap largestIdleMemTablets = new LargestMap(maxConcurrentMincs);
    final long now = currentTimeMillis();
    long ingestMemory = 0;
    long compactionMemory = 0;
    int numWaitingMincs = 0;
    // find the largest and most idle tablets
    for (TabletState ts : tablets) {
        // Make sure that the table still exists
        if (!tableExists(instance, ts.getExtent().getTableId())) {
            log.trace("Ignoring extent for deleted table: {}", ts.getExtent());
            continue;
        }
        final long memTabletSize = ts.getMemTableSize();
        final long minorCompactingSize = ts.getMinorCompactingMemTableSize();
        final long idleTime = now - Math.max(ts.getLastCommitTime(), ZERO_TIME);
        final long timeMemoryLoad = timeMemoryLoad(memTabletSize, idleTime);
        ingestMemory += memTabletSize;
        if (minorCompactingSize == 0 && memTabletSize > 0) {
            TabletInfo tabletInfo = new TabletInfo(ts.getExtent(), memTabletSize, idleTime, timeMemoryLoad);
            try {
                // If the table was deleted, getMinCIdleThreshold will throw an exception
                if (idleTime > getMinCIdleThreshold(ts.getExtent())) {
                    largestIdleMemTablets.put(timeMemoryLoad, tabletInfo);
                }
            } catch (IllegalArgumentException e) {
                Throwable cause = e.getCause();
                if (null != cause && cause instanceof TableNotFoundException) {
                    log.trace("Ignoring extent for deleted table: {}", ts.getExtent());
                    // We just want to eat this exception, do nothing with this tablet, and continue
                    continue;
                }
                throw e;
            }
            // Only place the tablet into largestMemTablets map when the table still exists
            largestMemTablets.put(timeMemoryLoad, tabletInfo);
        }
        compactionMemory += minorCompactingSize;
        if (minorCompactingSize > 0)
            numWaitingMincs++;
    }
    if (ingestMemory + compactionMemory > maxObserved) {
        maxObserved = ingestMemory + compactionMemory;
    }
    final long memoryChange = ingestMemory - prevIngestMemory;
    prevIngestMemory = ingestMemory;
    boolean startMinC = false;
    if (numWaitingMincs < maxMinCs) {
        // or if the idle time of the chosen tablet is greater than the threshold, start a minor compaction
        if (memoryChange >= 0 && ingestMemory + memoryChange > compactionThreshold * maxMemory) {
            startMinC = true;
        } else if (!largestIdleMemTablets.isEmpty()) {
            startMinC = true;
            // switch largestMemTablets to largestIdleMemTablets
            largestMemTablets = largestIdleMemTablets;
            log.debug("IDLE minor compaction chosen");
        }
    }
    if (startMinC) {
        long toBeCompacted = compactionMemory;
        outer: for (int i = numWaitingMincs; i < maxMinCs && !largestMemTablets.isEmpty(); ) /* empty */
        {
            Entry<Long, List<TabletInfo>> lastEntry = largestMemTablets.lastEntry();
            for (TabletInfo largest : lastEntry.getValue()) {
                toBeCompacted += largest.memTableSize;
                result.tabletsToMinorCompact.add(largest.extent);
                log.debug(String.format("COMPACTING %s  total = %,d ingestMemory = %,d", largest.extent.toString(), (ingestMemory + compactionMemory), ingestMemory));
                log.debug(String.format("chosenMem = %,d chosenIT = %.2f load %,d", largest.memTableSize, largest.idleTime / 1000.0, largest.load));
                if (toBeCompacted > ingestMemory * MAX_FLUSH_AT_ONCE_PERCENT)
                    break outer;
                i++;
            }
            largestMemTablets.remove(lastEntry.getKey());
        }
    } else if (memoryChange < 0) {
        // before idle mincs, starting a minor compaction meant that memoryChange >= 0.
        // we thought we might want to remove the "else" if that changed,
        // however it seems performing idle compactions shouldn't make the threshold
        // change more often, so it is staying for now.
        // also, now we have the case where memoryChange < 0 due to an idle compaction, yet
        // we are still adjusting the threshold. should this be tracked and prevented?
        // memory change < 0 means a minor compaction occurred
        // we want to see how full the memory got during the compaction
        // (the goal is for it to have between 80% and 90% memory utilization)
        // and adjust the compactionThreshold accordingly
        log.debug(String.format("BEFORE compactionThreshold = %.3f maxObserved = %,d", compactionThreshold, maxObserved));
        if (compactionThreshold < 0.82 && maxObserved < 0.8 * maxMemory) {
            // 0.82 * 1.1 is about 0.9, which is our desired max threshold
            compactionThreshold *= 1.1;
        } else if (compactionThreshold > 0.056 && maxObserved > 0.9 * maxMemory) {
            // 0.056 * 0.9 is about 0.05, which is our desired min threshold
            compactionThreshold *= 0.9;
        }
        maxObserved = 0;
        log.debug(String.format("AFTER compactionThreshold = %.3f", compactionThreshold));
    }
    return result;
}
Also used : Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry)

Example 63 with TableNotFoundException

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

the class VerifyTabletAssignments method checkTable.

private static void checkTable(final ClientContext context, final Opts opts, String tableName, HashSet<KeyExtent> check) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, InterruptedException {
    if (check == null)
        System.out.println("Checking table " + tableName);
    else
        System.out.println("Checking table " + tableName + " again, failures " + check.size());
    TreeMap<KeyExtent, String> tabletLocations = new TreeMap<>();
    Table.ID tableId = Tables.getNameToIdMap(context.getInstance()).get(tableName);
    MetadataServicer.forTableId(context, tableId).getTabletLocations(tabletLocations);
    final HashSet<KeyExtent> failures = new HashSet<>();
    Map<HostAndPort, List<KeyExtent>> extentsPerServer = new TreeMap<>();
    for (Entry<KeyExtent, String> entry : tabletLocations.entrySet()) {
        KeyExtent keyExtent = entry.getKey();
        String loc = entry.getValue();
        if (loc == null)
            System.out.println(" Tablet " + keyExtent + " has no location");
        else if (opts.verbose)
            System.out.println(" Tablet " + keyExtent + " is located at " + loc);
        if (loc != null) {
            final HostAndPort parsedLoc = HostAndPort.fromString(loc);
            List<KeyExtent> extentList = extentsPerServer.get(parsedLoc);
            if (extentList == null) {
                extentList = new ArrayList<>();
                extentsPerServer.put(parsedLoc, extentList);
            }
            if (check == null || check.contains(keyExtent))
                extentList.add(keyExtent);
        }
    }
    ExecutorService tp = Executors.newFixedThreadPool(20);
    for (final Entry<HostAndPort, List<KeyExtent>> entry : extentsPerServer.entrySet()) {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                try {
                    checkTabletServer(context, entry, failures);
                } catch (Exception e) {
                    log.error("Failure on tablet server '" + entry.getKey() + ".", e);
                    failures.addAll(entry.getValue());
                }
            }
        };
        tp.execute(r);
    }
    tp.shutdown();
    while (!tp.awaitTermination(1, TimeUnit.HOURS)) {
    }
    if (failures.size() > 0)
        checkTable(context, opts, tableName, failures);
}
Also used : Table(org.apache.accumulo.core.client.impl.Table) TreeMap(java.util.TreeMap) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 64 with TableNotFoundException

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

the class ConditionalWriterIT method testDeleteTable.

@Test
public void testDeleteTable() throws Exception {
    String table = getUniqueNames(1)[0];
    Connector conn = getConnector();
    try {
        conn.createConditionalWriter(table, new ConditionalWriterConfig());
        Assert.fail("Creating conditional writer for table that doesn't exist should fail");
    } catch (TableNotFoundException e) {
    }
    conn.tableOperations().create(table);
    try (ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig())) {
        conn.tableOperations().delete(table);
        ConditionalMutation cm1 = new ConditionalMutation("r1", new Condition("tx", "seq"));
        cm1.put("tx", "seq", "1");
        cm1.put("data", "x", "a");
        Result result = cw.write(cm1);
        try {
            Status status = result.getStatus();
            Assert.fail("Expected exception writing conditional mutation to deleted table. Got status: " + status);
        } catch (AccumuloException ae) {
            Assert.assertEquals(TableDeletedException.class, ae.getCause().getClass());
        }
    }
}
Also used : Condition(org.apache.accumulo.core.data.Condition) Status(org.apache.accumulo.core.client.ConditionalWriter.Status) Connector(org.apache.accumulo.core.client.Connector) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) ConditionalWriterConfig(org.apache.accumulo.core.client.ConditionalWriterConfig) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) Result(org.apache.accumulo.core.client.ConditionalWriter.Result) Test(org.junit.Test)

Example 65 with TableNotFoundException

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

the class NamespacesIT method verifyTableOperationsExceptions.

@Test
public void verifyTableOperationsExceptions() throws Exception {
    String tableName = namespace + ".1";
    IteratorSetting setting = new IteratorSetting(200, VersioningIterator.class);
    Text a = new Text("a");
    Text z = new Text("z");
    TableOperations ops = c.tableOperations();
    // this one doesn't throw an exception, so don't fail; just check that it works
    assertFalse(ops.exists(tableName));
    // table operations that should throw an AccumuloException caused by NamespaceNotFoundException
    int numRun = 0;
    ACCUMULOEXCEPTIONS_NAMESPACENOTFOUND: for (int i = 0; ; ++i) try {
        switch(i) {
            case 0:
                ops.create(tableName);
                fail();
                break;
            case 1:
                ops.create("a");
                ops.clone("a", tableName, true, Collections.emptyMap(), Collections.emptySet());
                fail();
                break;
            case 2:
                ops.importTable(tableName, System.getProperty("user.dir") + "/target");
                fail();
                break;
            default:
                // break out of infinite loop
                // check test integrity
                assertEquals(3, i);
                // check test integrity
                assertEquals(3, numRun);
                break ACCUMULOEXCEPTIONS_NAMESPACENOTFOUND;
        }
    } catch (Exception e) {
        numRun++;
        if (!(e instanceof AccumuloException) || !(e.getCause() instanceof NamespaceNotFoundException))
            throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
    }
    // table operations that should throw an AccumuloException caused by a TableNotFoundException caused by a NamespaceNotFoundException
    // these are here because we didn't declare TableNotFoundException in the API :(
    numRun = 0;
    ACCUMULOEXCEPTIONS_TABLENOTFOUND: for (int i = 0; ; ++i) try {
        switch(i) {
            case 0:
                ops.removeConstraint(tableName, 0);
                fail();
                break;
            case 1:
                ops.removeProperty(tableName, "a");
                fail();
                break;
            case 2:
                ops.setProperty(tableName, "a", "b");
                fail();
                break;
            default:
                // break out of infinite loop
                // check test integrity
                assertEquals(3, i);
                // check test integrity
                assertEquals(3, numRun);
                break ACCUMULOEXCEPTIONS_TABLENOTFOUND;
        }
    } catch (Exception e) {
        numRun++;
        if (!(e instanceof AccumuloException) || !(e.getCause() instanceof TableNotFoundException) || !(e.getCause().getCause() instanceof NamespaceNotFoundException))
            throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
    }
    // table operations that should throw a TableNotFoundException caused by NamespaceNotFoundException
    numRun = 0;
    TABLENOTFOUNDEXCEPTIONS: for (int i = 0; ; ++i) try {
        switch(i) {
            case 0:
                ops.addConstraint(tableName, NumericValueConstraint.class.getName());
                fail();
                break;
            case 1:
                ops.addSplits(tableName, new TreeSet<>());
                fail();
                break;
            case 2:
                ops.attachIterator(tableName, setting);
                fail();
                break;
            case 3:
                ops.cancelCompaction(tableName);
                fail();
                break;
            case 4:
                ops.checkIteratorConflicts(tableName, setting, EnumSet.allOf(IteratorScope.class));
                fail();
                break;
            case 5:
                ops.clearLocatorCache(tableName);
                fail();
                break;
            case 6:
                ops.clone(tableName, "2", true, Collections.emptyMap(), Collections.emptySet());
                fail();
                break;
            case 7:
                ops.compact(tableName, a, z, true, true);
                fail();
                break;
            case 8:
                ops.delete(tableName);
                fail();
                break;
            case 9:
                ops.deleteRows(tableName, a, z);
                fail();
                break;
            case 10:
                ops.splitRangeByTablets(tableName, new Range(), 10);
                fail();
                break;
            case 11:
                ops.exportTable(tableName, namespace + "_dir");
                fail();
                break;
            case 12:
                ops.flush(tableName, a, z, true);
                fail();
                break;
            case 13:
                ops.getDiskUsage(Collections.singleton(tableName));
                fail();
                break;
            case 14:
                ops.getIteratorSetting(tableName, "a", IteratorScope.scan);
                fail();
                break;
            case 15:
                ops.getLocalityGroups(tableName);
                fail();
                break;
            case 16:
                ops.getMaxRow(tableName, Authorizations.EMPTY, a, true, z, true);
                fail();
                break;
            case 17:
                ops.getProperties(tableName);
                fail();
                break;
            case 18:
                ops.importDirectory(tableName, "", "", false);
                fail();
                break;
            case 19:
                ops.testClassLoad(tableName, VersioningIterator.class.getName(), SortedKeyValueIterator.class.getName());
                fail();
                break;
            case 20:
                ops.listConstraints(tableName);
                fail();
                break;
            case 21:
                ops.listIterators(tableName);
                fail();
                break;
            case 22:
                ops.listSplits(tableName);
                fail();
                break;
            case 23:
                ops.merge(tableName, a, z);
                fail();
                break;
            case 24:
                ops.offline(tableName, true);
                fail();
                break;
            case 25:
                ops.online(tableName, true);
                fail();
                break;
            case 26:
                ops.removeIterator(tableName, "a", EnumSet.of(IteratorScope.scan));
                fail();
                break;
            case 27:
                ops.rename(tableName, tableName + "2");
                fail();
                break;
            case 28:
                ops.setLocalityGroups(tableName, Collections.emptyMap());
                fail();
                break;
            default:
                // break out of infinite loop
                // check test integrity
                assertEquals(29, i);
                // check test integrity
                assertEquals(29, numRun);
                break TABLENOTFOUNDEXCEPTIONS;
        }
    } catch (Exception e) {
        numRun++;
        if (!(e instanceof TableNotFoundException) || !(e.getCause() instanceof NamespaceNotFoundException))
            throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) NamespaceNotEmptyException(org.apache.accumulo.core.client.NamespaceNotEmptyException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) VersioningIterator(org.apache.accumulo.core.iterators.user.VersioningIterator) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) Test(org.junit.Test)

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