Search in sources :

Example 26 with TServerInstance

use of org.apache.accumulo.core.metadata.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, last.get(extent));
        assertNotNull(assignment);
        assertFalse(servers.get(assignment).extents.contains(extent));
        servers.get(assignment).extents.add(extent);
        last.put(extent, assignment);
    }
}
Also used : KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 27 with TServerInstance

use of org.apache.accumulo.core.metadata.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());
    }
    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());
    }
    // 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);
}
Also used : TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Test(org.junit.Test)

Example 28 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.

the class HostRegexTableLoadBalancerReconfigurationTest method getOnlineTabletsForTable.

@Override
public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, TableId tableId) {
    List<TabletStats> tablets = new ArrayList<>();
    // Report assignment information
    for (Entry<KeyExtent, TServerInstance> e : this.assignments.entrySet()) {
        if (e.getValue().equals(tserver) && e.getKey().tableId().equals(tableId)) {
            TabletStats ts = new TabletStats();
            ts.setExtent(e.getKey().toThrift());
            tablets.add(ts);
        }
    }
    return tablets;
}
Also used : TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 29 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.

the class HostRegexTableLoadBalancerReconfigurationTest method testConfigurationChanges.

@Test
public void testConfigurationChanges() {
    ServerContext context1 = createMockContext();
    replay(context1);
    final TestServerConfigurationFactory factory = new TestServerConfigurationFactory(context1);
    ServerContext context2 = createMockContext();
    expect(context2.getConfiguration()).andReturn(factory.getSystemConfiguration()).anyTimes();
    expect(context2.getTableConfiguration(FOO.getId())).andReturn(factory.getTableConfiguration(FOO.getId())).anyTimes();
    expect(context2.getTableConfiguration(BAR.getId())).andReturn(factory.getTableConfiguration(BAR.getId())).anyTimes();
    expect(context2.getTableConfiguration(BAZ.getId())).andReturn(factory.getTableConfiguration(BAZ.getId())).anyTimes();
    replay(context2);
    init(context2);
    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);
    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())) {
                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())) {
            fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().getHost());
        }
    }
    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);
    assertEquals(0, migrationsOut.size());
    // Change property, simulate call by TableConfWatcher
    ((ConfigurationCopy) factory.getSystemConfiguration()).set(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "r01.*");
    // Wait to trigger the out of bounds check and the repool check
    UtilWaitThread.sleep(10000);
    this.balance(Collections.unmodifiableSortedMap(allTabletServers), migrations, migrationsOut);
    assertEquals(5, migrationsOut.size());
    for (TabletMigration migration : migrationsOut) {
        assertTrue(migration.newServer.getHost().startsWith("192.168.0.1") || migration.newServer.getHost().startsWith("192.168.0.2") || migration.newServer.getHost().startsWith("192.168.0.3") || migration.newServer.getHost().startsWith("192.168.0.4") || migration.newServer.getHost().startsWith("192.168.0.5"));
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ServerContext(org.apache.accumulo.server.ServerContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.

the class TabletLocationStateTest method testGetState_Hosted.

@Test
public void testGetState_Hosted() throws Exception {
    Set<TServerInstance> liveServers = new java.util.HashSet<>();
    liveServers.add(current);
    tls = new TabletLocationState(keyExtent, null, current, last, null, walogs, true);
    assertEquals(TabletState.HOSTED, tls.getState(liveServers));
}
Also used : TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Test(org.junit.Test)

Aggregations

TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)89 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)32 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)30 HashMap (java.util.HashMap)21 ServerContext (org.apache.accumulo.server.ServerContext)18 TabletLocationState (org.apache.accumulo.core.metadata.TabletLocationState)17 HostAndPort (org.apache.accumulo.core.util.HostAndPort)14 HashSet (java.util.HashSet)13 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)13 TableId (org.apache.accumulo.core.data.TableId)12 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)11 List (java.util.List)10 LiveTServerSet (org.apache.accumulo.server.manager.LiveTServerSet)10 TException (org.apache.thrift.TException)10 TreeMap (java.util.TreeMap)9 UUID (java.util.UUID)9 TreeSet (java.util.TreeSet)8 Key (org.apache.accumulo.core.data.Key)8 Value (org.apache.accumulo.core.data.Value)8