Search in sources :

Example 66 with TableNotFoundException

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

the class MultiTableBatchWriterIT method testTableRenameNewWriters.

@Test
public void testTableRenameNewWriters() throws Exception {
    try {
        final String[] names = getUniqueNames(4);
        final String table1 = names[0], table2 = names[1];
        final String newTable1 = names[2], newTable2 = names[3];
        TableOperations tops = connector.tableOperations();
        tops.create(table1);
        tops.create(table2);
        BatchWriter bw1 = mtbw.getBatchWriter(table1), bw2 = mtbw.getBatchWriter(table2);
        Mutation m1 = new Mutation("foo");
        m1.put("col1", "", "val1");
        m1.put("col2", "", "val2");
        bw1.addMutation(m1);
        bw2.addMutation(m1);
        tops.rename(table1, newTable1);
        // after seeing the rename
        try {
            bw1 = mtbw.getBatchWriter(table1);
            Assert.fail("Should not be able to find this table");
        } catch (TableNotFoundException e) {
        // pass
        }
        tops.rename(table2, newTable2);
        try {
            bw2 = mtbw.getBatchWriter(table2);
            Assert.fail("Should not be able to find this table");
        } catch (TableNotFoundException e) {
        // pass
        }
        bw1 = mtbw.getBatchWriter(newTable1);
        bw2 = mtbw.getBatchWriter(newTable2);
        Mutation m2 = new Mutation("bar");
        m2.put("col1", "", "val1");
        m2.put("col2", "", "val2");
        bw1.addMutation(m2);
        bw2.addMutation(m2);
        mtbw.close();
        Map<Entry<String, String>, String> expectations = new HashMap<>();
        expectations.put(Maps.immutableEntry("foo", "col1"), "val1");
        expectations.put(Maps.immutableEntry("foo", "col2"), "val2");
        expectations.put(Maps.immutableEntry("bar", "col1"), "val1");
        expectations.put(Maps.immutableEntry("bar", "col2"), "val2");
        for (String table : Arrays.asList(newTable1, newTable2)) {
            try (Scanner s = connector.createScanner(table, new Authorizations())) {
                s.setRange(new Range());
                Map<Entry<String, String>, String> actual = new HashMap<>();
                for (Entry<Key, Value> entry : s) {
                    actual.put(Maps.immutableEntry(entry.getKey().getRow().toString(), entry.getKey().getColumnFamily().toString()), entry.getValue().toString());
                }
                Assert.assertEquals("Differing results for " + table, expectations, actual);
            }
        }
    } finally {
        if (null != mtbw) {
            mtbw.close();
        }
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) HashMap(java.util.HashMap) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) Value(org.apache.accumulo.core.data.Value) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 67 with TableNotFoundException

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

the class MultiTableBatchWriterIT method testTableRenameNewWritersNoCaching.

@Test
public void testTableRenameNewWritersNoCaching() throws Exception {
    mtbw = getMultiTableBatchWriter();
    try {
        final String[] names = getUniqueNames(4);
        final String table1 = names[0], table2 = names[1];
        final String newTable1 = names[2], newTable2 = names[3];
        TableOperations tops = connector.tableOperations();
        tops.create(table1);
        tops.create(table2);
        BatchWriter bw1 = mtbw.getBatchWriter(table1), bw2 = mtbw.getBatchWriter(table2);
        Mutation m1 = new Mutation("foo");
        m1.put("col1", "", "val1");
        m1.put("col2", "", "val2");
        bw1.addMutation(m1);
        bw2.addMutation(m1);
        tops.rename(table1, newTable1);
        tops.rename(table2, newTable2);
        try {
            bw1 = mtbw.getBatchWriter(table1);
            Assert.fail("Should not have gotten batchwriter for " + table1);
        } catch (TableNotFoundException e) {
        // Pass
        }
        try {
            bw2 = mtbw.getBatchWriter(table2);
        } catch (TableNotFoundException e) {
        // Pass
        }
    } finally {
        if (null != mtbw) {
            mtbw.close();
        }
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 68 with TableNotFoundException

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

the class Indexer method flush.

/**
 * Flushes all Mutations in the index writer. And all metric mutations to the metrics table.
 * Note that the metrics table is not updated until this method is explicitly called (or implicitly via close).
 */
public void flush() {
    try {
        // Flush index writer
        indexWriter.flush();
        // Write out metrics mutations
        BatchWriter metricsWriter = connector.createBatchWriter(table.getMetricsTableName(), writerConfig);
        metricsWriter.addMutations(getMetricsMutations());
        metricsWriter.close();
        // Re-initialize the metrics
        metrics.clear();
        metrics.put(METRICS_TABLE_ROW_COUNT, new AtomicLong(0));
    } catch (MutationsRejectedException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Index mutation was rejected by server on flush", e);
    } catch (TableNotFoundException e) {
        throw new PrestoException(ACCUMULO_TABLE_DNE, "Accumulo table does not exist", e);
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AtomicLong(java.util.concurrent.atomic.AtomicLong) PrestoException(com.facebook.presto.spi.PrestoException) BatchWriter(org.apache.accumulo.core.client.BatchWriter) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 69 with TableNotFoundException

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

the class AccumuloDefaultIndexScanner method getIndexRowRanges.

/**
 * Get a list of rowid ranges by scanning a column index.
 *
 * @param column     - the hive column name
 * @param indexRange - Key range to scan on the index table
 * @return List of matching rowid ranges or null if too many matches found
 * if index values are not found a newline range is added to list to
 * short-circuit the query
 */
@Override
public List<Range> getIndexRowRanges(String column, Range indexRange) {
    List<Range> rowIds = new ArrayList<Range>();
    Scanner scan = null;
    String col = this.colMap.get(column);
    if (col != null) {
        try {
            LOG.debug("Searching tab=" + indexTable + " column=" + column + " range=" + indexRange);
            Connector conn = getConnector();
            scan = conn.createScanner(indexTable, auths);
            scan.setRange(indexRange);
            Text cf = new Text(col);
            LOG.debug("Using Column Family=" + toString());
            scan.fetchColumnFamily(cf);
            for (Map.Entry<Key, Value> entry : scan) {
                rowIds.add(new Range(entry.getKey().getColumnQualifier()));
                // if we have too many results return null for a full scan
                if (rowIds.size() > maxRowIds) {
                    return null;
                }
            }
            // no hits on the index so return a no match range
            if (rowIds.isEmpty()) {
                LOG.debug("Found 0 index matches");
            } else {
                LOG.debug("Found " + rowIds.size() + " index matches");
            }
            return rowIds;
        } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
            LOG.error("Failed to scan index table: " + indexTable, e);
        } finally {
            if (scan != null) {
                scan.close();
            }
        }
    }
    // assume the index is bad and do a full scan
    LOG.debug("Index lookup failed for table " + indexTable);
    return null;
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) HashMap(java.util.HashMap) Map(java.util.Map) Key(org.apache.accumulo.core.data.Key)

Example 70 with TableNotFoundException

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

the class TestAccumuloDefaultIndexScanner method buildMockHandler.

public static AccumuloDefaultIndexScanner buildMockHandler(int maxMatches) {
    try {
        String table = "table";
        Text emptyText = new Text("");
        Configuration conf = new Configuration();
        conf.set(AccumuloIndexParameters.INDEXTABLE_NAME, table);
        conf.setInt(AccumuloIndexParameters.MAX_INDEX_ROWS, maxMatches);
        conf.set(AccumuloIndexParameters.INDEXED_COLUMNS, "*");
        conf.set(serdeConstants.LIST_COLUMNS, "rid,name,age,cars,mgr");
        conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, ":rowId,name:name,age:age,cars:cars,mgr:mgr");
        AccumuloDefaultIndexScanner handler = new AccumuloDefaultIndexScanner();
        handler.init(conf);
        MockInstance inst = new MockInstance("test_instance");
        Connector conn = inst.getConnector("root", new PasswordToken(""));
        if (!conn.tableOperations().exists(table)) {
            conn.tableOperations().create(table);
            BatchWriterConfig batchConfig = new BatchWriterConfig();
            BatchWriter writer = conn.createBatchWriter(table, batchConfig);
            addRow(writer, "fred", "name_name", "row1");
            addRow(writer, "25", "age_age", "row1");
            addRow(writer, 5, "cars_cars", "row1");
            addRow(writer, true, "mgr_mgr", "row1");
            addRow(writer, "bill", "name_name", "row2");
            addRow(writer, "20", "age_age", "row2");
            addRow(writer, 2, "cars_cars", "row2");
            addRow(writer, false, "mgr_mgr", "row2");
            addRow(writer, "sally", "name_name", "row3");
            addRow(writer, "23", "age_age", "row3");
            addRow(writer, 6, "cars_cars", "row3");
            addRow(writer, true, "mgr_mgr", "row3");
            addRow(writer, "rob", "name_name", "row4");
            addRow(writer, "60", "age_age", "row4");
            addRow(writer, 1, "cars_cars", "row4");
            addRow(writer, false, "mgr_mgr", "row4");
            writer.close();
        }
        AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
        AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
        Mockito.when(connectionParams.getConnector()).thenReturn(conn);
        handler.setConnectParams(connectionParams);
        return handler;
    } catch (AccumuloSecurityException | AccumuloException | TableExistsException | TableNotFoundException e) {
        LOG.error(e.getLocalizedMessage(), e);
    }
    return null;
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) TableExistsException(org.apache.accumulo.core.client.TableExistsException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

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