public TServerInstance getAssignment(SortedMap<TServerInstance,TabletServerStatus> locations, TServerInstance last) { if (locations.size() == 0) return null; if (last != null) { // Maintain locality String fakeSessionID = " "; TServerInstance simple = new TServerInstance(last.getLocation(), fakeSessionID); Iterator<TServerInstance> find = locations.tailMap(simple).keySet().iterator(); if (find.hasNext()) { TServerInstance current = find.next(); if (current.host().equals(last.host())) return current; } } // The strategy here is to walk through the locations and hand them back, one at a time // Grab an iterator off of the set of options; use a new iterator if it hands back something not // in the current list. if (assignments == null || !assignments.hasNext()) assignments = randomize(locations.keySet()).iterator(); TServerInstance result = assignments.next(); if (!locations.containsKey(result)) { assignments = null; return randomize(locations.keySet()).iterator().next(); } return result; }
public TServerInstance(HostAndPort address, String session) { this.location = address; this.session = session; this.cachedStringRepresentation = hostPort() + "[" + session + "]"; }
@Override public void setLocations(Collection<Assignment> assignments) throws DistributedStoreException { if (assignments.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); Assignment assignment = assignments.iterator().next(); if (assignment.tablet.compareTo(RootTable.EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); String value = assignment.server.getLocation() + "|" + assignment.server.getSession(); Iterator<TabletLocationState> currentIter = iterator(); TabletLocationState current = currentIter.next(); if (current.current != null) { throw new DistributedStoreException( "Trying to set the root tablet location: it is already set to " + current.current); } if (!current.future.equals(assignment.server)) { throw new DistributedStoreException("Root tablet is already assigned to " + current.future); } store.put(RootTable.ZROOT_TABLET_LOCATION, value.getBytes(UTF_8)); store.put(RootTable.ZROOT_TABLET_LAST_LOCATION, value.getBytes(UTF_8)); // Make the following unnecessary by making the entire update atomic store.remove(RootTable.ZROOT_TABLET_FUTURE_LOCATION); log.debug("Put down root tablet location"); }
public void putFutureLocation(Mutation m) { m.put(TabletsSection.FutureLocationColumnFamily.NAME, asColumnQualifier(), asMutationValue()); }
TServerInstance find(Map<String,TServerInfo> servers, String tabletServer) { HostAndPort addr; String sessionId = null; if (tabletServer.charAt(tabletServer.length() - 1) == ']') { int index = tabletServer.indexOf('['); if (index == -1) { throw new IllegalArgumentException("Could not parse tabletserver '" + tabletServer + "'"); } addr = AddressUtil.parseAddress(tabletServer.substring(0, index), false); // Strip off the last bracket sessionId = tabletServer.substring(index + 1, tabletServer.length() - 1); } else { addr = AddressUtil.parseAddress(tabletServer, false); } for (Entry<String,TServerInfo> entry : servers.entrySet()) { if (entry.getValue().instance.getLocation().equals(addr)) { // Return the instance if we have no desired session ID, or we match the desired session ID if (sessionId == null || sessionId.equals(entry.getValue().instance.getSession())) return entry.getValue().instance; } } return null; }
self.putLastLocation(m); if (lastLocation != null && !lastLocation.equals(self)) lastLocation.clearLastLocation(m);
protected TServerInstance parse(byte[] current) { String str = new String(current, UTF_8); String[] parts = str.split("[|]", 2); HostAndPort address = HostAndPort.fromString(parts[0]); if (parts.length > 1 && parts[1] != null && parts[1].length() > 0) { return new TServerInstance(address, parts[1]); } else { // a 1.2 location specification: DO NOT WANT return null; } }
if (server.equals(this.master.migrations.get(tls.extent))) this.master.migrations.remove(tls.extent); break; case ASSIGNED_TO_DEAD_SERVER: assignedToDeadServers.add(tls); if (server.equals(this.master.migrations.get(tls.extent))) this.master.migrations.remove(tls.extent); TServerInstance tserver = tls.futureOrCurrent(); .tailMap(new TServerInstance(tls.suspend.server, " ")).keySet().iterator(); if (find.hasNext()) { TServerInstance found = find.next(); if (found.getLocation().equals(tls.suspend.server)) { returnInstance = found;
Mutation m = new Mutation(tls.extent.getMetadataEntry()); if (tls.current != null) { tls.current.clearLocation(m); if (logsForDeadServers != null) { List<Path> logs = logsForDeadServers.get(tls.current); if (logs != null) { for (Path log : logs) { LogEntry entry = new LogEntry(tls.extent, 0, tls.current.hostPort(), log.toString()); m.put(entry.getColumnFamily(), entry.getColumnQualifier(), entry.getValue()); SuspendingTServer suspender = new SuspendingTServer(tls.current.getLocation(), suspensionTimestamp); suspender.setSuspension(m); tls.future.clearFutureLocation(m);
ServerServices services = new ServerServices(new String(lockData, UTF_8)); HostAndPort client = services.getAddress(ServerServices.Service.TSERV_CLIENT); TServerInstance instance = new TServerInstance(client, stat.getEphemeralOwner()); current.put(zPath, tServerInfo); currentInstances.put(instance, tServerInfo); } else if (!info.instance.equals(instance)) { doomed.add(info.instance); updates.add(instance);
@Override public boolean equals(Object o) { if (o instanceof TserverGroupInfo) { TserverGroupInfo otgi = (TserverGroupInfo) o; return tsi.equals(otgi.tsi); } return false; }
@Override public String toString() { return tsi.toString(); }
public String hostPort() { return getLocation().toString(); }
public synchronized TServerConnection getConnection(TServerInstance server) throws TException { if (server == null) return null; TServerInfo serverInfo = current.get(server.hostPort()); // lock was lost? if (serverInfo == null) return null; // instance changed? if (!serverInfo.instance.equals(server)) return null; TServerConnection result = serverInfo.connection; return result; }
List<TServerInstance> subset = new ArrayList<>(); master.onlineTabletServers().forEach(t -> { if (regex.matcher(t.host()).matches()) { subset.add(t); server = servers[random.nextInt(servers.length)].getLocation(); client = ThriftUtil.getTServerClient(server, master.getContext(), timeInMillis); List<String> attempt1 = Collections.singletonList(file);
Map<String,SortedMap<TServerInstance,TabletServerStatus>> newPools = new HashMap<>(); for (Entry<TServerInstance,TabletServerStatus> e : current.entrySet()) { List<String> poolNames = getPoolNamesForHost(e.getKey().host()); for (String pool : poolNames) { SortedMap<TServerInstance,TabletServerStatus> np = newPools.get(pool);
@Override public boolean equals(Object obj) { if (obj instanceof TServerInstance) { return compareTo((TServerInstance) obj) == 0; } return false; }
public void clearFutureLocation(Mutation m) { m.putDelete(TabletsSection.FutureLocationColumnFamily.NAME, asColumnQualifier()); }
public static void replaceDatafiles(ServerContext context, KeyExtent extent, Set<FileRef> datafilesToDelete, Set<FileRef> scanFiles, FileRef path, Long compactionId, DataFileValue size, String address, TServerInstance lastLocation, ZooLock zooLock, boolean insertDeleteFlags) { if (insertDeleteFlags) { // add delete flags for those paths before the data file reference is removed MetadataTableUtil.addDeleteEntries(extent, datafilesToDelete, context); } // replace data file references to old mapfiles with the new mapfiles Mutation m = new Mutation(extent.getMetadataEntry()); for (FileRef pathToRemove : datafilesToDelete) m.putDelete(DataFileColumnFamily.NAME, pathToRemove.meta()); for (FileRef scanFile : scanFiles) m.put(ScanFileColumnFamily.NAME, scanFile.meta(), new Value(new byte[0])); if (size.getNumEntries() > 0) m.put(DataFileColumnFamily.NAME, path.meta(), new Value(size.encode())); if (compactionId != null) TabletsSection.ServerColumnFamily.COMPACT_COLUMN.put(m, new Value(("" + compactionId).getBytes())); TServerInstance self = getTServerInstance(address, zooLock); self.putLastLocation(m); // remove the old location if (lastLocation != null && !lastLocation.equals(self)) lastLocation.clearLastLocation(m); MetadataTableUtil.update(context, zooLock, m, extent); }
private Set<TServerInstance> parseServers(String servers) { if (servers == null) return null; // parse "host:port[INSTANCE]" Set<TServerInstance> result = new HashSet<>(); if (servers.length() > 0) { 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; }