Search in sources :

Example 6 with QuorumServerInfo

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

the class RaftJournalTest method createNewJournalSystem.

/**
 * Creates list of raft journal systems in a clustered mode.
 */
private RaftJournalSystem createNewJournalSystem(RaftJournalSystem seed) throws Exception {
    List<InetSocketAddress> clusterAddresses = seed.getQuorumServerInfoList().stream().map(QuorumServerInfo::getServerAddress).map(address -> InetSocketAddress.createUnresolved(address.getHost(), address.getRpcPort())).collect(Collectors.toList());
    List<Integer> freePorts = getFreePorts(1);
    InetSocketAddress joinAddr = InetSocketAddress.createUnresolved("localhost", freePorts.get(0));
    clusterAddresses.add(joinAddr);
    return RaftJournalSystem.create(RaftJournalConfiguration.defaults(NetworkAddressUtils.ServiceType.MASTER_RAFT).setPath(mFolder.newFolder()).setClusterAddresses(clusterAddresses).setLocalAddress(joinAddr));
}
Also used : CatchupFuture(alluxio.master.journal.CatchupFuture) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) PropertyKey(alluxio.conf.PropertyKey) ArrayList(java.util.ArrayList) WaitForOptions(alluxio.util.WaitForOptions) ServerSocket(java.net.ServerSocket) After(org.junit.After) Map(java.util.Map) NoopMaster(alluxio.master.NoopMaster) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) Method(java.lang.reflect.Method) Before(org.junit.Before) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) ServerConfiguration(alluxio.conf.ServerConfiguration) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) File(alluxio.proto.journal.File) List(java.util.List) Rule(org.junit.Rule) ForkJoinPool(java.util.concurrent.ForkJoinPool) Journal(alluxio.proto.journal.Journal) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RaftServer(org.apache.ratis.server.RaftServer) Assert(org.junit.Assert) JournalContext(alluxio.master.journal.JournalContext) CommonUtils(alluxio.util.CommonUtils) TemporaryFolder(org.junit.rules.TemporaryFolder) InetSocketAddress(java.net.InetSocketAddress) QuorumServerInfo(alluxio.grpc.QuorumServerInfo)

Example 7 with QuorumServerInfo

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

the class QuorumCommandIntegrationTest method quorumRemove.

@Test
public void quorumRemove() throws Exception {
    mCluster = MultiProcessCluster.newBuilder(PortCoordination.QUORUM_SHELL_REMOVE).setClusterName("QuorumShellRemove").setNumMasters(5).setNumWorkers(0).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();
    String output;
    try (FileSystemAdminShell shell = new FileSystemAdminShell(ServerConfiguration.global())) {
        AlluxioURI testDir = new AlluxioURI("/testDir");
        mCluster.getFileSystemClient().createDirectory(testDir);
        // Verify cluster is reachable.
        Assert.assertTrue(mCluster.getFileSystemClient().exists(testDir));
        // Validate quorum state is updated as expected after shutting down 2 masters.
        mCluster.stopMaster(0);
        mCluster.stopMaster(1);
        // Verify cluster is reachable.
        Assert.assertTrue(mCluster.getFileSystemClient().exists(testDir));
        // Wait for up to 2 election timeouts until quorum notices changes.
        CommonUtils.waitFor("Quorum noticing change.", () -> {
            try {
                return mCluster.getJournalMasterClientForMaster().getQuorumInfo().getServerInfoList().stream().filter((info) -> info.getServerState() == QuorumServerState.UNAVAILABLE).collect(Collectors.toList()).size() == 2;
            } catch (Exception e) {
                return false;
            }
        }, WaitForOptions.defaults().setTimeoutMs(6 * (int) ServerConfiguration.getMs(PropertyKey.MASTER_EMBEDDED_JOURNAL_MAX_ELECTION_TIMEOUT)));
        // Remove unavailable masters using shell.
        for (QuorumServerInfo serverInfo : mCluster.getJournalMasterClientForMaster().getQuorumInfo().getServerInfoList()) {
            if (serverInfo.getServerState() == QuorumServerState.UNAVAILABLE) {
                mOutput.reset();
                String serverAddress = String.format("%s:%d", serverInfo.getServerAddress().getHost(), serverInfo.getServerAddress().getRpcPort());
                shell.run("journal", "quorum", "remove", "-domain", "MASTER", "-address", serverAddress);
                output = mOutput.toString().trim();
                Assert.assertEquals(String.format(QuorumRemoveCommand.OUTPUT_RESULT, serverAddress, JournalDomain.MASTER.name()), lastLine(output));
            }
        }
        // Verify quorum size is resized down to 3 after removing 2 masters.
        Assert.assertEquals(3, mCluster.getJournalMasterClientForMaster().getQuorumInfo().getServerInfoList().size());
        mCluster.stopMaster(2);
        // Verify cluster is reachable.
        Assert.assertTrue(mCluster.getFileSystemClient().exists(testDir));
    }
    mCluster.notifySuccess();
}
Also used : Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MultiProcessCluster(alluxio.multi.process.MultiProcessCluster) QuorumCommand(alluxio.cli.fsadmin.journal.QuorumCommand) MasterNetAddress(alluxio.multi.process.MasterNetAddress) QuorumInfoCommand(alluxio.cli.fsadmin.journal.QuorumInfoCommand) PropertyKey(alluxio.conf.PropertyKey) FileSystemAdminShell(alluxio.cli.fsadmin.FileSystemAdminShell) WaitForOptions(alluxio.util.WaitForOptions) JournalType(alluxio.master.journal.JournalType) ConfigurationRule(alluxio.ConfigurationRule) QuorumElectCommand(alluxio.cli.fsadmin.journal.QuorumElectCommand) QuorumServerState(alluxio.grpc.QuorumServerState) AlluxioURI(alluxio.AlluxioURI) After(org.junit.After) PortCoordination(alluxio.multi.process.PortCoordination) SystemOutRule(alluxio.SystemOutRule) JournalDomain(alluxio.grpc.JournalDomain) ExpectedException(org.junit.rules.ExpectedException) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) ServerConfiguration(alluxio.conf.ServerConfiguration) ExceptionMessage(alluxio.exception.ExceptionMessage) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Rule(org.junit.Rule) QuorumRemoveCommand(alluxio.cli.fsadmin.journal.QuorumRemoveCommand) SystemErrRule(alluxio.SystemErrRule) Assert(org.junit.Assert) CommonUtils(alluxio.util.CommonUtils) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) FileSystemAdminShell(alluxio.cli.fsadmin.FileSystemAdminShell) ExpectedException(org.junit.rules.ExpectedException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

QuorumServerInfo (alluxio.grpc.QuorumServerInfo)7 NetAddress (alluxio.grpc.NetAddress)5 Collectors (java.util.stream.Collectors)5 PropertyKey (alluxio.conf.PropertyKey)4 ServerConfiguration (alluxio.conf.ServerConfiguration)4 CommonUtils (alluxio.util.CommonUtils)4 WaitForOptions (alluxio.util.WaitForOptions)4 IOException (java.io.IOException)4 List (java.util.List)4 Test (org.junit.Test)4 ExceptionMessage (alluxio.exception.ExceptionMessage)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 After (org.junit.After)3 Assert (org.junit.Assert)3