use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class BaseHostRegexTableLoadBalancerTest method createCurrent.
protected SortedMap<TServerInstance, TabletServerStatus> createCurrent(int numTservers) {
String base = "192.168.0.";
TreeMap<TServerInstance, TabletServerStatus> current = new TreeMap<>();
for (int i = 1; i <= numTservers; i++) {
TabletServerStatus status = new TabletServerStatus();
Map<String, TableInfo> tableMap = new HashMap<>();
tableMap.put(FOO.getId().canonicalID(), new TableInfo());
tableMap.put(BAR.getId().canonicalID(), new TableInfo());
tableMap.put(BAZ.getId().canonicalID(), new TableInfo());
status.setTableMap(tableMap);
current.put(new TServerInstance(base + i + ":9997", 1), status);
}
// now put all of the tablets on one server
for (Map.Entry<String, TServerInstance> entry : initialTableLocation.entrySet()) {
TabletServerStatus status = current.get(entry.getValue());
if (status != null) {
String tableId = getTableOperations().tableIdMap().get(entry.getKey());
status.getTableMap().get(tableId).setOnlineTablets(5);
}
}
return current;
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class ChaoticLoadBalancerTest method testAssignMigrations.
@Test
public void testAssignMigrations() {
servers.clear();
servers.put(new TServerInstance(HostAndPort.fromParts("127.0.0.1", 1234), "a"), new FakeTServer());
servers.put(new TServerInstance(HostAndPort.fromParts("127.0.0.1", 1235), "b"), new FakeTServer());
servers.put(new TServerInstance(HostAndPort.fromParts("127.0.0.1", 1236), "c"), new FakeTServer());
Map<KeyExtent, TServerInstance> metadataTable = new TreeMap<>();
String table = "t1";
metadataTable.put(makeExtent(table, null, null), null);
table = "t2";
metadataTable.put(makeExtent(table, "a", null), null);
metadataTable.put(makeExtent(table, null, "a"), null);
table = "t3";
metadataTable.put(makeExtent(table, "a", null), null);
metadataTable.put(makeExtent(table, "b", "a"), null);
metadataTable.put(makeExtent(table, "c", "b"), null);
metadataTable.put(makeExtent(table, "d", "c"), null);
metadataTable.put(makeExtent(table, "e", "d"), null);
metadataTable.put(makeExtent(table, null, "e"), null);
TestChaoticLoadBalancer balancer = new TestChaoticLoadBalancer();
SortedMap<TServerInstance, TabletServerStatus> current = new TreeMap<>();
for (Entry<TServerInstance, FakeTServer> entry : servers.entrySet()) {
current.put(entry.getKey(), entry.getValue().getStatus(entry.getKey()));
}
Map<KeyExtent, TServerInstance> assignments = new HashMap<>();
balancer.getAssignments(getAssignments(servers), metadataTable, assignments);
assertEquals(assignments.size(), metadataTable.size());
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class DefaultLoadBalancerTest method testAssignMigrations.
@Test
public void testAssignMigrations() {
servers.put(new TServerInstance(HostAndPort.fromParts("127.0.0.1", 1234), "a"), new FakeTServer());
servers.put(new TServerInstance(HostAndPort.fromParts("127.0.0.2", 1234), "b"), new FakeTServer());
servers.put(new TServerInstance(HostAndPort.fromParts("127.0.0.3", 1234), "c"), new FakeTServer());
List<KeyExtent> metadataTable = new ArrayList<>();
String table = "t1";
metadataTable.add(makeExtent(table, null, null));
table = "t2";
metadataTable.add(makeExtent(table, "a", null));
metadataTable.add(makeExtent(table, null, "a"));
table = "t3";
metadataTable.add(makeExtent(table, "a", null));
metadataTable.add(makeExtent(table, "b", "a"));
metadataTable.add(makeExtent(table, "c", "b"));
metadataTable.add(makeExtent(table, "d", "c"));
metadataTable.add(makeExtent(table, "e", "d"));
metadataTable.add(makeExtent(table, null, "e"));
Collections.sort(metadataTable);
TestDefaultLoadBalancer balancer = new TestDefaultLoadBalancer();
SortedMap<TServerInstance, TabletServerStatus> current = new TreeMap<>();
for (Entry<TServerInstance, FakeTServer> entry : servers.entrySet()) {
current.put(entry.getKey(), entry.getValue().getStatus(entry.getKey()));
}
assignTablets(metadataTable, servers, current, balancer);
// Verify that the counts on the tables are correct
Map<String, Integer> expectedCounts = new HashMap<>();
expectedCounts.put("t1", 1);
expectedCounts.put("t2", 1);
expectedCounts.put("t3", 2);
checkBalance(metadataTable, servers, expectedCounts);
// Rebalance once
for (Entry<TServerInstance, FakeTServer> entry : servers.entrySet()) {
current.put(entry.getKey(), entry.getValue().getStatus(entry.getKey()));
}
// Nothing should happen, we are balanced
ArrayList<TabletMigration> out = new ArrayList<>();
balancer.getMigrations(current, out);
assertEquals(out.size(), 0);
// Take down a tabletServer
TServerInstance first = current.keySet().iterator().next();
current.remove(first);
FakeTServer remove = servers.remove(first);
// reassign offline extents
assignTablets(remove.extents, servers, current, balancer);
checkBalance(metadataTable, servers, null);
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class DefaultLoadBalancerTest method assignTablets.
private void assignTablets(List<KeyExtent> metadataTable, Map<TServerInstance, FakeTServer> servers, SortedMap<TServerInstance, TabletServerStatus> status, TestDefaultLoadBalancer balancer) {
// Assign tablets
for (KeyExtent extent : metadataTable) {
TServerInstance assignment = balancer.getAssignment(status, extent, last.get(extent));
assertNotNull(assignment);
assertFalse(servers.get(assignment).extents.contains(extent));
servers.get(assignment).extents.add(extent);
last.put(extent, assignment);
}
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class HostRegexTableLoadBalancerReconfigurationTest method getOnlineTabletsForTable.
@Override
public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, Table.ID tableId) throws ThriftSecurityException, TException {
List<TabletStats> tablets = new ArrayList<>();
// Report assignment information
for (Entry<KeyExtent, TServerInstance> e : this.assignments.entrySet()) {
if (e.getValue().equals(tserver) && e.getKey().getTableId().equals(tableId)) {
TabletStats ts = new TabletStats();
ts.setExtent(e.getKey().toThrift());
tablets.add(ts);
}
}
return tablets;
}
Aggregations