use of alluxio.grpc.QuorumServerInfo in project alluxio by Alluxio.
the class QuorumInfoCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
JournalMasterClient jmClient = mMasterJournalMasterClient;
String domainVal = cl.getOptionValue(DOMAIN_OPTION_NAME);
try {
JournalDomain domain = JournalDomain.valueOf(domainVal);
if (domain == JournalDomain.JOB_MASTER) {
jmClient = mJobMasterJournalMasterClient;
}
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(ExceptionMessage.INVALID_OPTION_VALUE.getMessage(DOMAIN_OPTION_NAME, Arrays.toString(JournalDomain.values())));
}
GetQuorumInfoPResponse quorumInfo = jmClient.getQuorumInfo();
Optional<QuorumServerInfo> leadingMasterInfoOpt = quorumInfo.getServerInfoList().stream().filter(QuorumServerInfo::getIsLeader).findFirst();
String leadingMasterAddr = leadingMasterInfoOpt.isPresent() ? netAddressToString(leadingMasterInfoOpt.get().getServerAddress()) : "UNKNOWN";
List<String[]> table = quorumInfo.getServerInfoList().stream().map(info -> new String[] { info.getServerState().toString(), Integer.toString(info.getPriority()), netAddressToString(info.getServerAddress()) }).collect(Collectors.toList());
table.add(0, new String[] { "STATE", "PRIORITY", "SERVER ADDRESS" });
mPrintStream.println(String.format(OUTPUT_HEADER_DOMAIN, quorumInfo.getDomain()));
mPrintStream.println(String.format(OUTPUT_HEADER_QUORUM_SIZE, quorumInfo.getServerInfoList().size()));
mPrintStream.println(String.format(OUTPUT_HEADER_LEADING_MASTER, leadingMasterAddr));
mPrintStream.println();
for (String[] output : table) {
mPrintStream.printf(OUTPUT_SERVER_INFO, output);
}
return 0;
}
use of alluxio.grpc.QuorumServerInfo in project alluxio by Alluxio.
the class QuorumElectCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
JournalMasterClient jmClient = mMasterJournalMasterClient;
String serverAddress = cl.getOptionValue(ADDRESS_OPTION_NAME);
NetAddress address = QuorumCommand.stringToAddress(serverAddress);
boolean success = false;
try {
mPrintStream.println(String.format(TRANSFER_INIT, serverAddress));
String transferId = jmClient.transferLeadership(address);
AtomicReference<String> errorMessage = new AtomicReference<>("");
// wait for confirmation of leadership transfer
// in milliseconds
final int TIMEOUT_3MIN = 3 * 60 * 1000;
CommonUtils.waitFor("election to finalize.", () -> {
try {
errorMessage.set(jmClient.getTransferLeaderMessage(transferId).getTransMsg().getMsg());
if (!errorMessage.get().isEmpty()) {
// if an error is reported, end the retry immediately
return true;
}
GetQuorumInfoPResponse quorumInfo = jmClient.getQuorumInfo();
Optional<QuorumServerInfo> leadingMasterInfoOpt = quorumInfo.getServerInfoList().stream().filter(QuorumServerInfo::getIsLeader).findFirst();
NetAddress leaderAddress = leadingMasterInfoOpt.isPresent() ? leadingMasterInfoOpt.get().getServerAddress() : null;
return address.equals(leaderAddress);
} catch (IOException e) {
return false;
}
}, WaitForOptions.defaults().setTimeoutMs(TIMEOUT_3MIN));
if (!errorMessage.get().isEmpty()) {
throw new Exception(errorMessage.get());
}
mPrintStream.println(String.format(TRANSFER_SUCCESS, serverAddress));
success = true;
} catch (Exception e) {
mPrintStream.println(String.format(TRANSFER_FAILED, serverAddress, e.getMessage()));
}
// reset priorities regardless of transfer success
try {
mPrintStream.println(String.format(RESET_INIT, success ? "successful" : "failed"));
jmClient.resetPriorities();
mPrintStream.println(RESET_SUCCESS);
} catch (IOException e) {
mPrintStream.println(String.format(RESET_FAILED, e));
success = false;
}
return success ? 0 : -1;
}
use of alluxio.grpc.QuorumServerInfo in project alluxio by Alluxio.
the class EmbeddedJournalIntegrationTestResizing method resizeCluster.
@Test
public void resizeCluster() throws Exception {
final int NUM_MASTERS = 5;
final int NUM_WORKERS = 0;
mCluster = MultiProcessCluster.newBuilder(PortCoordination.EMBEDDED_JOURNAL_RESIZE).setClusterName("EmbeddedJournalResizing_resizeCluster").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();
assertEquals(5, mCluster.getJournalMasterClientForMaster().getQuorumInfo().getServerInfoList().size());
AlluxioURI testDir = new AlluxioURI("/" + CommonUtils.randomAlphaNumString(10));
FileSystem fs = mCluster.getFileSystemClient();
fs.createDirectory(testDir);
assertTrue(fs.exists(testDir));
// Stop 2 masters. Now cluster can't tolerate any loss.
mCluster.stopMaster(0);
mCluster.stopMaster(1);
// Verify cluster is still serving requests.
assertTrue(fs.exists(testDir));
waitForQuorumPropertySize(info -> info.getServerState() == QuorumServerState.UNAVAILABLE, 2);
// Get and verify list of unavailable masters.
List<NetAddress> unavailableMasters = new LinkedList<>();
for (QuorumServerInfo serverState : mCluster.getJournalMasterClientForMaster().getQuorumInfo().getServerInfoList()) {
if (serverState.getServerState().equals(QuorumServerState.UNAVAILABLE)) {
unavailableMasters.add(serverState.getServerAddress());
}
}
assertEquals(2, unavailableMasters.size());
// Remove unavailable masters from quorum.
for (NetAddress unavailableMasterAddress : unavailableMasters) {
mCluster.getJournalMasterClientForMaster().removeQuorumServer(unavailableMasterAddress);
}
// Verify quorum is down to 3 masters.
assertEquals(3, mCluster.getJournalMasterClientForMaster().getQuorumInfo().getServerInfoList().size());
// Validate that cluster can tolerate one more master failure after resizing.
mCluster.stopMaster(2);
assertTrue(fs.exists(testDir));
mCluster.notifySuccess();
}
use of alluxio.grpc.QuorumServerInfo 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;
}
use of alluxio.grpc.QuorumServerInfo in project alluxio by Alluxio.
the class SnapshotReplicationManagerTest method before.
private void before(int numFollowers) throws Exception {
mLeader = Mockito.mock(RaftJournalSystem.class);
Mockito.when(mLeader.isLeader()).thenReturn(true);
Mockito.when(mLeader.getLocalPeerId()).thenReturn(RaftPeerId.getRaftPeerId("leader"));
mLeaderStore = getSimpleStateMachineStorage();
mLeaderSnapshotManager = Mockito.spy(new SnapshotReplicationManager(mLeader, mLeaderStore));
String serverName = InProcessServerBuilder.generateName();
mServer = InProcessServerBuilder.forName(serverName).directExecutor().addService(new RaftJournalServiceHandler(mLeaderSnapshotManager)).build();
mServer.start();
ManagedChannel channel = InProcessChannelBuilder.forName(serverName).directExecutor().build();
RaftJournalServiceGrpc.RaftJournalServiceStub stub = RaftJournalServiceGrpc.newStub(channel);
// mock RaftJournalServiceClient
mClient = Mockito.mock(RaftJournalServiceClient.class);
Mockito.doNothing().when(mClient).close();
// download rpc mock
Mockito.when(mClient.downloadSnapshot(any())).thenAnswer((args) -> {
StreamObserver responseObserver = args.getArgument(0, StreamObserver.class);
return stub.downloadSnapshot(responseObserver);
});
// upload rpc mock
Mockito.when(mClient.uploadSnapshot(any())).thenAnswer((args) -> {
StreamObserver responseObserver = args.getArgument(0, StreamObserver.class);
return stub.uploadSnapshot(responseObserver);
});
Mockito.doReturn(mClient).when(mLeaderSnapshotManager).getJournalServiceClient();
for (int i = 0; i < numFollowers; i++) {
Follower follower = new Follower(mClient);
mFollowers.put(follower.getRaftPeerId(), follower);
}
List<QuorumServerInfo> quorumServerInfos = mFollowers.values().stream().map(follower -> {
return QuorumServerInfo.newBuilder().setServerAddress(NetAddress.newBuilder().setHost(follower.mHost).setRpcPort(follower.mRpcPort)).build();
}).collect(Collectors.toList());
Mockito.when(mLeader.getQuorumServerInfoList()).thenReturn(quorumServerInfos);
Mockito.when(mLeader.sendMessageAsync(any(), any())).thenAnswer((args) -> {
RaftPeerId peerId = args.getArgument(0, RaftPeerId.class);
Message message = args.getArgument(1, Message.class);
JournalQueryRequest queryRequest = JournalQueryRequest.parseFrom(message.getContent().asReadOnlyByteBuffer());
Message response = mFollowers.get(peerId).mSnapshotManager.handleRequest(queryRequest);
RaftClientReply reply = Mockito.mock(RaftClientReply.class);
Mockito.when(reply.getMessage()).thenReturn(response);
return CompletableFuture.completedFuture(reply);
});
}
Aggregations