public async Task ProcessClusterMapAsync(IBucket bucket, BucketConfig config)
        {
            foreach (var nodeAdapter in config.GetNodes())
            {
                var endPoint = nodeAdapter.GetIpEndPoint(ClusterOptions.UseSsl);
                if (TryGetNode(endPoint, out IClusterNode bootstrapNode))
                {
                    await bootstrapNode.SelectBucket(bucket.Name);

                    bootstrapNode.NodesAdapter = nodeAdapter;
                    bootstrapNode.BuildServiceUris();
                    continue; //bootstrap node is skipped because it already went through these steps
                }

                var node = await ClusterNode.CreateAsync(this, endPoint);

                await node.SelectBucket(bucket.Name);

                node.NodesAdapter = nodeAdapter;
                node.BuildServiceUris();
                AddNode(node);
            }
            PruneNodes(config);
        }
Example #2
0
        public async Task InitializeAsync()
        {
            // DNS-SRV
            if (ClusterOptions.IsValidDnsSrv())
            {
                try
                {
                    var bootstrapUri = ClusterOptions.ConnectionStringValue.GetDnsBootStrapUri();
                    var servers      = await ClusterOptions.DnsResolver.GetDnsSrvEntriesAsync(bootstrapUri);

                    if (servers.Any())
                    {
                        Log.LogInformation($"Successfully retrieved DNS SRV entries: [{string.Join(",", servers)}]");
                        ClusterOptions.Servers(servers);
                    }
                }
                catch (Exception exception)
                {
                    Log.LogInformation(exception, "Error trying to retrieve DNS SRV entries.");
                }
            }

            foreach (var server in ClusterOptions.ServersValue)
            {
                var bsEndpoint = server.GetIpEndPoint(ClusterOptions.KvPort, ClusterOptions.EnableIPV6Addressing);
                var node       = await ClusterNode.CreateAsync(this, bsEndpoint);

                node.BootstrapUri = server;
                GlobalConfig      = await node.GetClusterMap();

                if (GlobalConfig == null) //TODO NCBC-1966 xerror info is being hidden, so on failure this will not be null
                {
                    AddNode(node);        //GCCCP is not supported - pre-6.5 server fall back to CCCP like SDK 2
                }
                else
                {
                    GlobalConfig.IsGlobal = true;
                    foreach (var nodeAdapter in GlobalConfig.GetNodes()) //Initialize cluster nodes for global services
                    {
                        if (server.Host.Equals(nodeAdapter.Hostname))    //this is the bootstrap node so update
                        {
                            node.BootstrapUri = server;
                            node.NodesAdapter = nodeAdapter;
                            node.BuildServiceUris();
                            SupportsCollections = node.Supports(ServerFeatures.Collections);
                            AddNode(node);
                        }
                        else
                        {
                            var endpoint = nodeAdapter.GetIpEndPoint(ClusterOptions.EnableTls);
                            if (endpoint.Port == 0)
                            {
                                endpoint.Port = 11210;
                            }
                            var newNode = await ClusterNode.CreateAsync(this, endpoint);

                            newNode.BootstrapUri = server;
                            newNode.NodesAdapter = nodeAdapter;
                            newNode.BuildServiceUris();
                            SupportsCollections = node.Supports(ServerFeatures.Collections);
                            AddNode(newNode);
                        }
                    }
                }
            }
        }