Search in sources :

Example 11 with TabletMigration

use of org.apache.accumulo.server.master.state.TabletMigration in project accumulo by apache.

the class HostRegexTableLoadBalancerTest method testOutOfBoundsTablets.

@Test
public void testOutOfBoundsTablets() {
    init(new AccumuloServerContext(instance, factory));
    // Wait to trigger the out of bounds check which will call our version of getOnlineTabletsForTable
    UtilWaitThread.sleep(11000);
    Set<KeyExtent> migrations = new HashSet<>();
    List<TabletMigration> migrationsOut = new ArrayList<>();
    this.balance(createCurrent(15), migrations, migrationsOut);
    Assert.assertEquals(2, migrationsOut.size());
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) ArrayList(java.util.ArrayList) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with TabletMigration

use of org.apache.accumulo.server.master.state.TabletMigration in project accumulo by apache.

the class TableLoadBalancerTest method test.

@Test
public void test() throws Exception {
    final Instance inst = EasyMock.createMock(Instance.class);
    EasyMock.expect(inst.getInstanceID()).andReturn(UUID.nameUUIDFromBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }).toString()).anyTimes();
    EasyMock.expect(inst.getZooKeepers()).andReturn("10.0.0.1:1234").anyTimes();
    EasyMock.expect(inst.getZooKeepersSessionTimeOut()).andReturn(30_000).anyTimes();
    EasyMock.replay(inst);
    ServerConfigurationFactory confFactory = new ServerConfigurationFactory(inst) {

        @Override
        public TableConfiguration getTableConfiguration(Table.ID tableId) {
            // create a dummy namespaceConfiguration to satisfy requireNonNull in TableConfiguration constructor
            NamespaceConfiguration dummyConf = new NamespaceConfiguration(null, inst, null);
            return new TableConfiguration(inst, tableId, dummyConf) {

                @Override
                public String get(Property property) {
                    // fake the get table configuration so the test doesn't try to look in zookeeper for per-table classpath stuff
                    return DefaultConfiguration.getInstance().get(property);
                }
            };
        }
    };
    String t1Id = TABLE_ID_MAP.get("t1"), t2Id = TABLE_ID_MAP.get("t2"), t3Id = TABLE_ID_MAP.get("t3");
    state = new TreeMap<>();
    TServerInstance svr = mkts("10.0.0.1", "0x01020304");
    state.put(svr, status(t1Id, 10, t2Id, 10, t3Id, 10));
    Set<KeyExtent> migrations = Collections.emptySet();
    List<TabletMigration> migrationsOut = new ArrayList<>();
    TableLoadBalancer tls = new TableLoadBalancer();
    tls.init(new AccumuloServerContext(inst, confFactory));
    tls.balance(state, migrations, migrationsOut);
    Assert.assertEquals(0, migrationsOut.size());
    state.put(mkts("10.0.0.2", "0x02030405"), status());
    tls = new TableLoadBalancer();
    tls.init(new AccumuloServerContext(inst, confFactory));
    tls.balance(state, migrations, migrationsOut);
    int count = 0;
    Map<Table.ID, Integer> movedByTable = new HashMap<>();
    movedByTable.put(Table.ID.of(t1Id), 0);
    movedByTable.put(Table.ID.of(t2Id), 0);
    movedByTable.put(Table.ID.of(t3Id), 0);
    for (TabletMigration migration : migrationsOut) {
        if (migration.oldServer.equals(svr))
            count++;
        Table.ID key = migration.tablet.getTableId();
        movedByTable.put(key, movedByTable.get(key) + 1);
    }
    Assert.assertEquals(15, count);
    for (Integer moved : movedByTable.values()) {
        Assert.assertEquals(5, moved.intValue());
    }
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Table(org.apache.accumulo.core.client.impl.Table) TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) Instance(org.apache.accumulo.core.client.Instance) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) UUID(java.util.UUID) NamespaceConfiguration(org.apache.accumulo.server.conf.NamespaceConfiguration) Property(org.apache.accumulo.core.conf.Property) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) Test(org.junit.Test)

Example 13 with TabletMigration

use of org.apache.accumulo.server.master.state.TabletMigration in project accumulo by apache.

the class ChaoticLoadBalancerTest method testUnevenAssignment.

@Test
public void testUnevenAssignment() {
    servers.clear();
    for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
        String cString = Character.toString(c);
        HostAndPort fakeAddress = HostAndPort.fromParts("127.0.0.1", c);
        String fakeInstance = cString;
        TServerInstance tsi = new TServerInstance(fakeAddress, fakeInstance);
        FakeTServer fakeTServer = new FakeTServer();
        servers.put(tsi, fakeTServer);
        fakeTServer.extents.add(makeExtent(cString, null, null));
    }
    // Put more tablets on one server, but not more than the number of servers
    Entry<TServerInstance, FakeTServer> first = servers.entrySet().iterator().next();
    first.getValue().extents.add(makeExtent("newTable", "a", null));
    first.getValue().extents.add(makeExtent("newTable", "b", "a"));
    first.getValue().extents.add(makeExtent("newTable", "c", "b"));
    first.getValue().extents.add(makeExtent("newTable", "d", "c"));
    first.getValue().extents.add(makeExtent("newTable", "e", "d"));
    first.getValue().extents.add(makeExtent("newTable", "f", "e"));
    first.getValue().extents.add(makeExtent("newTable", "g", "f"));
    first.getValue().extents.add(makeExtent("newTable", "h", "g"));
    first.getValue().extents.add(makeExtent("newTable", "i", null));
    TestChaoticLoadBalancer balancer = new TestChaoticLoadBalancer();
    Set<KeyExtent> migrations = Collections.emptySet();
    // Just want to make sure it gets some migrations, randomness prevents guarantee of a defined amount, or even expected amount
    List<TabletMigration> migrationsOut = new ArrayList<>();
    while (migrationsOut.size() != 0) {
        balancer.balance(getAssignments(servers), migrations, migrationsOut);
    }
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) Test(org.junit.Test)

Example 14 with TabletMigration

use of org.apache.accumulo.server.master.state.TabletMigration in project accumulo by apache.

the class DefaultLoadBalancerTest method testUnevenAssignment.

@Test
public void testUnevenAssignment() {
    for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
        String cString = Character.toString(c);
        HostAndPort fakeAddress = HostAndPort.fromParts("127.0.0.1", c);
        String fakeInstance = cString;
        TServerInstance tsi = new TServerInstance(fakeAddress, fakeInstance);
        FakeTServer fakeTServer = new FakeTServer();
        servers.put(tsi, fakeTServer);
        fakeTServer.extents.add(makeExtent(cString, null, null));
    }
    // Put more tablets on one server, but not more than the number of servers
    Entry<TServerInstance, FakeTServer> first = servers.entrySet().iterator().next();
    first.getValue().extents.add(makeExtent("newTable", "a", null));
    first.getValue().extents.add(makeExtent("newTable", "b", "a"));
    first.getValue().extents.add(makeExtent("newTable", "c", "b"));
    first.getValue().extents.add(makeExtent("newTable", "d", "c"));
    first.getValue().extents.add(makeExtent("newTable", "e", "d"));
    first.getValue().extents.add(makeExtent("newTable", "f", "e"));
    first.getValue().extents.add(makeExtent("newTable", "g", "f"));
    first.getValue().extents.add(makeExtent("newTable", "h", "g"));
    first.getValue().extents.add(makeExtent("newTable", "i", null));
    TestDefaultLoadBalancer balancer = new TestDefaultLoadBalancer();
    Set<KeyExtent> migrations = Collections.emptySet();
    int moved = 0;
    // balance until we can't balance no more!
    while (true) {
        List<TabletMigration> migrationsOut = new ArrayList<>();
        balancer.balance(getAssignments(servers), migrations, migrationsOut);
        if (migrationsOut.size() == 0)
            break;
        for (TabletMigration migration : migrationsOut) {
            if (servers.get(migration.oldServer).extents.remove(migration.tablet))
                moved++;
            servers.get(migration.newServer).extents.add(migration.tablet);
        }
    }
    assertEquals(8, moved);
}
Also used : TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Test(org.junit.Test)

Aggregations

TabletMigration (org.apache.accumulo.server.master.state.TabletMigration)14 ArrayList (java.util.ArrayList)13 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)13 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)9 Test (org.junit.Test)9 AccumuloServerContext (org.apache.accumulo.server.AccumuloServerContext)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Table (org.apache.accumulo.core.client.impl.Table)4 TKeyExtent (org.apache.accumulo.core.data.thrift.TKeyExtent)3 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)3 TabletStats (org.apache.accumulo.core.tabletserver.thrift.TabletStats)3 HostAndPort (org.apache.accumulo.core.util.HostAndPort)3 TreeMap (java.util.TreeMap)2 TableOperations (org.apache.accumulo.core.client.admin.TableOperations)2 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)2 TException (org.apache.thrift.TException)2 Entry (java.util.Map.Entry)1 Random (java.util.Random)1 SortedMap (java.util.SortedMap)1