Search in sources :

Example 21 with HostAndPort

use of org.apache.accumulo.core.util.HostAndPort 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);
        String fakeInstance = cString;
        TServerInstance tsi = new TServerInstance(fakeAddress, fakeInstance);
        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.size() == 0)
            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.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Entry(java.util.Map.Entry) Test(org.junit.Test)

Example 22 with HostAndPort

use of org.apache.accumulo.core.util.HostAndPort in project accumulo by apache.

the class WrongTabletTest method main.

public static void main(String[] args) {
    final Opts opts = new Opts();
    opts.parseArgs(WrongTabletTest.class.getName(), args);
    final HostAndPort location = HostAndPort.fromString(opts.location);
    final Instance inst = opts.getInstance();
    final ServerConfigurationFactory conf = new ServerConfigurationFactory(inst);
    final ClientContext context = new AccumuloServerContext(inst, conf) {

        @Override
        public synchronized Credentials getCredentials() {
            try {
                return new Credentials(opts.getPrincipal(), opts.getToken());
            } catch (AccumuloSecurityException e) {
                throw new RuntimeException(e);
            }
        }
    };
    try {
        TabletClientService.Iface client = ThriftUtil.getTServerClient(location, context);
        Mutation mutation = new Mutation(new Text("row_0003750001"));
        mutation.putDelete(new Text("colf"), new Text("colq"));
        client.update(Tracer.traceInfo(), context.rpcCreds(), new KeyExtent(Table.ID.of("!!"), null, new Text("row_0003750000")).toThrift(), mutation.toThrift(), TDurability.DEFAULT);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) ClientOpts(org.apache.accumulo.server.cli.ClientOpts) Instance(org.apache.accumulo.core.client.Instance) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) Mutation(org.apache.accumulo.core.data.Mutation) Credentials(org.apache.accumulo.core.client.impl.Credentials)

Example 23 with HostAndPort

use of org.apache.accumulo.core.util.HostAndPort in project accumulo by apache.

the class Admin method stopTabletServer.

private static void stopTabletServer(final ClientContext context, List<String> servers, final boolean force) throws AccumuloException, AccumuloSecurityException {
    if (context.getInstance().getMasterLocations().size() == 0) {
        log.info("No masters running. Not attempting safe unload of tserver.");
        return;
    }
    final Instance instance = context.getInstance();
    final String zTServerRoot = getTServersZkPath(instance);
    final ZooCache zc = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    for (String server : servers) {
        for (int port : context.getConfiguration().getPort(Property.TSERV_CLIENTPORT)) {
            HostAndPort address = AddressUtil.parseAddress(server, port);
            final String finalServer = qualifyWithZooKeeperSessionId(zTServerRoot, zc, address.toString());
            log.info("Stopping server {}", finalServer);
            MasterClient.executeVoid(context, new ClientExec<MasterClientService.Client>() {

                @Override
                public void execute(MasterClientService.Client client) throws Exception {
                    client.shutdownTabletServer(Tracer.traceInfo(), context.rpcCreds(), finalServer, force);
                }
            });
        }
    }
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) ZooCacheFactory(org.apache.accumulo.fate.zookeeper.ZooCacheFactory) Instance(org.apache.accumulo.core.client.Instance) MasterClientService(org.apache.accumulo.core.master.thrift.MasterClientService) MasterClient(org.apache.accumulo.core.client.impl.MasterClient) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 24 with HostAndPort

use of org.apache.accumulo.core.util.HostAndPort 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 25 with HostAndPort

use of org.apache.accumulo.core.util.HostAndPort 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

HostAndPort (org.apache.accumulo.core.util.HostAndPort)38 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)12 ArrayList (java.util.ArrayList)11 TTransportException (org.apache.thrift.transport.TTransportException)10 AccumuloException (org.apache.accumulo.core.client.AccumuloException)8 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)8 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)8 TException (org.apache.thrift.TException)8 UnknownHostException (java.net.UnknownHostException)7 IOException (java.io.IOException)6 Instance (org.apache.accumulo.core.client.Instance)6 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)6 TabletClientService (org.apache.accumulo.core.tabletserver.thrift.TabletClientService)6 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)6 KeeperException (org.apache.zookeeper.KeeperException)6 Test (org.junit.Test)6 Connector (org.apache.accumulo.core.client.Connector)5 Client (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)5 MasterClient (org.apache.accumulo.core.client.impl.MasterClient)4 Text (org.apache.hadoop.io.Text)4