use of com.google.common.net.HostAndPort in project torodb by torodb.
the class TopologyService method chooseNewSyncSource.
public CompletableFuture<Optional<HostAndPort>> chooseNewSyncSource(Optional<OpTime> lastFetchedOpTime) {
return executor.onAnyVersion().mapAsync(coord -> {
Instant now = clock.instant();
HostAndPort currentSyncSource = coord.getSyncSourceAddress().orElse(null);
boolean shouldChange = currentSyncSource == null || coord.shouldChangeSyncSource(currentSyncSource, now);
if (shouldChange) {
return coord.chooseNewSyncSource(clock.instant(), lastFetchedOpTime);
} else {
return coord.getSyncSourceAddress();
}
});
}
use of com.google.common.net.HostAndPort in project torodb by torodb.
the class TopologyService method shouldChangeSyncSource.
CompletableFuture<Boolean> shouldChangeSyncSource() {
return executor.onAnyVersion().mapAsync(coord -> {
Instant now = clock.instant();
HostAndPort currentSyncSource = coord.getSyncSourceAddress().orElse(null);
return currentSyncSource == null || coord.shouldChangeSyncSource(currentSyncSource, now);
});
}
use of com.google.common.net.HostAndPort in project torodb by torodb.
the class TopologyCoordinator method executeReplSetSyncFrom.
ReplSetSyncFromReply executeReplSetSyncFrom(ErrorCode status, HostAndPort target, OpTime lastOpApplied) throws MongoException {
if (status == ErrorCode.CALLBACK_CANCELED) {
throw new ShutdownInProgressException("replication system is shutting down");
}
final HostAndPort syncFromRequested = target;
MemberConfig targetConfig = null;
int targetIndex;
for (targetIndex = 0; targetIndex < _rsConfig.getMembers().size(); targetIndex++) {
MemberConfig it = _rsConfig.getMembers().get(targetIndex);
if (it.getHostAndPort().equals(target)) {
targetConfig = it;
break;
}
}
if (targetConfig == null) {
throw new NodeNotFoundException("Could not find member \"" + target + "\" in replica set");
}
if (targetConfig.isArbiter()) {
throw new InvalidOptionsException("Cannot sync from \"" + target + "\" because it is an arbiter");
}
String warning = null;
MemberHeartbeatData hbdata = _hbdata.get(targetIndex);
if (hbdata.isAuthIssue()) {
throw new UnauthorizedException("not authorized to communicate with " + target);
}
if (hbdata.getHealth() == Health.UNREACHABLE) {
throw new HostUnreachableException("I cannot reach the requested member: " + target);
}
assert hbdata.getOpTime() != null;
if (hbdata.getOpTime().getSecs() + 10 < lastOpApplied.getSecs()) {
LOGGER.warn("attempting to sync from {}, but its latest opTime is {} and ours is {} " + "so this may not work", target, hbdata.getOpTime().getSecs(), lastOpApplied.getSecs());
warning = "requested member \"" + target + "\" is more than 10 seconds behind us";
}
HostAndPort prevSyncSource = getSyncSourceAddress().orElse(null);
setForceSyncSourceIndex(targetIndex);
return new ReplSetSyncFromReply(prevSyncSource, syncFromRequested, warning);
}
use of com.google.common.net.HostAndPort in project alluxio by Alluxio.
the class AbstractFileSystem method getFileBlockLocations.
@Override
public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException {
if (file == null) {
return null;
}
if (mStatistics != null) {
mStatistics.incrementReadOps(1);
}
AlluxioURI path = new AlluxioURI(HadoopUtils.getPathWithoutScheme(file.getPath()));
List<FileBlockInfo> blocks = getFileBlocks(path);
List<BlockLocation> blockLocations = new ArrayList<>();
for (FileBlockInfo fileBlockInfo : blocks) {
long offset = fileBlockInfo.getOffset();
long end = offset + fileBlockInfo.getBlockInfo().getLength();
// Check if there is any overlapping between [start, start+len] and [offset, end]
if (end >= start && offset <= start + len) {
ArrayList<String> names = new ArrayList<>();
ArrayList<String> hosts = new ArrayList<>();
// add the existing in-memory block locations
for (alluxio.wire.BlockLocation location : fileBlockInfo.getBlockInfo().getLocations()) {
HostAndPort address = HostAndPort.fromParts(location.getWorkerAddress().getHost(), location.getWorkerAddress().getDataPort());
names.add(address.toString());
hosts.add(address.getHostText());
}
// add under file system locations
for (String location : fileBlockInfo.getUfsLocations()) {
names.add(location);
hosts.add(HostAndPort.fromString(location).getHostText());
}
blockLocations.add(new BlockLocation(CommonUtils.toStringArray(names), CommonUtils.toStringArray(hosts), offset, fileBlockInfo.getBlockInfo().getLength()));
}
}
BlockLocation[] ret = new BlockLocation[blockLocations.size()];
blockLocations.toArray(ret);
return ret;
}
use of com.google.common.net.HostAndPort in project cdap by caskdata.
the class JobHistoryServerTokenUtils method obtainToken.
/**
* Gets a JHS delegation token and stores it in the given Credentials.
*
* @return the same Credentials instance as the one given in parameter.
*/
public static Credentials obtainToken(Configuration configuration, Credentials credentials) {
if (!UserGroupInformation.isSecurityEnabled()) {
return credentials;
}
String historyServerAddress = configuration.get("mapreduce.jobhistory.address");
HostAndPort hostAndPort = HostAndPort.fromString(historyServerAddress);
try {
ResourceMgrDelegate resourceMgrDelegate = new ResourceMgrDelegate(new YarnConfiguration(configuration));
MRClientCache clientCache = new MRClientCache(configuration, resourceMgrDelegate);
MRClientProtocol hsProxy = clientCache.getInitializedHSProxy();
GetDelegationTokenRequest request = new GetDelegationTokenRequestPBImpl();
request.setRenewer(YarnUtils.getYarnTokenRenewer(configuration));
InetSocketAddress address = new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
Token<TokenIdentifier> token = ConverterUtils.convertFromYarn(hsProxy.getDelegationToken(request).getDelegationToken(), address);
credentials.addToken(new Text(token.getService()), token);
LOG.debug("Adding JobHistoryServer delegation token {}.", token);
return credentials;
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations