Search in sources :

Example 61 with TServerInstance

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

the class DefaultLoadBalancerTest method testUnevenAssignment2.

@Test
public void testUnevenAssignment2() {
    // make 26 servers
    for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
        String cString = Character.toString(c);
        HostAndPort fakeAddress = HostAndPort.fromParts("127.0.0.1", c);
        TServerInstance tsi = new TServerInstance(fakeAddress, cString);
        FakeTServer fakeTServer = new FakeTServer();
        servers.put(tsi, fakeTServer);
    }
    // put 60 tablets on 25 of them
    List<Entry<TServerInstance, FakeTServer>> shortList = new ArrayList<>(servers.entrySet());
    Entry<TServerInstance, FakeTServer> shortServer = shortList.remove(0);
    int c = 0;
    for (int i = 0; i < 60; i++) {
        for (Entry<TServerInstance, FakeTServer> entry : shortList) {
            entry.getValue().extents.add(makeExtent("t" + c, null, null));
        }
    }
    // put 10 on the that short server:
    for (int i = 0; i < 10; i++) {
        shortServer.getValue().extents.add(makeExtent("s" + i, null, 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.isEmpty())
            break;
        for (TabletMigration migration : migrationsOut) {
            if (servers.get(migration.oldServer).extents.remove(migration.tablet))
                moved++;
            last.remove(migration.tablet);
            servers.get(migration.newServer).extents.add(migration.tablet);
            last.put(migration.tablet, migration.newServer);
        }
    }
    // average is 58, with 2 at 59: we need 48 more moved to the short server
    assertEquals(48, moved);
}
Also used : TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Entry(java.util.Map.Entry) Test(org.junit.Test)

Example 62 with TServerInstance

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

the class TableLoadBalancerTest method test.

@Test
public void test() {
    final ServerContext context = createMockContext();
    TableConfiguration conf = createMock(TableConfiguration.class);
    // Eclipse might show @SuppressWarnings("removal") as unnecessary.
    // Eclipse is wrong. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=565271
    @SuppressWarnings("removal") Property TABLE_CLASSPATH = Property.TABLE_CLASSPATH;
    expect(conf.resolve(Property.TABLE_CLASSLOADER_CONTEXT, TABLE_CLASSPATH)).andReturn(Property.TABLE_CLASSLOADER_CONTEXT).anyTimes();
    expect(conf.get(Property.TABLE_CLASSLOADER_CONTEXT)).andReturn("").anyTimes();
    expect(context.getTableConfiguration(EasyMock.anyObject())).andReturn(conf).anyTimes();
    replay(context, conf);
    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(context);
    tls.balance(state, migrations, migrationsOut);
    assertEquals(0, migrationsOut.size());
    state.put(mkts("10.0.0.2", "0x02030405"), status());
    tls = new TableLoadBalancer();
    tls.init(context);
    tls.balance(state, migrations, migrationsOut);
    int count = 0;
    Map<TableId, Integer> movedByTable = new HashMap<>();
    movedByTable.put(TableId.of(t1Id), 0);
    movedByTable.put(TableId.of(t2Id), 0);
    movedByTable.put(TableId.of(t3Id), 0);
    for (TabletMigration migration : migrationsOut) {
        if (migration.oldServer.equals(svr)) {
            count++;
        }
        TableId key = migration.tablet.tableId();
        movedByTable.put(key, movedByTable.get(key) + 1);
    }
    assertEquals(15, count);
    for (Integer moved : movedByTable.values()) {
        assertEquals(5, moved.intValue());
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) 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) MockServerContext(org.apache.accumulo.server.MockServerContext) ServerContext(org.apache.accumulo.server.ServerContext) Property(org.apache.accumulo.core.conf.Property) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) Test(org.junit.Test)

Example 63 with TServerInstance

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

the class TabletLocationStateTest method testGetState_Dead2.

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

Example 64 with TServerInstance

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

the class TabletLocationStateTest method testGetState_Assigned.

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

Example 65 with TServerInstance

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

the class ManagerMetadataUtil method updateTabletDataFile.

/**
 * Update tablet file data from flush. Returns a StoredTabletFile if there are data entries.
 */
public static Optional<StoredTabletFile> updateTabletDataFile(ServerContext context, KeyExtent extent, TabletFile newDatafile, DataFileValue dfv, MetadataTime time, String address, ServiceLock zooLock, Set<String> unusedWalLogs, TServerInstance lastLocation, long flushId) {
    TabletMutator tablet = context.getAmple().mutateTablet(extent);
    // if there are no entries, the path doesn't get stored in metadata table, only the flush ID
    Optional<StoredTabletFile> newFile = Optional.empty();
    // if entries are present, write to path to metadata table
    if (dfv.getNumEntries() > 0) {
        tablet.putFile(newDatafile, dfv);
        tablet.putTime(time);
        newFile = Optional.of(newDatafile.insert());
        TServerInstance self = getTServerInstance(address, zooLock);
        tablet.putLocation(self, LocationType.LAST);
        // remove the old location
        if (lastLocation != null && !lastLocation.equals(self)) {
            tablet.deleteLocation(lastLocation, LocationType.LAST);
        }
    }
    tablet.putFlushId(flushId);
    unusedWalLogs.forEach(tablet::deleteWal);
    tablet.putZooLock(zooLock);
    tablet.mutate();
    return newFile;
}
Also used : TabletMutator(org.apache.accumulo.core.metadata.schema.Ample.TabletMutator) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

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