Search in sources :

Example 1 with NetAddress

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

the class MetaMasterMasterServiceHandler method getMasterId.

@Override
public void getMasterId(GetMasterIdPRequest request, StreamObserver<GetMasterIdPResponse> responseObserver) {
    NetAddress masterAddress = request.getMasterAddress();
    RpcUtils.call(LOG, (RpcUtils.RpcCallableThrowsIOException<GetMasterIdPResponse>) () -> {
        return GetMasterIdPResponse.newBuilder().setMasterId(mMetaMaster.getMasterId(Address.fromProto(masterAddress))).build();
    }, "getMasterId", "request=%s", responseObserver, request);
}
Also used : RpcUtils(alluxio.RpcUtils) GetMasterIdPResponse(alluxio.grpc.GetMasterIdPResponse) NetAddress(alluxio.grpc.NetAddress)

Example 2 with NetAddress

use of alluxio.grpc.NetAddress 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;
}
Also used : GetQuorumInfoPResponse(alluxio.grpc.GetQuorumInfoPResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) IOException(java.io.IOException) IOException(java.io.IOException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) JournalMasterClient(alluxio.client.journal.JournalMasterClient) NetAddress(alluxio.grpc.NetAddress)

Example 3 with NetAddress

use of alluxio.grpc.NetAddress 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();
}
Also used : FileSystem(alluxio.client.file.FileSystem) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) LinkedList(java.util.LinkedList) AlluxioURI(alluxio.AlluxioURI) NetAddress(alluxio.grpc.NetAddress) MasterNetAddress(alluxio.multi.process.MasterNetAddress) Test(org.junit.Test)

Example 4 with NetAddress

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

the class EmbeddedJournalIntegrationTestTransferLeadership method transferWhenAlreadyTransferring.

@Test
public void transferWhenAlreadyTransferring() throws Exception {
    mCluster = MultiProcessCluster.newBuilder(PortCoordination.EMBEDDED_JOURNAL_ALREADY_TRANSFERRING).setClusterName("EmbeddedJournalTransferLeadership_transferWhenAlreadyTransferring").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();
    int newLeaderIdx = (mCluster.getPrimaryMasterIndex(MASTER_INDEX_WAIT_TIME) + 1) % NUM_MASTERS;
    // `getPrimaryMasterIndex` uses the same `mMasterAddresses` variable as getMasterAddresses
    // we can therefore access to the new leader's address this way
    MasterNetAddress newLeaderAddr = mCluster.getMasterAddresses().get(newLeaderIdx);
    NetAddress netAddress = masterEBJAddr2NetAddr(newLeaderAddr);
    mCluster.getJournalMasterClientForMaster().transferLeadership(netAddress);
    // this second call should throw an exception
    String transferId = mCluster.getJournalMasterClientForMaster().transferLeadership(netAddress);
    String exceptionMessage = mCluster.getJournalMasterClientForMaster().getTransferLeaderMessage(transferId).getTransMsg().getMsg();
    Assert.assertFalse(exceptionMessage.isEmpty());
    mCluster.notifySuccess();
}
Also used : MasterNetAddress(alluxio.multi.process.MasterNetAddress) NetAddress(alluxio.grpc.NetAddress) MasterNetAddress(alluxio.multi.process.MasterNetAddress) Test(org.junit.Test)

Example 5 with NetAddress

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

the class EmbeddedJournalIntegrationTestTransferLeadership method transferLeadershipOutsideCluster.

@Test
public void transferLeadershipOutsideCluster() throws Exception {
    mCluster = MultiProcessCluster.newBuilder(PortCoordination.EMBEDDED_JOURNAL_OUTSIDE_CLUSTER).setClusterName("EmbeddedJournalTransferLeadership_transferLeadership").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();
    NetAddress netAddress = NetAddress.newBuilder().setHost("hostname").setRpcPort(0).build();
    String transferId = mCluster.getJournalMasterClientForMaster().transferLeadership(netAddress);
    String exceptionMessage = mCluster.getJournalMasterClientForMaster().getTransferLeaderMessage(transferId).getTransMsg().getMsg();
    Assert.assertTrue(exceptionMessage.startsWith(String.format("<%s:%d> is not part of the quorum", netAddress.getHost(), netAddress.getRpcPort())));
    for (MasterNetAddress address : mCluster.getMasterAddresses()) {
        String host = address.getHostname();
        int port = address.getEmbeddedJournalPort();
        Assert.assertTrue(exceptionMessage.contains(String.format("%s:%d", host, port)));
    }
    mCluster.notifySuccess();
}
Also used : MasterNetAddress(alluxio.multi.process.MasterNetAddress) NetAddress(alluxio.grpc.NetAddress) MasterNetAddress(alluxio.multi.process.MasterNetAddress) 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