Search in sources :

Example 1 with RaftServerProtocol

use of io.atomix.protocols.raft.protocol.RaftServerProtocol in project atomix by atomix.

the class RaftPerformanceTest method createServer.

/**
 * Creates a Raft server.
 */
private RaftServer createServer(Node node, List<Node> members) throws UnknownHostException {
    RaftServerProtocol protocol;
    ManagedMessagingService messagingService;
    if (USE_NETTY) {
        messagingService = (ManagedMessagingService) NettyMessagingService.builder().withEndpoint(node.endpoint()).build().start().join();
        messagingServices.add(messagingService);
        protocol = new RaftServerMessagingProtocol(messagingService, protocolSerializer, endpointMap::get);
    } else {
        protocol = protocolFactory.newServerProtocol(node.id());
    }
    RaftServer.Builder builder = RaftServer.builder(node.id()).withProtocol(protocol).withThreadModel(ThreadModel.THREAD_PER_SERVICE).withClusterService(new DefaultClusterService(node, new DefaultClusterMetadataService(ClusterMetadata.builder().withBootstrapNodes(members).build(), messagingService), messagingService)).withStorage(RaftStorage.builder().withStorageLevel(StorageLevel.MAPPED).withDirectory(new File(String.format("target/perf-logs/%s", node.id()))).withSerializer(storageSerializer).withMaxEntriesPerSegment(32768).withMaxSegmentSize(1024 * 1024).build()).addPrimitiveType(TestPrimitiveType.INSTANCE);
    RaftServer server = builder.build();
    servers.add(server);
    return server;
}
Also used : RaftServerProtocol(io.atomix.protocols.raft.protocol.RaftServerProtocol) DefaultClusterMetadataService(io.atomix.cluster.impl.DefaultClusterMetadataService) RaftServerMessagingProtocol(io.atomix.protocols.raft.protocol.RaftServerMessagingProtocol) ManagedMessagingService(io.atomix.messaging.ManagedMessagingService) DefaultClusterService(io.atomix.cluster.impl.DefaultClusterService) File(java.io.File)

Example 2 with RaftServerProtocol

use of io.atomix.protocols.raft.protocol.RaftServerProtocol in project zeppelin by apache.

the class ClusterManagerServer method initThread.

private void initThread() {
    // RaftServer Thread
    new Thread(new Runnable() {

        @Override
        public void run() {
            LOGGER.info("RaftServer run() >>>");
            Address address = Address.from(zeplServerHost, raftServerPort);
            Member member = Member.builder(MemberId.from(zeplServerHost + ":" + raftServerPort)).withAddress(address).build();
            messagingService = NettyMessagingService.builder().withAddress(address).build().start().join();
            RaftServerProtocol protocol = new RaftServerMessagingProtocol(messagingService, ClusterManager.protocolSerializer, raftAddressMap::get);
            BootstrapService bootstrapService = new BootstrapService() {

                @Override
                public MessagingService getMessagingService() {
                    return messagingService;
                }

                @Override
                public BroadcastService getBroadcastService() {
                    return new BroadcastServiceAdapter();
                }
            };
            ManagedClusterMembershipService clusterService = new DefaultClusterMembershipService(member, new DefaultNodeDiscoveryService(bootstrapService, member, new BootstrapDiscoveryProvider(clusterNodes)), bootstrapService, new MembershipConfig());
            File atomixDateDir = com.google.common.io.Files.createTempDir();
            atomixDateDir.deleteOnExit();
            RaftServer.Builder builder = RaftServer.builder(member.id()).withMembershipService(clusterService).withProtocol(protocol).withStorage(RaftStorage.builder().withStorageLevel(StorageLevel.MEMORY).withDirectory(atomixDateDir).withSerializer(storageSerializer).withMaxSegmentSize(1024 * 1024).build());
            raftServer = builder.build();
            raftServer.bootstrap(clusterMemberIds);
            messagingService.registerHandler(CLUSTER_INTP_EVENT_TOPIC, subscribeClusterIntpEvent, MoreExecutors.directExecutor());
            messagingService.registerHandler(CLUSTER_NOTE_EVENT_TOPIC, subscribeClusterNoteEvent, MoreExecutors.directExecutor());
            messagingService.registerHandler(CLUSTER_AUTH_EVENT_TOPIC, subscribeClusterAuthEvent, MoreExecutors.directExecutor());
            messagingService.registerHandler(CLUSTER_INTP_SETTING_EVENT_TOPIC, subscribeIntpSettingEvent, MoreExecutors.directExecutor());
            HashMap<String, Object> meta = new HashMap<String, Object>();
            String nodeName = getClusterNodeName();
            meta.put(ClusterMeta.NODE_NAME, nodeName);
            meta.put(ClusterMeta.SERVER_HOST, zeplServerHost);
            meta.put(ClusterMeta.SERVER_PORT, raftServerPort);
            meta.put(ClusterMeta.SERVER_START_TIME, LocalDateTime.now());
            putClusterMeta(SERVER_META, nodeName, meta);
            LOGGER.info("RaftServer run() <<<");
        }
    }).start();
}
Also used : RaftServerProtocol(io.atomix.protocols.raft.protocol.RaftServerProtocol) RaftServerMessagingProtocol(org.apache.zeppelin.cluster.protocol.RaftServerMessagingProtocol) DefaultNodeDiscoveryService(io.atomix.cluster.impl.DefaultNodeDiscoveryService) Address(io.atomix.utils.net.Address) BootstrapDiscoveryProvider(io.atomix.cluster.discovery.BootstrapDiscoveryProvider) RaftServer(io.atomix.protocols.raft.RaftServer) DefaultClusterMembershipService(io.atomix.cluster.impl.DefaultClusterMembershipService) File(java.io.File)

Example 3 with RaftServerProtocol

use of io.atomix.protocols.raft.protocol.RaftServerProtocol in project atomix by atomix.

the class RaftFuzzTest method createServer.

/**
 * Creates a Raft server.
 */
private RaftServer createServer(RaftMember member) {
    RaftServerProtocol protocol;
    if (USE_NETTY) {
        try {
            Endpoint endpoint = new Endpoint(InetAddress.getLocalHost(), ++port);
            MessagingService messagingManager = NettyMessagingService.builder().withEndpoint(endpoint).build().start().join();
            messagingServices.add(messagingManager);
            endpointMap.put(member.nodeId(), endpoint);
            protocol = new RaftServerMessagingProtocol(messagingManager, protocolSerializer, endpointMap::get);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    } else {
        protocol = protocolFactory.newServerProtocol(member.nodeId());
    }
    RaftServer.Builder builder = RaftServer.builder(member.nodeId()).withProtocol(protocol).withStorage(RaftStorage.builder().withStorageLevel(StorageLevel.DISK).withDirectory(new File(String.format("target/fuzz-logs/%s", member.nodeId()))).withSerializer(storageSerializer).withMaxSegmentSize(1024 * 1024).build()).addPrimitiveType(TestPrimitiveType.INSTANCE);
    RaftServer server = builder.build();
    servers.add(server);
    return server;
}
Also used : RaftServerProtocol(io.atomix.protocols.raft.protocol.RaftServerProtocol) RaftServerMessagingProtocol(io.atomix.protocols.raft.protocol.RaftServerMessagingProtocol) Endpoint(io.atomix.messaging.Endpoint) UnknownHostException(java.net.UnknownHostException) File(java.io.File) NettyMessagingService(io.atomix.messaging.impl.NettyMessagingService) MessagingService(io.atomix.messaging.MessagingService)

Aggregations

RaftServerProtocol (io.atomix.protocols.raft.protocol.RaftServerProtocol)3 File (java.io.File)3 RaftServerMessagingProtocol (io.atomix.protocols.raft.protocol.RaftServerMessagingProtocol)2 BootstrapDiscoveryProvider (io.atomix.cluster.discovery.BootstrapDiscoveryProvider)1 DefaultClusterMembershipService (io.atomix.cluster.impl.DefaultClusterMembershipService)1 DefaultClusterMetadataService (io.atomix.cluster.impl.DefaultClusterMetadataService)1 DefaultClusterService (io.atomix.cluster.impl.DefaultClusterService)1 DefaultNodeDiscoveryService (io.atomix.cluster.impl.DefaultNodeDiscoveryService)1 Endpoint (io.atomix.messaging.Endpoint)1 ManagedMessagingService (io.atomix.messaging.ManagedMessagingService)1 MessagingService (io.atomix.messaging.MessagingService)1 NettyMessagingService (io.atomix.messaging.impl.NettyMessagingService)1 RaftServer (io.atomix.protocols.raft.RaftServer)1 Address (io.atomix.utils.net.Address)1 UnknownHostException (java.net.UnknownHostException)1 RaftServerMessagingProtocol (org.apache.zeppelin.cluster.protocol.RaftServerMessagingProtocol)1