use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class HostRegexTableLoadBalancerReconfigurationTest method testConfigurationChanges.
@Test
public void testConfigurationChanges() {
init(new AccumuloServerContext(instance, factory));
Map<KeyExtent, TServerInstance> unassigned = new HashMap<>();
for (List<KeyExtent> extents : tableExtents.values()) {
for (KeyExtent ke : extents) {
unassigned.put(ke, null);
}
}
this.getAssignments(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments);
Assert.assertEquals(15, assignments.size());
// Ensure unique tservers
for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
for (Entry<KeyExtent, TServerInstance> e2 : assignments.entrySet()) {
if (e.getKey().equals(e2.getKey())) {
continue;
}
if (e.getValue().equals(e2.getValue())) {
Assert.fail("Assignment failure. " + e.getKey() + " and " + e2.getKey() + " are assigned to the same host: " + e.getValue());
}
}
}
// Ensure assignments are correct
for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
if (!tabletInBounds(e.getKey(), e.getValue())) {
Assert.fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().host());
}
}
Set<KeyExtent> migrations = new HashSet<>();
List<TabletMigration> migrationsOut = new ArrayList<>();
// Wait to trigger the out of bounds check which will call our version of getOnlineTabletsForTable
UtilWaitThread.sleep(3000);
this.balance(Collections.unmodifiableSortedMap(allTabletServers), migrations, migrationsOut);
Assert.assertEquals(0, migrationsOut.size());
// Change property, simulate call by TableConfWatcher
DEFAULT_TABLE_PROPERTIES.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "r01.*");
this.propertiesChanged();
// Wait to trigger the out of bounds check and the repool check
UtilWaitThread.sleep(10000);
this.balance(Collections.unmodifiableSortedMap(allTabletServers), migrations, migrationsOut);
Assert.assertEquals(5, migrationsOut.size());
for (TabletMigration migration : migrationsOut) {
Assert.assertTrue(migration.newServer.host().startsWith("192.168.0.1") || migration.newServer.host().startsWith("192.168.0.2") || migration.newServer.host().startsWith("192.168.0.3") || migration.newServer.host().startsWith("192.168.0.4") || migration.newServer.host().startsWith("192.168.0.5"));
}
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method testAllUnassigned.
@Test
public void testAllUnassigned() {
init(new AccumuloServerContext(instance, factory));
Map<KeyExtent, TServerInstance> assignments = new HashMap<>();
Map<KeyExtent, TServerInstance> unassigned = new HashMap<>();
for (List<KeyExtent> extents : tableExtents.values()) {
for (KeyExtent ke : extents) {
unassigned.put(ke, null);
}
}
this.getAssignments(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments);
Assert.assertEquals(15, assignments.size());
// Ensure unique tservers
for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
for (Entry<KeyExtent, TServerInstance> e2 : assignments.entrySet()) {
if (e.getKey().equals(e2.getKey())) {
continue;
}
if (e.getValue().equals(e2.getValue())) {
Assert.fail("Assignment failure");
}
}
}
// Ensure assignments are correct
for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
if (!tabletInBounds(e.getKey(), e.getValue())) {
Assert.fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().host());
}
}
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method testPartiallyAssigned.
@Test
public void testPartiallyAssigned() {
init(new AccumuloServerContext(instance, factory));
Map<KeyExtent, TServerInstance> assignments = new HashMap<>();
Map<KeyExtent, TServerInstance> unassigned = new HashMap<>();
int i = 0;
for (List<KeyExtent> extents : tableExtents.values()) {
for (KeyExtent ke : extents) {
if ((i % 2) == 0) {
unassigned.put(ke, null);
}
i++;
}
}
this.getAssignments(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments);
Assert.assertEquals(unassigned.size(), assignments.size());
// Ensure unique tservers
for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
for (Entry<KeyExtent, TServerInstance> e2 : assignments.entrySet()) {
if (e.getKey().equals(e2.getKey())) {
continue;
}
if (e.getValue().equals(e2.getValue())) {
Assert.fail("Assignment failure");
}
}
}
// Ensure assignments are correct
for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
if (!tabletInBounds(e.getKey(), e.getValue())) {
Assert.fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().host());
}
}
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class MetadataBatchScanTest method main.
public static void main(String[] args) throws Exception {
ClientOpts opts = new ClientOpts();
opts.parseArgs(MetadataBatchScanTest.class.getName(), args);
Instance inst = new ZooKeeperInstance(ClientConfiguration.create().withInstance("acu14").withZkHosts("localhost"));
final Connector connector = inst.getConnector(opts.getPrincipal(), opts.getToken());
TreeSet<Long> splits = new TreeSet<>();
Random r = new Random(42);
while (splits.size() < 99999) {
splits.add((r.nextLong() & 0x7fffffffffffffffl) % 1000000000000l);
}
Table.ID tid = Table.ID.of("8");
Text per = null;
ArrayList<KeyExtent> extents = new ArrayList<>();
for (Long split : splits) {
Text er = new Text(String.format("%012d", split));
KeyExtent ke = new KeyExtent(tid, er, per);
per = er;
extents.add(ke);
}
extents.add(new KeyExtent(tid, null, per));
if (args[0].equals("write")) {
BatchWriter bw = connector.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
for (KeyExtent extent : extents) {
Mutation mut = extent.getPrevRowUpdateMutation();
new TServerInstance(HostAndPort.fromParts("192.168.1.100", 4567), "DEADBEEF").putLocation(mut);
bw.addMutation(mut);
}
bw.close();
} else if (args[0].equals("writeFiles")) {
BatchWriter bw = connector.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
for (KeyExtent extent : extents) {
Mutation mut = new Mutation(extent.getMetadataEntry());
String dir = "/t-" + UUID.randomUUID();
TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.put(mut, new Value(dir.getBytes(UTF_8)));
for (int i = 0; i < 5; i++) {
mut.put(DataFileColumnFamily.NAME, new Text(dir + "/00000_0000" + i + ".map"), new DataFileValue(10000, 1000000).encodeAsValue());
}
bw.addMutation(mut);
}
bw.close();
} else if (args[0].equals("scan")) {
int numThreads = Integer.parseInt(args[1]);
final int numLoop = Integer.parseInt(args[2]);
int numLookups = Integer.parseInt(args[3]);
HashSet<Integer> indexes = new HashSet<>();
while (indexes.size() < numLookups) {
indexes.add(r.nextInt(extents.size()));
}
final List<Range> ranges = new ArrayList<>();
for (Integer i : indexes) {
ranges.add(extents.get(i).toMetadataRange());
}
Thread[] threads = new Thread[numThreads];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println(runScanTest(connector, numLoop, ranges));
} catch (Exception e) {
log.error("Exception while running scan test.", e);
}
}
});
}
long t1 = System.currentTimeMillis();
for (Thread thread : threads) {
thread.start();
}
for (Thread thread : threads) {
thread.join();
}
long t2 = System.currentTimeMillis();
System.out.printf("tt : %6.2f%n", (t2 - t1) / 1000.0);
} else {
throw new IllegalArgumentException();
}
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class RegexGroupBalanceIT method getCounts.
private Table<String, String, MutableInt> getCounts(Connector conn, String tablename) throws TableNotFoundException {
try (Scanner s = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
s.fetchColumnFamily(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME);
org.apache.accumulo.core.client.impl.Table.ID tableId = org.apache.accumulo.core.client.impl.Table.ID.of(conn.tableOperations().tableIdMap().get(tablename));
s.setRange(MetadataSchema.TabletsSection.getRange(tableId));
Table<String, String, MutableInt> groupLocationCounts = HashBasedTable.create();
for (Entry<Key, Value> entry : s) {
String group = entry.getKey().getRow().toString();
if (group.endsWith("<")) {
group = "03";
} else {
group = group.substring(tableId.canonicalID().length() + 1).substring(0, 2);
}
String loc = new TServerInstance(entry.getValue(), entry.getKey().getColumnQualifier()).toString();
MutableInt count = groupLocationCounts.get(group, loc);
if (count == null) {
count = new MutableInt(0);
groupLocationCounts.put(group, loc, count);
}
count.increment();
}
return groupLocationCounts;
}
}
Aggregations