Search in sources :

Example 41 with HostAndPort

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();
        }
    });
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Instant(java.time.Instant)

Example 42 with HostAndPort

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);
    });
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Instant(java.time.Instant)

Example 43 with HostAndPort

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);
}
Also used : MemberHeartbeatData(com.torodb.mongodb.commands.pojos.MemberHeartbeatData) HostAndPort(com.google.common.net.HostAndPort) NodeNotFoundException(com.eightkdata.mongowp.exceptions.NodeNotFoundException) InvalidOptionsException(com.eightkdata.mongowp.exceptions.InvalidOptionsException) ShutdownInProgressException(com.eightkdata.mongowp.exceptions.ShutdownInProgressException) HostUnreachableException(com.eightkdata.mongowp.exceptions.HostUnreachableException) UnauthorizedException(com.eightkdata.mongowp.exceptions.UnauthorizedException) ReplSetSyncFromReply(com.torodb.mongodb.commands.signatures.repl.ReplSetSyncFromCommand.ReplSetSyncFromReply) MemberConfig(com.torodb.mongodb.commands.pojos.MemberConfig)

Example 44 with HostAndPort

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;
}
Also used : ArrayList(java.util.ArrayList) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(org.apache.hadoop.fs.BlockLocation) HostAndPort(com.google.common.net.HostAndPort) AlluxioURI(alluxio.AlluxioURI)

Example 45 with HostAndPort

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);
    }
}
Also used : TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) InetSocketAddress(java.net.InetSocketAddress) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) MRClientProtocol(org.apache.hadoop.mapreduce.v2.api.MRClientProtocol) HostAndPort(com.google.common.net.HostAndPort) GetDelegationTokenRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest) ResourceMgrDelegate(org.apache.hadoop.mapred.ResourceMgrDelegate) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) GetDelegationTokenRequestPBImpl(org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetDelegationTokenRequestPBImpl)

Aggregations

HostAndPort (com.google.common.net.HostAndPort)45 IOException (java.io.IOException)8 Test (org.junit.Test)7 InetSocketAddress (java.net.InetSocketAddress)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Request (com.metamx.http.client.Request)3 SequenceInputStreamResponseHandler (com.metamx.http.client.response.SequenceInputStreamResponseHandler)3 SystemException (com.torodb.core.exceptions.SystemException)3 JCommander (com.beust.jcommander.JCommander)2 Console (com.beust.jcommander.internal.Console)2 OpTime (com.eightkdata.mongowp.OpTime)2 UnreachableMongoServerException (com.eightkdata.mongowp.client.core.UnreachableMongoServerException)2 MongoException (com.eightkdata.mongowp.exceptions.MongoException)2 Charsets (com.google.common.base.Charsets)2 Throwables (com.google.common.base.Throwables)2 Service (com.google.common.util.concurrent.Service)2 CreationException (com.google.inject.CreationException)2 NoSyncSourceFoundException (com.torodb.mongodb.repl.exceptions.NoSyncSourceFoundException)2 BackendPasswordConfig (com.torodb.packaging.config.model.backend.BackendPasswordConfig)2