Search in sources :

Example 1 with MessagingConfig

use of io.atomix.cluster.messaging.MessagingConfig in project atomix by atomix.

the class RaftPerformanceTest method createClient.

/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Exception {
    Member member = nextNode();
    RaftClientProtocol protocol;
    if (USE_NETTY) {
        MessagingService messagingService = new NettyMessagingService("test", member.address(), new MessagingConfig()).start().join();
        protocol = new RaftClientMessagingProtocol(messagingService, PROTOCOL_SERIALIZER, addressMap::get);
    } else {
        protocol = protocolFactory.newClientProtocol(member.id());
    }
    RaftClient client = RaftClient.builder().withMemberId(member.id()).withPartitionId(PartitionId.from("test", 1)).withProtocol(protocol).withThreadModel(ThreadModel.SHARED_THREAD_POOL).build();
    client.connect(members.stream().map(Member::id).collect(Collectors.toList())).join();
    clients.add(client);
    return client;
}
Also used : MessagingConfig(io.atomix.cluster.messaging.MessagingConfig) RaftClientProtocol(io.atomix.protocols.raft.protocol.RaftClientProtocol) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) RaftClientMessagingProtocol(io.atomix.protocols.raft.test.protocol.RaftClientMessagingProtocol) Member(io.atomix.cluster.Member) RaftMember(io.atomix.protocols.raft.cluster.RaftMember) DefaultRaftMember(io.atomix.protocols.raft.cluster.impl.DefaultRaftMember) RaftClient(io.atomix.protocols.raft.RaftClient) MessagingService(io.atomix.cluster.messaging.MessagingService) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) ManagedMessagingService(io.atomix.cluster.messaging.ManagedMessagingService)

Example 2 with MessagingConfig

use of io.atomix.cluster.messaging.MessagingConfig in project atomix by atomix.

the class RaftPerformanceTest method createServer.

/**
 * Creates a Raft server.
 */
private RaftServer createServer(Member member, List<Node> members) {
    RaftServerProtocol protocol;
    ManagedMessagingService messagingService;
    if (USE_NETTY) {
        messagingService = (ManagedMessagingService) new NettyMessagingService("test", member.address(), new MessagingConfig()).start().join();
        messagingServices.add(messagingService);
        protocol = new RaftServerMessagingProtocol(messagingService, PROTOCOL_SERIALIZER, addressMap::get);
    } else {
        protocol = protocolFactory.newServerProtocol(member.id());
    }
    BootstrapService bootstrapService = new BootstrapService() {

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

        @Override
        public UnicastService getUnicastService() {
            return new UnicastServiceAdapter();
        }

        @Override
        public BroadcastService getBroadcastService() {
            return new BroadcastServiceAdapter();
        }
    };
    RaftServer.Builder builder = RaftServer.builder(member.id()).withProtocol(protocol).withThreadModel(ThreadModel.SHARED_THREAD_POOL).withMembershipService(new DefaultClusterMembershipService(member, Version.from("1.0.0"), new DefaultNodeDiscoveryService(bootstrapService, member, new BootstrapDiscoveryProvider(members)), bootstrapService, new HeartbeatMembershipProtocol(new HeartbeatMembershipProtocolConfig()))).withStorage(RaftStorage.builder().withStorageLevel(StorageLevel.DISK).withDirectory(new File(String.format("target/perf-logs/%s", member.id()))).withNamespace(STORAGE_NAMESPACE).withMaxSegmentSize(1024 * 1024 * 64).withDynamicCompaction().withFlushOnCommit(false).build());
    RaftServer server = builder.build();
    servers.add(server);
    return server;
}
Also used : RaftServerProtocol(io.atomix.protocols.raft.protocol.RaftServerProtocol) RaftServerMessagingProtocol(io.atomix.protocols.raft.test.protocol.RaftServerMessagingProtocol) DefaultNodeDiscoveryService(io.atomix.cluster.impl.DefaultNodeDiscoveryService) RaftServer(io.atomix.protocols.raft.RaftServer) BootstrapDiscoveryProvider(io.atomix.cluster.discovery.BootstrapDiscoveryProvider) ManagedMessagingService(io.atomix.cluster.messaging.ManagedMessagingService) HeartbeatMembershipProtocolConfig(io.atomix.cluster.protocol.HeartbeatMembershipProtocolConfig) MessagingConfig(io.atomix.cluster.messaging.MessagingConfig) DefaultClusterMembershipService(io.atomix.cluster.impl.DefaultClusterMembershipService) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) HeartbeatMembershipProtocol(io.atomix.cluster.protocol.HeartbeatMembershipProtocol) File(java.io.File) BootstrapService(io.atomix.cluster.BootstrapService)

Example 3 with MessagingConfig

use of io.atomix.cluster.messaging.MessagingConfig in project atomix by atomix.

the class RaftFuzzTest method createClient.

/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Exception {
    MemberId memberId = nextNodeId();
    RaftClientProtocol protocol;
    if (USE_NETTY) {
        Address address = Address.from(++port);
        MessagingService messagingManager = new NettyMessagingService("test", address, new MessagingConfig()).start().join();
        addressMap.put(memberId, address);
        protocol = new RaftClientMessagingProtocol(messagingManager, PROTOCOL_SERIALIZER, addressMap::get);
    } else {
        protocol = protocolFactory.newClientProtocol(memberId);
    }
    RaftClient client = RaftClient.builder().withMemberId(memberId).withProtocol(protocol).build();
    client.connect(members.stream().map(RaftMember::memberId).collect(Collectors.toList())).join();
    clients.add(client);
    return client;
}
Also used : MessagingConfig(io.atomix.cluster.messaging.MessagingConfig) MemberId(io.atomix.cluster.MemberId) RaftClientProtocol(io.atomix.protocols.raft.protocol.RaftClientProtocol) Address(io.atomix.utils.net.Address) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) RaftClientMessagingProtocol(io.atomix.protocols.raft.test.protocol.RaftClientMessagingProtocol) RaftClient(io.atomix.protocols.raft.RaftClient) MessagingService(io.atomix.cluster.messaging.MessagingService) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService)

Example 4 with MessagingConfig

use of io.atomix.cluster.messaging.MessagingConfig in project atomix by atomix.

the class AtomixConfigTest method testAtomixConfig.

@Test
public void testAtomixConfig() throws Exception {
    AtomixConfig config = Atomix.config(getClass().getClassLoader().getResource("test.conf").getPath());
    ClusterConfig cluster = config.getClusterConfig();
    assertEquals("test", cluster.getClusterId());
    MemberConfig node = cluster.getNodeConfig();
    assertEquals("one", node.getId().id());
    assertEquals("localhost:5000", node.getAddress().toString());
    assertEquals("foo", node.getZoneId());
    assertEquals("bar", node.getRackId());
    assertEquals("baz", node.getHostId());
    assertEquals("bar", node.getProperties().getProperty("foo"));
    assertEquals("baz", node.getProperties().getProperty("bar"));
    MulticastConfig multicast = cluster.getMulticastConfig();
    assertTrue(multicast.isEnabled());
    assertEquals("230.0.1.1", multicast.getGroup().getHostAddress());
    assertEquals(56789, multicast.getPort());
    HeartbeatMembershipProtocolConfig protocol = (HeartbeatMembershipProtocolConfig) cluster.getProtocolConfig();
    assertEquals(Duration.ofMillis(200), protocol.getHeartbeatInterval());
    assertEquals(12, protocol.getPhiFailureThreshold());
    assertEquals(Duration.ofSeconds(15), protocol.getFailureTimeout());
    MembershipConfig membership = cluster.getMembershipConfig();
    assertEquals(Duration.ofSeconds(1), membership.getBroadcastInterval());
    assertEquals(12, membership.getReachabilityThreshold());
    assertEquals(Duration.ofSeconds(15), membership.getReachabilityTimeout());
    MulticastDiscoveryConfig discovery = (MulticastDiscoveryConfig) cluster.getDiscoveryConfig();
    assertEquals(MulticastDiscoveryProvider.TYPE, discovery.getType());
    assertEquals(Duration.ofSeconds(1), discovery.getBroadcastInterval());
    assertEquals(12, discovery.getFailureThreshold());
    assertEquals(Duration.ofSeconds(15), discovery.getFailureTimeout());
    MessagingConfig messaging = cluster.getMessagingConfig();
    assertEquals(2, messaging.getInterfaces().size());
    assertEquals("127.0.0.1", messaging.getInterfaces().get(0));
    assertEquals("0.0.0.0", messaging.getInterfaces().get(1));
    assertEquals(5000, messaging.getPort().intValue());
    assertEquals(Duration.ofSeconds(10), messaging.getConnectTimeout());
    assertTrue(messaging.getTlsConfig().isEnabled());
    assertEquals("keystore.jks", messaging.getTlsConfig().getKeyStore());
    assertEquals("foo", messaging.getTlsConfig().getKeyStorePassword());
    assertEquals("truststore.jks", messaging.getTlsConfig().getTrustStore());
    assertEquals("bar", messaging.getTlsConfig().getTrustStorePassword());
    RaftPartitionGroupConfig managementGroup = (RaftPartitionGroupConfig) config.getManagementGroup();
    assertEquals(RaftPartitionGroup.TYPE, managementGroup.getType());
    assertEquals(1, managementGroup.getPartitions());
    assertEquals(Duration.ofSeconds(5), managementGroup.getElectionTimeout());
    assertEquals(Duration.ofMillis(500), managementGroup.getHeartbeatInterval());
    assertEquals(Duration.ofSeconds(10), managementGroup.getDefaultSessionTimeout());
    assertEquals(new MemorySize(1024 * 1024 * 16), managementGroup.getStorageConfig().getSegmentSize());
    RaftPartitionGroupConfig groupOne = (RaftPartitionGroupConfig) config.getPartitionGroups().get("one");
    assertEquals(RaftPartitionGroup.TYPE, groupOne.getType());
    assertEquals("one", groupOne.getName());
    assertEquals(7, groupOne.getPartitions());
    PrimaryBackupPartitionGroupConfig groupTwo = (PrimaryBackupPartitionGroupConfig) config.getPartitionGroups().get("two");
    assertEquals(PrimaryBackupPartitionGroup.TYPE, groupTwo.getType());
    assertEquals("two", groupTwo.getName());
    assertEquals(32, groupTwo.getPartitions());
    LogPartitionGroupConfig groupThree = (LogPartitionGroupConfig) config.getPartitionGroups().get("three");
    assertEquals(LogPartitionGroup.TYPE, groupThree.getType());
    assertEquals("three", groupThree.getName());
    assertEquals(3, groupThree.getPartitions());
    ConsensusProfileConfig consensusProfile = (ConsensusProfileConfig) config.getProfiles().get(0);
    assertEquals(ConsensusProfile.TYPE, consensusProfile.getType());
    assertEquals("management", consensusProfile.getManagementGroup());
    assertEquals("consensus", consensusProfile.getDataGroup());
    assertEquals(3, consensusProfile.getPartitions());
    assertTrue(consensusProfile.getMembers().containsAll(Arrays.asList("one", "two", "three")));
    DataGridProfileConfig dataGridProfile = (DataGridProfileConfig) config.getProfiles().get(1);
    assertEquals(DataGridProfile.TYPE, dataGridProfile.getType());
    assertEquals("management", dataGridProfile.getManagementGroup());
    assertEquals("data", dataGridProfile.getDataGroup());
    assertEquals(32, dataGridProfile.getPartitions());
    AtomicMapConfig fooDefaults = config.getPrimitiveDefault("atomic-map");
    assertEquals("atomic-map", fooDefaults.getType().name());
    assertEquals("two", ((MultiPrimaryProtocolConfig) fooDefaults.getProtocolConfig()).getGroup());
    AtomicMapConfig foo = config.getPrimitive("foo");
    assertEquals("atomic-map", foo.getType().name());
    assertTrue(foo.isNullValues());
    DistributedSetConfig bar = config.getPrimitive("bar");
    assertTrue(bar.getCacheConfig().isEnabled());
    MultiPrimaryProtocolConfig multiPrimary = (MultiPrimaryProtocolConfig) bar.getProtocolConfig();
    assertEquals(MultiPrimaryProtocol.TYPE, multiPrimary.getType());
    assertEquals(Replication.SYNCHRONOUS, multiPrimary.getReplication());
    assertEquals(Duration.ofSeconds(1), multiPrimary.getRetryDelay());
    AtomicValueConfig baz = config.getPrimitive("baz");
    MultiRaftProtocolConfig multiRaft = (MultiRaftProtocolConfig) baz.getProtocolConfig();
    assertEquals(ReadConsistency.SEQUENTIAL, multiRaft.getReadConsistency());
    assertEquals(Recovery.RECOVER, multiRaft.getRecoveryStrategy());
    assertEquals(Duration.ofSeconds(2), multiRaft.getRetryDelay());
    DistributedLogConfig log = config.getPrimitive("log");
    assertEquals("log", log.getType().name());
    DistributedLogProtocolConfig logConfig = (DistributedLogProtocolConfig) log.getProtocolConfig();
    assertEquals(DistributedLogProtocol.TYPE, logConfig.getType());
    assertEquals("three", logConfig.getGroup());
}
Also used : MultiRaftProtocolConfig(io.atomix.protocols.raft.MultiRaftProtocolConfig) MemorySize(io.atomix.utils.memory.MemorySize) MembershipConfig(io.atomix.cluster.MembershipConfig) DistributedLogConfig(io.atomix.core.log.DistributedLogConfig) MulticastDiscoveryConfig(io.atomix.cluster.discovery.MulticastDiscoveryConfig) DistributedSetConfig(io.atomix.core.set.DistributedSetConfig) DistributedLogProtocolConfig(io.atomix.protocols.log.DistributedLogProtocolConfig) HeartbeatMembershipProtocolConfig(io.atomix.cluster.protocol.HeartbeatMembershipProtocolConfig) AtomicValueConfig(io.atomix.core.value.AtomicValueConfig) MessagingConfig(io.atomix.cluster.messaging.MessagingConfig) AtomicMapConfig(io.atomix.core.map.AtomicMapConfig) RaftPartitionGroupConfig(io.atomix.protocols.raft.partition.RaftPartitionGroupConfig) PrimaryBackupPartitionGroupConfig(io.atomix.protocols.backup.partition.PrimaryBackupPartitionGroupConfig) ConsensusProfileConfig(io.atomix.core.profile.ConsensusProfileConfig) MultiPrimaryProtocolConfig(io.atomix.protocols.backup.MultiPrimaryProtocolConfig) MulticastConfig(io.atomix.cluster.MulticastConfig) MemberConfig(io.atomix.cluster.MemberConfig) DataGridProfileConfig(io.atomix.core.profile.DataGridProfileConfig) ClusterConfig(io.atomix.cluster.ClusterConfig) LogPartitionGroupConfig(io.atomix.protocols.log.partition.LogPartitionGroupConfig) Test(org.junit.Test)

Example 5 with MessagingConfig

use of io.atomix.cluster.messaging.MessagingConfig in project atomix by atomix.

the class NettyMessagingServiceTest method setUp.

@Before
public void setUp() throws Exception {
    address1 = Address.from(findAvailablePort(5001));
    netty1 = (ManagedMessagingService) new NettyMessagingService("test", address1, new MessagingConfig()).start().join();
    address2 = Address.from(findAvailablePort(5002));
    netty2 = (ManagedMessagingService) new NettyMessagingService("test", address2, new MessagingConfig()).start().join();
    addressv11 = Address.from(findAvailablePort(5003));
    nettyv11 = (ManagedMessagingService) new NettyMessagingService("test", addressv11, new MessagingConfig(), ProtocolVersion.V1).start().join();
    addressv12 = Address.from(findAvailablePort(5004));
    nettyv12 = (ManagedMessagingService) new NettyMessagingService("test", addressv12, new MessagingConfig(), ProtocolVersion.V1).start().join();
    addressv21 = Address.from(findAvailablePort(5005));
    nettyv21 = (ManagedMessagingService) new NettyMessagingService("test", addressv21, new MessagingConfig(), ProtocolVersion.V2).start().join();
    addressv22 = Address.from(findAvailablePort(5006));
    nettyv22 = (ManagedMessagingService) new NettyMessagingService("test", addressv22, new MessagingConfig(), ProtocolVersion.V2).start().join();
    invalidAddress = Address.from(IP_STRING, 5007);
}
Also used : MessagingConfig(io.atomix.cluster.messaging.MessagingConfig) Before(org.junit.Before)

Aggregations

MessagingConfig (io.atomix.cluster.messaging.MessagingConfig)6 NettyMessagingService (io.atomix.cluster.messaging.impl.NettyMessagingService)4 MessagingService (io.atomix.cluster.messaging.MessagingService)3 ManagedMessagingService (io.atomix.cluster.messaging.ManagedMessagingService)2 HeartbeatMembershipProtocolConfig (io.atomix.cluster.protocol.HeartbeatMembershipProtocolConfig)2 RaftClient (io.atomix.protocols.raft.RaftClient)2 RaftServer (io.atomix.protocols.raft.RaftServer)2 RaftClientProtocol (io.atomix.protocols.raft.protocol.RaftClientProtocol)2 RaftServerProtocol (io.atomix.protocols.raft.protocol.RaftServerProtocol)2 RaftClientMessagingProtocol (io.atomix.protocols.raft.test.protocol.RaftClientMessagingProtocol)2 RaftServerMessagingProtocol (io.atomix.protocols.raft.test.protocol.RaftServerMessagingProtocol)2 Address (io.atomix.utils.net.Address)2 File (java.io.File)2 BootstrapService (io.atomix.cluster.BootstrapService)1 ClusterConfig (io.atomix.cluster.ClusterConfig)1 Member (io.atomix.cluster.Member)1 MemberConfig (io.atomix.cluster.MemberConfig)1 MemberId (io.atomix.cluster.MemberId)1 MembershipConfig (io.atomix.cluster.MembershipConfig)1 MulticastConfig (io.atomix.cluster.MulticastConfig)1