Esempio n. 1
0
        internal static MemberAttributeConfig BuildMemberAttributesForCore(MemberId myself, Config config)
        {
            MemberAttributeConfig memberAttributeConfig = new MemberAttributeConfig();

            memberAttributeConfig.setStringAttribute(MEMBER_UUID, myself.Uuid.ToString());

            AdvertisedSocketAddress discoveryAddress = config.Get(CausalClusteringSettings.discovery_advertised_address);

            memberAttributeConfig.setStringAttribute(DISCOVERY_SERVER, discoveryAddress.ToString());

            AdvertisedSocketAddress transactionSource = config.Get(CausalClusteringSettings.transaction_advertised_address);

            memberAttributeConfig.setStringAttribute(TRANSACTION_SERVER, transactionSource.ToString());

            AdvertisedSocketAddress raftAddress = config.Get(CausalClusteringSettings.raft_advertised_address);

            memberAttributeConfig.setStringAttribute(RAFT_SERVER, raftAddress.ToString());

            ClientConnectorAddresses clientConnectorAddresses = ClientConnectorAddresses.ExtractFromConfig(config);

            memberAttributeConfig.setStringAttribute(CLIENT_CONNECTOR_ADDRESSES, clientConnectorAddresses.ToString());

            memberAttributeConfig.setBooleanAttribute(REFUSE_TO_BE_LEADER_KEY, config.Get(refuse_to_be_leader));

            memberAttributeConfig.setStringAttribute(MEMBER_DB_NAME, config.Get(CausalClusteringSettings.database));

            return(memberAttributeConfig);
        }
Esempio n. 2
0
        private HazelcastInstance CreateHazelcastInstance()
        {
            JoinConfig joinConfig = new JoinConfig();

            joinConfig.MulticastConfig.Enabled = false;
            TcpIpConfig tcpIpConfig = joinConfig.TcpIpConfig;

            tcpIpConfig.Enabled = true;

//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            ICollection <string> initialMembers = _remoteMembersResolver.resolve(SocketAddress::toString);

            initialMembers.forEach(tcpIpConfig.addMember);

            ListenSocketAddress hazelcastAddress = Config.get(discovery_listen_address);
            NetworkConfig       networkConfig    = new NetworkConfig();

            if (!hazelcastAddress.Wildcard)
            {
                InterfacesConfig interfaces = new InterfacesConfig();
                interfaces.addInterface(hazelcastAddress.Hostname);
                interfaces.Enabled       = true;
                networkConfig.Interfaces = interfaces;
            }

            networkConfig.Port = hazelcastAddress.Port;
            networkConfig.Join = joinConfig;
            networkConfig.PortAutoIncrement = false;

            // We'll use election_timeout as a base value to calculate HZ timeouts. We multiply by 1.5
            long?electionTimeoutMillis      = Config.get(CausalClusteringSettings.leader_election_timeout).toMillis();
            long?baseHazelcastTimeoutMillis = (3 * electionTimeoutMillis) / 2;

            /*
             * Some HZ settings require the value in seconds. Adding the divider and subtracting 1 is equivalent to the
             * ceiling function for integers ( Math.ceil() returns double ). Anything < 0 will return 0, any
             * multiple of 1000 returns the result of the division by 1000, any non multiple of 1000 returns the result
             * of the division + 1. In other words, values in millis are rounded up.
             */
            long baseHazelcastTimeoutSeconds = (baseHazelcastTimeoutMillis + 1000 - 1) / 1000;

            com.hazelcast.config.Config c = new com.hazelcast.config.Config();
            c.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.Name, baseHazelcastTimeoutMillis.ToString());
            c.setProperty(MERGE_NEXT_RUN_DELAY_SECONDS.Name, baseHazelcastTimeoutSeconds.ToString());
            c.setProperty(MERGE_FIRST_RUN_DELAY_SECONDS.Name, baseHazelcastTimeoutSeconds.ToString());
            c.setProperty(INITIAL_MIN_CLUSTER_SIZE.Name, HAZELCAST_MIN_CLUSTER.ToString());

            if (Config.get(disable_middleware_logging))
            {
                c.setProperty(LOGGING_TYPE.Name, "none");
            }

            if (hazelcastAddress.IPv6)
            {
                c.setProperty(PREFER_IPv4_STACK.Name, "false");
            }

            c.NetworkConfig = networkConfig;

            MemberAttributeConfig memberAttributeConfig = HazelcastClusterTopology.BuildMemberAttributesForCore(MyselfConflict, Config);

            c.MemberAttributeConfig = memberAttributeConfig;
            LogConnectionInfo(initialMembers);
            c.addListenerConfig(new ListenerConfig(new OurMembershipListener(this)));

            JobHandle logJob = _scheduler.schedule(Group.HZ_TOPOLOGY_HEALTH, _hazelcastIsHealthyTimeoutMs, () => Log.warn("The server has not been able to connect in a timely fashion to the " + "cluster. Please consult the logs for more details. Rebooting the server may " + "solve the problem."));

            try
            {
                _hazelcastInstance = Hazelcast.newHazelcastInstance(c);
                logJob.Cancel(true);
            }
            catch (HazelcastException e)
            {
                string errorMessage = string.Format("Hazelcast was unable to start with setting: {0} = {1}", discovery_listen_address.name(), Config.get(discovery_listen_address));
                UserLog.error(errorMessage);
                Log.error(errorMessage, e);
                throw new Exception(e);
            }

            IList <string> groups = Config.get(CausalClusteringSettings.server_groups);

            refreshGroups(_hazelcastInstance, MyselfConflict.Uuid.ToString(), groups);

            return(_hazelcastInstance);
        }