Search in sources :

Example 51 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TabletStateChangeIteratorIT method test.

@Test
public void test() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        String[] tables = getUniqueNames(6);
        final String t1 = tables[0];
        final String t2 = tables[1];
        final String t3 = tables[2];
        final String metaCopy1 = tables[3];
        final String metaCopy2 = tables[4];
        final String metaCopy3 = tables[5];
        // create some metadata
        createTable(client, t1, true);
        createTable(client, t2, false);
        createTable(client, t3, true);
        // examine a clone of the metadata table, so we can manipulate it
        copyTable(client, MetadataTable.NAME, metaCopy1);
        State state = new State(client);
        int tabletsInFlux = findTabletsNeedingAttention(client, metaCopy1, state);
        while (tabletsInFlux > 0) {
            log.debug("Waiting for {} tablets for {}", tabletsInFlux, metaCopy1);
            UtilWaitThread.sleep(500);
            copyTable(client, MetadataTable.NAME, metaCopy1);
            tabletsInFlux = findTabletsNeedingAttention(client, metaCopy1, state);
        }
        assertEquals("No tables should need attention", 0, findTabletsNeedingAttention(client, metaCopy1, state));
        // The metadata table stabilized and metaCopy1 contains a copy suitable for testing. Before
        // metaCopy1 is modified, copy it for subsequent test.
        copyTable(client, metaCopy1, metaCopy2);
        copyTable(client, metaCopy1, metaCopy3);
        // test the assigned case (no location)
        removeLocation(client, metaCopy1, t3);
        assertEquals("Should have two tablets without a loc", 2, findTabletsNeedingAttention(client, metaCopy1, state));
        // test the cases where the assignment is to a dead tserver
        reassignLocation(client, metaCopy2, t3);
        assertEquals("Should have one tablet that needs to be unassigned", 1, findTabletsNeedingAttention(client, metaCopy2, state));
        // test the cases where there is ongoing merges
        state = new State(client) {

            @Override
            public Collection<MergeInfo> merges() {
                TableId tableIdToModify = TableId.of(client.tableOperations().tableIdMap().get(t3));
                return Collections.singletonList(new MergeInfo(new KeyExtent(tableIdToModify, null, null), MergeInfo.Operation.MERGE));
            }
        };
        assertEquals("Should have 2 tablets that need to be chopped or unassigned", 1, findTabletsNeedingAttention(client, metaCopy2, state));
        // test the bad tablet location state case (inconsistent metadata)
        state = new State(client);
        addDuplicateLocation(client, metaCopy3, t3);
        assertEquals("Should have 1 tablet that needs a metadata repair", 1, findTabletsNeedingAttention(client, metaCopy3, state));
        // clean up
        dropTables(client, t1, t2, t3, metaCopy1, metaCopy2, metaCopy3);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) MergeInfo(org.apache.accumulo.server.manager.state.MergeInfo) TableState(org.apache.accumulo.core.manager.state.tables.TableState) ManagerState(org.apache.accumulo.core.manager.thrift.ManagerState) CurrentState(org.apache.accumulo.server.manager.state.CurrentState) Collection(java.util.Collection) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Test(org.junit.Test)

Example 52 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TabletStateChangeIteratorIT method removeLocation.

private void removeLocation(AccumuloClient client, String table, String tableNameToModify) throws TableNotFoundException, MutationsRejectedException {
    TableId tableIdToModify = TableId.of(client.tableOperations().tableIdMap().get(tableNameToModify));
    BatchDeleter deleter = client.createBatchDeleter(table, Authorizations.EMPTY, 1);
    deleter.setRanges(Collections.singleton(new KeyExtent(tableIdToModify, null, null).toMetaRange()));
    deleter.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
    deleter.delete();
    deleter.close();
}
Also used : TableId(org.apache.accumulo.core.data.TableId) BatchDeleter(org.apache.accumulo.core.client.BatchDeleter) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent)

Example 53 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TabletStateChangeIteratorIT method addDuplicateLocation.

private void addDuplicateLocation(AccumuloClient client, String table, String tableNameToModify) throws TableNotFoundException, MutationsRejectedException {
    TableId tableIdToModify = TableId.of(client.tableOperations().tableIdMap().get(tableNameToModify));
    Mutation m = new Mutation(new KeyExtent(tableIdToModify, null, null).toMetaRow());
    m.put(CurrentLocationColumnFamily.NAME, new Text("1234567"), new Value("fake:9005"));
    try (BatchWriter bw = client.createBatchWriter(table)) {
        bw.addMutation(m);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) BatchWriter(org.apache.accumulo.core.client.BatchWriter) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent)

Example 54 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TableIT method test.

@Test
public void test() throws Exception {
    assumeTrue(getClusterType() == ClusterType.MINI);
    AccumuloCluster cluster = getCluster();
    MiniAccumuloClusterImpl mac = (MiniAccumuloClusterImpl) cluster;
    String rootPath = mac.getConfig().getDir().getAbsolutePath();
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        TableOperations to = c.tableOperations();
        String tableName = getUniqueNames(1)[0];
        to.create(tableName);
        VerifyParams params = new VerifyParams(getClientProps(), tableName);
        TestIngest.ingest(c, params);
        to.flush(tableName, null, null, true);
        VerifyIngest.verifyIngest(c, params);
        TableId id = TableId.of(to.tableIdMap().get(tableName));
        try (Scanner s = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
            s.setRange(new KeyExtent(id, null, null).toMetaRange());
            s.fetchColumnFamily(DataFileColumnFamily.NAME);
            assertTrue(Iterators.size(s.iterator()) > 0);
            FileSystem fs = getCluster().getFileSystem();
            assertTrue(fs.listStatus(new Path(rootPath + "/accumulo/tables/" + id)).length > 0);
            to.delete(tableName);
            assertEquals(0, Iterators.size(s.iterator()));
            try {
                assertEquals(0, fs.listStatus(new Path(rootPath + "/accumulo/tables/" + id)).length);
            } catch (FileNotFoundException ex) {
            // that's fine, too
            }
            assertNull(to.tableIdMap().get(tableName));
            to.create(tableName);
            TestIngest.ingest(c, params);
            VerifyIngest.verifyIngest(c, params);
            to.delete(tableName);
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) Path(org.apache.hadoop.fs.Path) Scanner(org.apache.accumulo.core.client.Scanner) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) AccumuloCluster(org.apache.accumulo.cluster.AccumuloCluster) FileSystem(org.apache.hadoop.fs.FileSystem) VerifyParams(org.apache.accumulo.test.VerifyIngest.VerifyParams) FileNotFoundException(java.io.FileNotFoundException) MiniAccumuloClusterImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Test(org.junit.Test)

Example 55 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class BaseHostRegexTableLoadBalancerTest method createCurrent.

protected SortedMap<TabletServerId, TServerStatus> createCurrent(int numTservers) {
    String base = "192.168.0.";
    TreeMap<TabletServerId, TServerStatus> current = new TreeMap<>();
    for (int i = 1; i <= numTservers; i++) {
        TServerStatusImpl status = new TServerStatusImpl(new org.apache.accumulo.core.master.thrift.TabletServerStatus());
        Map<String, TableStatistics> tableMap = new HashMap<>();
        tableMap.put(FOO.getId().canonical(), new TableStatisticsImpl(new TableInfo()));
        tableMap.put(BAR.getId().canonical(), new TableStatisticsImpl(new TableInfo()));
        tableMap.put(BAZ.getId().canonical(), new TableStatisticsImpl(new TableInfo()));
        status.setTableMap(tableMap);
        current.put(new TabletServerIdImpl(base + i, 9997, Integer.toHexString(1)), status);
    }
    // now put all of the tablets on one server
    for (Map.Entry<String, TabletServerId> entry : initialTableLocation.entrySet()) {
        TServerStatus status = current.get(entry.getValue());
        if (status != null) {
            TableId tableId = environment.getTableIdMap().get(entry.getKey());
            ((TableStatisticsImpl) status.getTableMap().get(tableId.canonical())).setOnlineTabletCount(5);
        }
    }
    return current;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) HashMap(java.util.HashMap) TServerStatus(org.apache.accumulo.core.spi.balancer.data.TServerStatus) TreeMap(java.util.TreeMap) TabletServerIdImpl(org.apache.accumulo.core.manager.balancer.TabletServerIdImpl) TServerStatusImpl(org.apache.accumulo.core.manager.balancer.TServerStatusImpl) TableStatisticsImpl(org.apache.accumulo.core.manager.balancer.TableStatisticsImpl) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TableStatistics(org.apache.accumulo.core.spi.balancer.data.TableStatistics) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Aggregations

TableId (org.apache.accumulo.core.data.TableId)169 Text (org.apache.hadoop.io.Text)64 HashMap (java.util.HashMap)55 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)55 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)43 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)41 Map (java.util.Map)37 Key (org.apache.accumulo.core.data.Key)36 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)34 HashSet (java.util.HashSet)31 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)31 Value (org.apache.accumulo.core.data.Value)31 IOException (java.io.IOException)28 Scanner (org.apache.accumulo.core.client.Scanner)28 AccumuloException (org.apache.accumulo.core.client.AccumuloException)27 Mutation (org.apache.accumulo.core.data.Mutation)27 List (java.util.List)26 Range (org.apache.accumulo.core.data.Range)24 BatchWriter (org.apache.accumulo.core.client.BatchWriter)23