Exemplo n.º 1
0
        /// <summary>
        /// Converts an <see cref="VNodeBuilder"/> to a <see cref="ClusterVNode"/>.
        /// </summary>
        /// <param name="options">The options with which to build the infoController</param>
        /// <param name="consumerStrategies">The consumer strategies with which to build the node</param>
        /// <returns>A <see cref="ClusterVNode"/> built with the options that were set on the <see cref="VNodeBuilder"/></returns>
        public ClusterVNode Build(IOptions options = null, IPersistentSubscriptionConsumerStrategyFactory[] consumerStrategies = null)
        {
            EnsureHttpPrefixes();
            SetUpProjectionsIfNeeded();
            _gossipAdvertiseInfo = EnsureGossipAdvertiseInfo();


            _dbConfig = CreateDbConfig(_chunkSize, _cachedChunks, _dbPath, _chunksCacheSize,
                    _inMemoryDb, _log);
            FileStreamExtensions.ConfigureFlush(disableFlushToDisk: _unsafeDisableFlushToDisk);

            _db = new TFChunkDb(_dbConfig);

            _vNodeSettings = new ClusterVNodeSettings(Guid.NewGuid(),
                    0,
                    _internalTcp,
                    _internalSecureTcp,
                    _externalTcp,
                    _externalSecureTcp,
                    _internalHttp,
                    _externalHttp,
                    _gossipAdvertiseInfo,
                    _intHttpPrefixes.ToArray(),
                    _extHttpPrefixes.ToArray(),
                    _enableTrustedAuth,
                    _certificate,
                    _workerThreads,
                    _discoverViaDns,
                    _clusterDns,
                    _gossipSeeds.ToArray(),
                    _minFlushDelay,
                    _clusterNodeCount,
                    _prepareAckCount,
                    _commitAckCount,
                    _prepareTimeout,
                    _commitTimeout,
                    _useSsl,
                    _sslTargetHost,
                    _sslValidateServer,
                    _statsPeriod,
                    _statsStorage,
                    _nodePriority,
                    _authenticationProviderFactory,
                    _disableScavengeMerging,
                    _scavengeHistoryMaxAge,
                    _adminOnPublic,
                    _statsOnPublic,
                    _gossipOnPublic,
                    _gossipInterval,
                    _gossipAllowedTimeDifference,
                    _gossipTimeout,
                    _intTcpHeartbeatTimeout,
                    _intTcpHeartbeatInterval,
                    _extTcpHeartbeatTimeout,
                    _extTcpHeartbeatInterval,
                    !_skipVerifyDbHashes,
                    _maxMemtableSize,
                    _hashCollisionReadLimit,
                    _startStandardProjections,
                    _disableHTTPCaching,
                    _logHttpRequests,
                    _index,
                    _enableHistograms,
                    _indexCacheDepth,
                    _indexBitnessVersion,
                    consumerStrategies,
                    _unsafeIgnoreHardDelete,
                    _betterOrdering,
                    _readerThreadsCount,
                    _alwaysKeepScavenged);
            var infoController = new InfoController(options, _projectionType);

            _log.Info("{0,-25} {1}", "INSTANCE ID:", _vNodeSettings.NodeInfo.InstanceId);
            _log.Info("{0,-25} {1}", "DATABASE:", _db.Config.Path);
            _log.Info("{0,-25} {1} (0x{1:X})", "WRITER CHECKPOINT:", _db.Config.WriterCheckpoint.Read());
            _log.Info("{0,-25} {1} (0x{1:X})", "CHASER CHECKPOINT:", _db.Config.ChaserCheckpoint.Read());
            _log.Info("{0,-25} {1} (0x{1:X})", "EPOCH CHECKPOINT:", _db.Config.EpochCheckpoint.Read());
            _log.Info("{0,-25} {1} (0x{1:X})", "TRUNCATE CHECKPOINT:", _db.Config.TruncateCheckpoint.Read());

            return new ClusterVNode(_db, _vNodeSettings, GetGossipSource(), infoController, _subsystems.ToArray());
        }
Exemplo n.º 2
0
        public ClusterVNodeSettings(Guid instanceId, int debugIndex,
                                    IPEndPoint internalTcpEndPoint,
                                    IPEndPoint internalSecureTcpEndPoint,
                                    IPEndPoint externalTcpEndPoint,
                                    IPEndPoint externalSecureTcpEndPoint,
                                    IPEndPoint internalHttpEndPoint,
                                    IPEndPoint externalHttpEndPoint,
                                    GossipAdvertiseInfo gossipAdvertiseInfo,
                                    string[] intHttpPrefixes,
                                    string[] extHttpPrefixes,
                                    bool enableTrustedAuth,
                                    X509Certificate2 certificate,
                                    int workerThreads,
                                    bool discoverViaDns,
                                    string clusterDns,
                                    IPEndPoint[] gossipSeeds,
                                    TimeSpan minFlushDelay,
                                    int clusterNodeCount,
                                    int prepareAckCount,
                                    int commitAckCount,
                                    TimeSpan prepareTimeout,
                                    TimeSpan commitTimeout,
                                    bool useSsl,
                                    string sslTargetHost,
                                    bool sslValidateServer,
                                    TimeSpan statsPeriod,
                                    StatsStorage statsStorage,
                                    int nodePriority,
                                    IAuthenticationProviderFactory authenticationProviderFactory,
                                    bool disableScavengeMerging,
                                    bool adminOnPublic,
                                    bool statsOnPublic,
                                    bool gossipOnPublic,
                                    TimeSpan gossipInterval,
                                    TimeSpan gossipAllowedTimeDifference,
                                    TimeSpan gossipTimeout,
                                    TimeSpan intTcpHeartbeatTimeout,
                                    TimeSpan intTcpHeartbeatInterval,
                                    TimeSpan extTcpHeartbeatTimeout,
                                    TimeSpan extTcpHeartbeatInterval,
				                    bool verifyDbHash,
				                    int maxMemtableEntryCount,
                                    bool startStandardProjections,
                                    bool disableHTTPCaching, string index = null, bool enableHistograms = false,
                                    int indexCacheDepth = 16,
                                    IPersistentSubscriptionConsumerStrategyFactory[] additionalConsumerStrategies = null)
        {
            Ensure.NotEmptyGuid(instanceId, "instanceId");
            Ensure.NotNull(internalTcpEndPoint, "internalTcpEndPoint");
            Ensure.NotNull(externalTcpEndPoint, "externalTcpEndPoint");
            Ensure.NotNull(internalHttpEndPoint, "internalHttpEndPoint");
            Ensure.NotNull(externalHttpEndPoint, "externalHttpEndPoint");
            Ensure.NotNull(intHttpPrefixes, "intHttpPrefixes");
            Ensure.NotNull(extHttpPrefixes, "extHttpPrefixes");
            if (internalSecureTcpEndPoint != null || externalSecureTcpEndPoint != null)
                Ensure.NotNull(certificate, "certificate");
            Ensure.Positive(workerThreads, "workerThreads");
            Ensure.NotNull(clusterDns, "clusterDns");
            Ensure.NotNull(gossipSeeds, "gossipSeeds");
            Ensure.Positive(clusterNodeCount, "clusterNodeCount");
            Ensure.Positive(prepareAckCount, "prepareAckCount");
            Ensure.Positive(commitAckCount, "commitAckCount");
            Ensure.NotNull(gossipAdvertiseInfo, "gossipAdvertiseInfo");

            if (discoverViaDns && string.IsNullOrWhiteSpace(clusterDns))
                throw new ArgumentException("Either DNS Discovery must be disabled (and seeds specified), or a cluster DNS name must be provided.");

            if (useSsl)
                Ensure.NotNull(sslTargetHost, "sslTargetHost");

            NodeInfo = new VNodeInfo(instanceId, debugIndex,
                                     internalTcpEndPoint, internalSecureTcpEndPoint,
                                     externalTcpEndPoint, externalSecureTcpEndPoint,
                                     internalHttpEndPoint, externalHttpEndPoint);
            GossipAdvertiseInfo = gossipAdvertiseInfo;
            IntHttpPrefixes = intHttpPrefixes;
            ExtHttpPrefixes = extHttpPrefixes;
            EnableTrustedAuth = enableTrustedAuth;
            Certificate = certificate;
            WorkerThreads = workerThreads;
            StartStandardProjections = startStandardProjections;
            DisableHTTPCaching = disableHTTPCaching;
            AdditionalConsumerStrategies = additionalConsumerStrategies ?? new IPersistentSubscriptionConsumerStrategyFactory[0];

            DiscoverViaDns = discoverViaDns;
            ClusterDns = clusterDns;
            GossipSeeds = gossipSeeds;

            ClusterNodeCount = clusterNodeCount;
            MinFlushDelay = minFlushDelay;
            PrepareAckCount = prepareAckCount;
            CommitAckCount = commitAckCount;
            PrepareTimeout = prepareTimeout;
            CommitTimeout = commitTimeout;

            UseSsl = useSsl;
            SslTargetHost = sslTargetHost;
            SslValidateServer = sslValidateServer;

            StatsPeriod = statsPeriod;
            StatsStorage = statsStorage;

            AuthenticationProviderFactory = authenticationProviderFactory;

            NodePriority = nodePriority;
            DisableScavengeMerging = disableScavengeMerging;
            AdminOnPublic = adminOnPublic;
            StatsOnPublic = statsOnPublic;
            GossipOnPublic = gossipOnPublic;
            GossipInterval = gossipInterval;
            GossipAllowedTimeDifference = gossipAllowedTimeDifference;
            GossipTimeout = gossipTimeout;
            IntTcpHeartbeatTimeout = intTcpHeartbeatTimeout;
            IntTcpHeartbeatInterval = intTcpHeartbeatInterval;
            ExtTcpHeartbeatTimeout = extTcpHeartbeatTimeout;
            ExtTcpHeartbeatInterval = extTcpHeartbeatInterval;

            VerifyDbHash = verifyDbHash;
            MaxMemtableEntryCount = maxMemtableEntryCount;

            EnableHistograms = enableHistograms;
            IndexCacheDepth = indexCacheDepth;
            Index = index;
        }
Exemplo n.º 3
0
        private GossipAdvertiseInfo EnsureGossipAdvertiseInfo()
        {
            if (_gossipAdvertiseInfo == null)
            {
                IPAddress intIpAddressToAdvertise = _advertiseInternalIPAs ?? _internalTcp.Address;
                IPAddress extIpAddressToAdvertise = _advertiseExternalIPAs ?? _externalTcp.Address;

                if ((_internalTcp.Address.Equals(IPAddress.Parse("0.0.0.0")) ||
                     _externalTcp.Address.Equals(IPAddress.Parse("0.0.0.0"))) && _addInterfacePrefixes)
                {
                    IPAddress nonLoopbackAddress = IPFinder.GetNonLoopbackAddress();
                    IPAddress addressToAdvertise = _clusterNodeCount > 1 ? nonLoopbackAddress : IPAddress.Loopback;

                    if (_internalTcp.Address.Equals(IPAddress.Parse("0.0.0.0")) && _advertiseInternalIPAs == null)
                    {
                        intIpAddressToAdvertise = addressToAdvertise;
                    }
                    if (_externalTcp.Address.Equals(IPAddress.Parse("0.0.0.0")) && _advertiseExternalIPAs == null)
                    {
                        extIpAddressToAdvertise = addressToAdvertise;
                    }
                }
                var intTcpPort = _advertiseInternalTcpPortAs > 0 ? _advertiseInternalTcpPortAs : _internalTcp.Port;
                var intTcpEndPoint = new IPEndPoint(intIpAddressToAdvertise, intTcpPort);
                var intSecureTcpPort = _advertiseInternalSecureTcpPortAs > 0 ? _advertiseInternalSecureTcpPortAs : _internalSecureTcp == null ? 0 : _internalSecureTcp.Port;
                var intSecureTcpEndPoint = new IPEndPoint(intIpAddressToAdvertise, intSecureTcpPort);

                var extTcpPort = _advertiseExternalTcpPortAs > 0 ? _advertiseExternalTcpPortAs : _externalTcp.Port;
                var extTcpEndPoint = new IPEndPoint(extIpAddressToAdvertise, extTcpPort);
                var extSecureTcpPort = _advertiseExternalSecureTcpPortAs > 0 ? _advertiseExternalSecureTcpPortAs : _externalSecureTcp == null ? 0 : _externalSecureTcp.Port;
                var extSecureTcpEndPoint = new IPEndPoint(extIpAddressToAdvertise, extSecureTcpPort);

                var intHttpPort = _advertiseInternalHttpPortAs > 0 ? _advertiseInternalHttpPortAs : _internalHttp.Port;
                var extHttpPort = _advertiseExternalHttpPortAs > 0 ? _advertiseExternalHttpPortAs : _externalHttp.Port; 

                var intHttpEndPoint = new IPEndPoint(intIpAddressToAdvertise, intHttpPort);
                var extHttpEndPoint = new IPEndPoint(extIpAddressToAdvertise, extHttpPort);

                _gossipAdvertiseInfo = new GossipAdvertiseInfo(intTcpEndPoint, intSecureTcpEndPoint,
                                                              extTcpEndPoint, extSecureTcpEndPoint,
                                                              intHttpEndPoint, extHttpEndPoint,
                                                              _advertiseInternalIPAs, _advertiseExternalIPAs,
                                                              _advertiseInternalHttpPortAs, _advertiseExternalHttpPortAs);
            }
            return _gossipAdvertiseInfo;
        }