Search in sources :

Example 6 with NetAddress

use of alluxio.grpc.NetAddress in project alluxio by Alluxio.

the class EmbeddedJournalIntegrationTestTransferLeadership method transferAndWait.

private String transferAndWait(MasterNetAddress newLeaderAddr) throws Exception {
    NetAddress netAddress = NetAddress.newBuilder().setHost(newLeaderAddr.getHostname()).setRpcPort(newLeaderAddr.getEmbeddedJournalPort()).build();
    String transferId = mCluster.getJournalMasterClientForMaster().transferLeadership(netAddress);
    waitForQuorumPropertySize(info -> info.getIsLeader() && info.getServerAddress().equals(netAddress), 1);
    return transferId;
}
Also used : NetAddress(alluxio.grpc.NetAddress) MasterNetAddress(alluxio.multi.process.MasterNetAddress)

Example 7 with NetAddress

use of alluxio.grpc.NetAddress in project alluxio by Alluxio.

the class RaftJournalSystem method getQuorumServerInfoList.

/**
 * Used to get information of internal RAFT quorum.
 *
 * @return list of information for participating servers in RAFT quorum
 */
public synchronized List<QuorumServerInfo> getQuorumServerInfoList() throws IOException {
    List<QuorumServerInfo> quorumMemberStateList = new LinkedList<>();
    GroupInfoReply groupInfo = getGroupInfo();
    if (groupInfo == null) {
        throw new UnavailableException("Cannot get raft group info");
    }
    if (groupInfo.getException() != null) {
        throw groupInfo.getException();
    }
    RaftProtos.RoleInfoProto roleInfo = groupInfo.getRoleInfoProto();
    if (roleInfo == null) {
        throw new UnavailableException("Cannot get server role info");
    }
    RaftProtos.LeaderInfoProto leaderInfo = roleInfo.getLeaderInfo();
    if (leaderInfo == null) {
        throw new UnavailableException("Cannot get server leader info");
    }
    for (RaftProtos.ServerRpcProto member : leaderInfo.getFollowerInfoList()) {
        HostAndPort hp = HostAndPort.fromString(member.getId().getAddress());
        NetAddress memberAddress = NetAddress.newBuilder().setHost(hp.getHost()).setRpcPort(hp.getPort()).build();
        quorumMemberStateList.add(QuorumServerInfo.newBuilder().setIsLeader(false).setPriority(member.getId().getPriority()).setServerAddress(memberAddress).setServerState(member.getLastRpcElapsedTimeMs() > mConf.getMaxElectionTimeoutMs() ? QuorumServerState.UNAVAILABLE : QuorumServerState.AVAILABLE).build());
    }
    InetSocketAddress localAddress = mConf.getLocalAddress();
    NetAddress self = NetAddress.newBuilder().setHost(localAddress.getHostString()).setRpcPort(localAddress.getPort()).build();
    quorumMemberStateList.add(QuorumServerInfo.newBuilder().setIsLeader(true).setPriority(roleInfo.getSelf().getPriority()).setServerAddress(self).setServerState(QuorumServerState.AVAILABLE).build());
    quorumMemberStateList.sort(Comparator.comparing(info -> info.getServerAddress().toString()));
    return quorumMemberStateList;
}
Also used : Arrays(java.util.Arrays) GroupInfoReply(org.apache.ratis.protocol.GroupInfoReply) RaftGroup(org.apache.ratis.protocol.RaftGroup) LeaderNotReadyException(org.apache.ratis.protocol.exceptions.LeaderNotReadyException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) PropertyKey(alluxio.conf.PropertyKey) GrpcService(alluxio.grpc.GrpcService) LogUtils(alluxio.util.LogUtils) NetUtils(org.apache.ratis.util.NetUtils) JournalQueryRequest(alluxio.grpc.JournalQueryRequest) MetricKey(alluxio.metrics.MetricKey) Map(java.util.Map) RaftConfigKeys(org.apache.ratis.RaftConfigKeys) CancelledException(alluxio.exception.status.CancelledException) UnsafeByteOperations(org.apache.ratis.thirdparty.com.google.protobuf.UnsafeByteOperations) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) ServerConfiguration(alluxio.conf.ServerConfiguration) RaftPeer(org.apache.ratis.protocol.RaftPeer) RetryPolicy(org.apache.ratis.retry.RetryPolicy) Master(alluxio.master.Master) Collection(java.util.Collection) AbstractJournalSystem(alluxio.master.journal.AbstractJournalSystem) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) SupportedRpcType(org.apache.ratis.rpc.SupportedRpcType) CompletionException(java.util.concurrent.CompletionException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) List(java.util.List) ClientId(org.apache.ratis.protocol.ClientId) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftProperties(org.apache.ratis.conf.RaftProperties) ServiceType(alluxio.grpc.ServiceType) ExponentialBackoffRetry(org.apache.ratis.retry.ExponentialBackoffRetry) Optional(java.util.Optional) PrimarySelector(alluxio.master.PrimarySelector) RatisDropwizardExports(alluxio.metrics.sink.RatisDropwizardExports) AccessDeniedException(java.nio.file.AccessDeniedException) RaftClientConfigKeys(org.apache.ratis.client.RaftClientConfigKeys) UnavailableException(alluxio.exception.status.UnavailableException) TimeDuration(org.apache.ratis.util.TimeDuration) AsyncJournalWriter(alluxio.master.journal.AsyncJournalWriter) GroupInfoRequest(org.apache.ratis.protocol.GroupInfoRequest) CatchupFuture(alluxio.master.journal.CatchupFuture) SetConfigurationRequest(org.apache.ratis.protocol.SetConfigurationRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) WaitForOptions(alluxio.util.WaitForOptions) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) AddQuorumServerRequest(alluxio.grpc.AddQuorumServerRequest) Message(org.apache.ratis.protocol.Message) OptionalLong(java.util.OptionalLong) Constants(alluxio.Constants) QuorumServerState(alluxio.grpc.QuorumServerState) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MetricsSystem(alluxio.metrics.MetricsSystem) LinkedList(java.util.LinkedList) SizeInBytes(org.apache.ratis.util.SizeInBytes) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) NetAddress(alluxio.grpc.NetAddress) Iterator(java.util.Iterator) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftServerConfigKeys(org.apache.ratis.server.RaftServerConfigKeys) ExceptionMessage(alluxio.exception.ExceptionMessage) RaftProtos(org.apache.ratis.proto.RaftProtos) FileUtils(org.apache.commons.io.FileUtils) GrpcConfigKeys(org.apache.ratis.grpc.GrpcConfigKeys) RaftClientRequest(org.apache.ratis.protocol.RaftClientRequest) IOException(java.io.IOException) TransferLeaderMessage(alluxio.grpc.TransferLeaderMessage) HostAndPort(com.google.common.net.HostAndPort) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Parameters(org.apache.ratis.conf.Parameters) AtomicLong(java.util.concurrent.atomic.AtomicLong) LifeCycle(org.apache.ratis.util.LifeCycle) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RaftServer(org.apache.ratis.server.RaftServer) RaftClient(org.apache.ratis.client.RaftClient) Comparator(java.util.Comparator) Journal(alluxio.master.journal.Journal) Collections(java.util.Collections) CommonUtils(alluxio.util.CommonUtils) InetSocketAddress(java.net.InetSocketAddress) UnavailableException(alluxio.exception.status.UnavailableException) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) LinkedList(java.util.LinkedList) NetAddress(alluxio.grpc.NetAddress) HostAndPort(com.google.common.net.HostAndPort) RaftProtos(org.apache.ratis.proto.RaftProtos) GroupInfoReply(org.apache.ratis.protocol.GroupInfoReply)

Example 8 with NetAddress

use of alluxio.grpc.NetAddress in project alluxio by Alluxio.

the class EmbeddedJournalIntegrationTestResizing method replaceAll.

@Ignore
@Test
public void replaceAll() throws Exception {
    final int NUM_MASTERS = 5;
    final int NUM_WORKERS = 0;
    mCluster = MultiProcessCluster.newBuilder(PortCoordination.EMBEDDED_JOURNAL_REPLACE_ALL).setClusterName("EmbeddedJournalResizing_replaceAll").setNumMasters(NUM_MASTERS).setNumWorkers(NUM_WORKERS).addProperty(PropertyKey.MASTER_JOURNAL_TYPE, JournalType.EMBEDDED.toString()).addProperty(PropertyKey.MASTER_JOURNAL_FLUSH_TIMEOUT_MS, "5min").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MIN_ELECTION_TIMEOUT, "750ms").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MAX_ELECTION_TIMEOUT, "1500ms").build();
    mCluster.start();
    AlluxioURI testDir = new AlluxioURI("/" + CommonUtils.randomAlphaNumString(10));
    FileSystem fs = mCluster.getFileSystemClient();
    fs.createDirectory(testDir);
    assertTrue(fs.exists(testDir));
    List<MasterNetAddress> originalMasters = new ArrayList<>(mCluster.getMasterAddresses());
    for (MasterNetAddress masterNetAddress : originalMasters) {
        // remove a master from the Alluxio cluster (could be the leader)
        int masterIdx = mCluster.getMasterAddresses().indexOf(masterNetAddress);
        mCluster.stopAndRemoveMaster(masterIdx);
        waitForQuorumPropertySize(info -> info.getServerState() == QuorumServerState.UNAVAILABLE, 1);
        // remove said master from the Ratis quorum
        NetAddress toRemove = masterEBJAddr2NetAddr(masterNetAddress);
        mCluster.getJournalMasterClientForMaster().removeQuorumServer(toRemove);
        waitForQuorumPropertySize(info -> true, NUM_MASTERS - 1);
        waitForQuorumPropertySize(info -> info.getServerAddress() == toRemove, 0);
        // start a new master to replace the lost master
        mCluster.startNewMasters(1, false);
        waitForQuorumPropertySize(info -> true, NUM_MASTERS);
        // verify that the cluster is still operational
        fs = mCluster.getFileSystemClient();
        assertTrue(fs.exists(testDir));
    }
    Set<NetAddress> og = originalMasters.stream().map(this::masterEBJAddr2NetAddr).collect(Collectors.toSet());
    Set<NetAddress> curr = mCluster.getJournalMasterClientForMaster().getQuorumInfo().getServerInfoList().stream().map(QuorumServerInfo::getServerAddress).collect(Collectors.toSet());
    Set<NetAddress> intersection = new HashSet<>(og);
    intersection.retainAll(curr);
    // assert that none of the current masters are part of the original
    assertTrue(intersection.isEmpty());
    // assert the quorum remained the same size as the start
    assertEquals(NUM_MASTERS, curr.size());
    mCluster.notifySuccess();
}
Also used : MasterNetAddress(alluxio.multi.process.MasterNetAddress) FileSystem(alluxio.client.file.FileSystem) ArrayList(java.util.ArrayList) AlluxioURI(alluxio.AlluxioURI) NetAddress(alluxio.grpc.NetAddress) MasterNetAddress(alluxio.multi.process.MasterNetAddress) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

NetAddress (alluxio.grpc.NetAddress)8 MasterNetAddress (alluxio.multi.process.MasterNetAddress)5 QuorumServerInfo (alluxio.grpc.QuorumServerInfo)3 Test (org.junit.Test)3 AlluxioURI (alluxio.AlluxioURI)2 FileSystem (alluxio.client.file.FileSystem)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Constants (alluxio.Constants)1 RpcUtils (alluxio.RpcUtils)1 JournalMasterClient (alluxio.client.journal.JournalMasterClient)1 PropertyKey (alluxio.conf.PropertyKey)1 ServerConfiguration (alluxio.conf.ServerConfiguration)1 ExceptionMessage (alluxio.exception.ExceptionMessage)1 CancelledException (alluxio.exception.status.CancelledException)1 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 AddQuorumServerRequest (alluxio.grpc.AddQuorumServerRequest)1 GetMasterIdPResponse (alluxio.grpc.GetMasterIdPResponse)1 GetQuorumInfoPResponse (alluxio.grpc.GetQuorumInfoPResponse)1