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);
}
}
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();
}
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);
}
}
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);
}
}
}
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;
}
Aggregations