public String hostPort() { return getLocation().toString(); }
public String host() { return getLocation().getHost(); }
@Override public List<String> getActiveTservers(TInfo tinfo, TCredentials credentials) { Set<TServerInstance> tserverInstances = master.onlineTabletServers(); List<String> servers = new ArrayList<>(); for (TServerInstance tserverInstance : tserverInstances) { servers.add(tserverInstance.getLocation().toString()); } return servers; }
private Value asMutationValue() { return new Value(getLocation().toString().getBytes(UTF_8)); }
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; }
@Override public void setFutureLocations(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); } store.put(RootTable.ZROOT_TABLET_FUTURE_LOCATION, value.getBytes(UTF_8)); }
TServerInstance simple = new TServerInstance(last.getLocation(), fakeSessionID); Iterator<TServerInstance> find = current.tailMap(simple).keySet().iterator(); if (find.hasNext()) {
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; }
@Override public Repo<Master> call(long tid, Master master) throws Exception { // suppress assignment of tablets to the server if (force) { ZooReaderWriter zoo = master.getContext().getZooReaderWriter(); String path = master.getZooKeeperRoot() + Constants.ZTSERVERS + "/" + server.getLocation(); ZooLock.deleteLock(zoo, path); path = master.getZooKeeperRoot() + Constants.ZDEADTSERVERS + "/" + server.getLocation(); zoo.putPersistentData(path, "forced down".getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); } return null; }
@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"); }
@Override public void unassign(Collection<TabletLocationState> tablets, Map<TServerInstance,List<Path>> logsForDeadServers) throws DistributedStoreException { if (tablets.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); TabletLocationState tls = tablets.iterator().next(); if (tls.extent.compareTo(RootTable.EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); if (logsForDeadServers != null) { List<Path> logs = logsForDeadServers.get(tls.futureOrCurrent()); if (logs != null) { for (Path entry : logs) { LogEntry logEntry = new LogEntry(RootTable.EXTENT, System.currentTimeMillis(), tls.futureOrCurrent().getLocation().toString(), entry.toString()); byte[] value; try { value = logEntry.toBytes(); } catch (IOException ex) { throw new DistributedStoreException(ex); } store.put(RootTable.ZROOT_TABLET_WALOGS + "/" + logEntry.getUniqueID(), value); } } } store.remove(RootTable.ZROOT_TABLET_LOCATION); store.remove(RootTable.ZROOT_TABLET_FUTURE_LOCATION); log.debug("unassign root tablet location"); }
server = servers[random.nextInt(servers.length)].getLocation(); client = ThriftUtil.getTServerClient(server, master.getContext(), timeInMillis); List<String> attempt1 = Collections.singletonList(file);
/** * Fetch the tablets for the given table by asking the tablet server. Useful if your balance * strategy needs details at the tablet level to decide what tablets to move. * * @param tserver * The tablet server to ask. * @param tableId * The table id * @return a list of tablet statistics * @throws ThriftSecurityException * tablet server disapproves of your internal System password. * @throws TException * any other problem */ public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, Table.ID tableId) throws ThriftSecurityException, TException { log.debug("Scanning tablet server {} for table {}", tserver, tableId); Client client = ThriftUtil.getClient(new TabletClientService.Client.Factory(), tserver.getLocation(), context); try { return client.getTabletStats(Tracer.traceInfo(), context.rpcCreds(), tableId.canonicalID()); } catch (TTransportException e) { log.error("Unable to connect to {}: ", tserver, e); } finally { ThriftUtil.returnClient(client); } return null; }
if (find.hasNext()) { TServerInstance found = find.next(); if (found.getLocation().equals(tls.suspend.server)) { returnInstance = found;
public int port() { return getLocation().getPort(); }
SuspendingTServer suspender = new SuspendingTServer(tls.current.getLocation(), suspensionTimestamp); suspender.setSuspension(m);
public String host() { return getLocation().getHost(); }
@Override public List<String> getActiveTservers(TInfo tinfo, TCredentials credentials) throws TException { Set<TServerInstance> tserverInstances = master.onlineTabletServers(); List<String> servers = new ArrayList<>(); for (TServerInstance tserverInstance : tserverInstances) { servers.add(tserverInstance.getLocation().toString()); } return servers; }
@Override public void setFutureLocations(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(Constants.ROOT_TABLET_EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); String value = AddressUtil.toString(assignment.server.getLocation()) + "|" + assignment.server.getSession(); Iterator<TabletLocationState> currentIter = iterator(); TabletLocationState current = currentIter.next(); if (current.current != null) { throw new IllegalDSException("Trying to set the root tablet location: it is already set to " + current.current); } store.put(Constants.ZROOT_TABLET_FUTURE_LOCATION, value.getBytes(UTF_8)); }
@Override public Repo<Master> call(long tid, Master master) throws Exception { // suppress assignment of tablets to the server if (force) { String path = ZooUtil.getRoot(master.getInstance()) + Constants.ZTSERVERS + "/" + server.getLocation(); ZooLock.deleteLock(path); path = ZooUtil.getRoot(master.getInstance()) + Constants.ZDEADTSERVERS + "/" + server.getLocation(); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); zoo.putPersistentData(path, "forced down".getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); } return null; }