Ejemplo n.º 1
0
        internal async Task InitializeAsync()
        {
            //try to connect via GCCP
            foreach (var uri in _clusterOptions.Servers)
            {
                try
                {
                    var endPoint      = uri.GetIpEndPoint(11210, false);
                    var bootstrapNode = await GetClusterNode(endPoint, uri).ConfigureAwait(false);

                    //note this returns bucketConfig, but clusterConfig will be returned once server supports GCCP
                    _clusterConfig = await bootstrapNode.GetClusterMap().ConfigureAwait(false);

                    if (_clusterConfig == null)//TODO fix bug NCBC-1966 - hiding XError when no error map (and others)
                    {
                        //No GCCP but we connected - save connections and info for connecting later
                        _clusterOptions.GlobalNodes.Add(bootstrapNode);
                    }
                    else
                    {
                        foreach (var nodesExt in _clusterConfig.GetNodes())
                        {
                            //This is the bootstrap node so we update it
                            if (uri.Host == nodesExt.Hostname)
                            {
                                bootstrapNode.NodesAdapter = nodesExt;
                                bootstrapNode.BuildServiceUris();
                                _clusterOptions.GlobalNodes.Add(bootstrapNode);
                            }
                            else
                            {
                                endPoint = IpEndPointExtensions.GetEndPoint(nodesExt.Hostname, 11210);
                                var clusterNode = await GetClusterNode(endPoint, uri).ConfigureAwait(false);

                                clusterNode.NodesAdapter = nodesExt;
                                clusterNode.BuildServiceUris();
                                _clusterOptions.GlobalNodes.Add(clusterNode);
                            }
                        }

                        // get cluster capabilities
                        UpdateClusterCapabilities(_clusterConfig.GetClusterCapabilities());
                        _hasBootStrapped = true;
                    }
                }
                catch (AuthenticationException e)
                {
                    //auth failed so bubble up exception and clean up resources
                    Log.LogError(e, @"Could not authenticate user {_clusterOptions.UserName}");

                    while (_clusterOptions.GlobalNodes.TryTake(out IClusterNode clusterNode))
                    {
                        clusterNode.Dispose();
                    }

                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public void GetEndPoint_Valid_ExpectedResult(string server, bool preferIpv6, IPEndPoint expectedResult)
        {
            // Act

            var result = IpEndPointExtensions.GetEndPoint(server, preferIpv6);

            // Assert

            Assert.Equal(expectedResult, result);
        }
        /// <summary>
        /// Gets the <see cref="T:System.Net.IPEndPoint" /> for the KV port for this node.
        /// </summary>
        /// <param name="port">The port for the <see cref="T:System.Net.IPEndPoint" /></param>
        /// <returns>
        /// An <see cref="T:System.Net.IPEndPoint" /> with the port passed in.
        /// </returns>
        public IPEndPoint GetIpEndPoint(int port)
        {
            var key = Hostname + ":" + port;

            if (!_cachedEndPoints.TryGetValue(key, out var endPoint))
            {
                endPoint = IpEndPointExtensions.GetEndPoint(Hostname, port);
                IsIPv6   = endPoint.AddressFamily == AddressFamily.InterNetworkV6;
                _cachedEndPoints.TryAdd(key, endPoint);
            }
            return(endPoint);
        }
Ejemplo n.º 4
0
 // ReSharper disable once InconsistentNaming
 private void EnsureIPEndPointsAreLoaded()
 {
     lock (_syncObj)
     {
         if (_ipEndPoints == null || !_ipEndPoints.Any())
         {
             _ipEndPoints = new List <IPEndPoint>();
             foreach (var server in ServerList)
             {
                 _ipEndPoints.Add(IpEndPointExtensions.GetEndPoint(server));
             }
         }
     }
 }
Ejemplo n.º 5
0
        public void When_Replica_Index_Postive_LocatePrimary_Returns_It()
        {
            var vbucket =
                new VBucket(new List <IPEndPoint>
            {
                IpEndPointExtensions.GetEndPoint("127.0.0.1:10210"),
                IpEndPointExtensions.GetEndPoint("127.0.0.2:10210")
            },
                            100, -1, new short[] { 0 }, 0, new VBucketServerMap {
                ServerList = new[] { "127.0.0.1:10210", "127.0.0.2:10210" }
            }, "default");
            var found = vbucket.LocatePrimary();

            Assert.NotNull(found);
        }
Ejemplo n.º 6
0
        public void When_Replica_Index_Negative_LocatePrimary_Returns_Random_Server()
        {
            var vbucket =
                new VBucket(new List <IPEndPoint>
            {
                IpEndPointExtensions.GetEndPoint("127.0.0.1:10210"),
                IpEndPointExtensions.GetEndPoint("127.0.0.2:10210")
            },
                            100, -1, new short[] { -1 }, 0, new VBucketServerMap {
                ServerList = new[] { "127.0.0.1:10210" }
            }, "default",
                            new Mock <ILogger <VBucket> >().Object);
            var found = vbucket.LocatePrimary();

            Assert.NotNull(found);
        }
        // ReSharper disable once InconsistentNaming
        private void EnsureIPEndPointsAreLoaded()
        {
            const string hostPlaceHolder = "$HOST";

            lock (_syncObj)
            {
                if (_ipEndPoints == null || !_ipEndPoints.Any())
                {
                    foreach (var server in ServerList)
                    {
                        if (!server.Contains(hostPlaceHolder))
                        {
                            //create list only if valid endpoint exists, otherwise wwe will build once $HOST is resolved
                            if (_ipEndPoints == null)
                            {
                                _ipEndPoints = new List <IPEndPoint>();
                            }
                            _ipEndPoints.Add(IpEndPointExtensions.GetEndPoint(server));
                        }
                    }
                }
            }
        }