Search in sources :

Example 56 with TServerInstance

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

the class TabletStateChangeIterator method parseServers.

private Set<TServerInstance> parseServers(String servers) {
    if (servers == null)
        return null;
    // parse "host:port[INSTANCE]"
    Set<TServerInstance> result = new HashSet<>();
    if (!servers.isEmpty()) {
        for (String part : servers.split(",")) {
            String[] parts = part.split("\\[", 2);
            String hostport = parts[0];
            String instance = parts[1];
            if (instance != null && instance.endsWith("]"))
                instance = instance.substring(0, instance.length() - 1);
            result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
        }
    }
    return result;
}
Also used : TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) HashSet(java.util.HashSet)

Example 57 with TServerInstance

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

the class ZooTabletStateStore method iterator.

@Override
public ClosableIterator<TabletLocationState> iterator() {
    return new ClosableIterator<>() {

        boolean finished = false;

        @Override
        public boolean hasNext() {
            return !finished;
        }

        @Override
        public TabletLocationState next() {
            finished = true;
            try {
                TabletMetadata rootMeta = ample.readTablet(RootTable.EXTENT, ReadConsistency.EVENTUAL);
                TServerInstance currentSession = null;
                TServerInstance futureSession = null;
                TServerInstance lastSession = null;
                Location loc = rootMeta.getLocation();
                if (loc != null && loc.getType() == LocationType.FUTURE)
                    futureSession = loc;
                if (rootMeta.getLast() != null)
                    lastSession = rootMeta.getLast();
                if (loc != null && loc.getType() == LocationType.CURRENT) {
                    currentSession = loc;
                }
                List<Collection<String>> logs = new ArrayList<>();
                rootMeta.getLogs().forEach(logEntry -> {
                    logs.add(Collections.singleton(logEntry.filename));
                    log.debug("root tablet log {}", logEntry.filename);
                });
                return new TabletLocationState(RootTable.EXTENT, futureSession, currentSession, lastSession, null, logs, false);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void close() {
        }
    };
}
Also used : ArrayList(java.util.ArrayList) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) Collection(java.util.Collection) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Location(org.apache.accumulo.core.metadata.schema.TabletMetadata.Location)

Example 58 with TServerInstance

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

the class LiveTServerSet method checkServer.

private synchronized void checkServer(final Set<TServerInstance> updates, final Set<TServerInstance> doomed, final String path, final String zPath) throws InterruptedException, KeeperException {
    TServerInfo info = current.get(zPath);
    final var zLockPath = ServiceLock.path(path + "/" + zPath);
    ZcStat stat = new ZcStat();
    byte[] lockData = ServiceLock.getLockData(getZooCache(), zLockPath, stat);
    if (lockData == null) {
        if (info != null) {
            doomed.add(info.instance);
            current.remove(zPath);
            currentInstances.remove(info.instance);
        }
        Long firstSeen = locklessServers.get(zPath);
        if (firstSeen == null) {
            locklessServers.put(zPath, System.currentTimeMillis());
        } else if (System.currentTimeMillis() - firstSeen > MINUTES.toMillis(10)) {
            deleteServerNode(path + "/" + zPath);
            locklessServers.remove(zPath);
        }
    } else {
        locklessServers.remove(zPath);
        ServerServices services = new ServerServices(new String(lockData, UTF_8));
        HostAndPort client = services.getAddress(ServerServices.Service.TSERV_CLIENT);
        TServerInstance instance = new TServerInstance(client, stat.getEphemeralOwner());
        if (info == null) {
            updates.add(instance);
            TServerInfo tServerInfo = new TServerInfo(instance, new TServerConnection(client));
            current.put(zPath, tServerInfo);
            currentInstances.put(instance, tServerInfo);
        } else if (!info.instance.equals(instance)) {
            doomed.add(info.instance);
            updates.add(instance);
            TServerInfo tServerInfo = new TServerInfo(instance, new TServerConnection(client));
            current.put(zPath, tServerInfo);
            currentInstances.remove(info.instance);
            currentInstances.put(instance, tServerInfo);
        }
    }
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) ZcStat(org.apache.accumulo.fate.zookeeper.ZooCache.ZcStat) ServerServices(org.apache.accumulo.core.util.ServerServices) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 59 with TServerInstance

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

the class MetaDataTableScanner method createTabletLocationState.

public static TabletLocationState createTabletLocationState(Key k, Value v) throws IOException, BadLocationStateException {
    final SortedMap<Key, Value> decodedRow = WholeRowIterator.decodeRow(k, v);
    KeyExtent extent = null;
    TServerInstance future = null;
    TServerInstance current = null;
    TServerInstance last = null;
    SuspendingTServer suspend = null;
    long lastTimestamp = 0;
    List<Collection<String>> walogs = new ArrayList<>();
    boolean chopped = false;
    for (Entry<Key, Value> entry : decodedRow.entrySet()) {
        Key key = entry.getKey();
        Text row = key.getRow();
        Text cf = key.getColumnFamily();
        Text cq = key.getColumnQualifier();
        if (cf.compareTo(FutureLocationColumnFamily.NAME) == 0) {
            TServerInstance location = new TServerInstance(entry.getValue(), cq);
            if (future != null) {
                throw new BadLocationStateException("found two assignments for the same extent " + row + ": " + future + " and " + location, row);
            }
            future = location;
        } else if (cf.compareTo(CurrentLocationColumnFamily.NAME) == 0) {
            TServerInstance location = new TServerInstance(entry.getValue(), cq);
            if (current != null) {
                throw new BadLocationStateException("found two locations for the same extent " + row + ": " + current + " and " + location, row);
            }
            current = location;
        } else if (cf.compareTo(LogColumnFamily.NAME) == 0) {
            String[] split = entry.getValue().toString().split("\\|")[0].split(";");
            walogs.add(Arrays.asList(split));
        } else if (cf.compareTo(LastLocationColumnFamily.NAME) == 0) {
            if (lastTimestamp < entry.getKey().getTimestamp()) {
                last = new TServerInstance(entry.getValue(), cq);
            }
        } else if (cf.compareTo(ChoppedColumnFamily.NAME) == 0) {
            chopped = true;
        } else if (TabletColumnFamily.PREV_ROW_COLUMN.equals(cf, cq)) {
            extent = KeyExtent.fromMetaPrevRow(entry);
        } else if (SuspendLocationColumn.SUSPEND_COLUMN.equals(cf, cq)) {
            suspend = SuspendingTServer.fromValue(entry.getValue());
        }
    }
    if (extent == null) {
        String msg = "No prev-row for key extent " + decodedRow;
        log.error(msg);
        throw new BadLocationStateException(msg, k.getRow());
    }
    return new TabletLocationState(extent, future, current, last, suspend, walogs, chopped);
}
Also used : ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) BadLocationStateException(org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException) SuspendingTServer(org.apache.accumulo.core.metadata.SuspendingTServer) Value(org.apache.accumulo.core.data.Value) Collection(java.util.Collection) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) Key(org.apache.accumulo.core.data.Key)

Example 60 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance 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);
        TServerInstance tsi = new TServerInstance(fakeAddress, cString);
        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.isEmpty())
            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.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) HostAndPort(org.apache.accumulo.core.util.HostAndPort) 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