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;
}
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() {
}
};
}
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);
}
}
}
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);
}
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);
}
Aggregations