Exemplo n.º 1
0
        public async Task ProcessClusterMapAsync(IBucket bucket, BucketConfig config)
        {
            foreach (var nodeAdapter in config.GetNodes())
            {
                var endPoint = nodeAdapter.GetIpEndPoint(ClusterOptions.EnableTls);
                if (TryGetNode(endPoint, out IClusterNode bootstrapNode))
                {
                    Log.LogDebug($"Using existing node {endPoint} for bucket {bucket.Name} using rev#{config.Rev}");
                    await bootstrapNode.SelectBucket(bucket.Name);

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

                Log.LogDebug($"Creating node {endPoint} for bucket {bucket.Name} using rev#{config.Rev}");
                var node = await ClusterNode.CreateAsync(this, endPoint);

                node.Owner = bucket;
                await node.SelectBucket(bucket.Name);

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

            PruneNodes(config);
        }
Exemplo n.º 2
0
        public async Task <IBucket> CreateAndBootStrapBucketAsync(string name, Uri uri, BucketType type)
        {
            var node = GetUnassignedNode(uri, ClusterOptions.EnableIPV6Addressing);

            if (node == null)
            {
                var endpoint = uri.GetIpEndPoint(ClusterOptions.KvPort, ClusterOptions.UseInterNetworkV6Addresses);
                node = await ClusterNode.CreateAsync(this, endpoint);

                node.BootstrapUri = uri;
                AddNode(node);
            }

            var bucketFactory = ServiceProvider.GetRequiredService <IBucketFactory>();
            var bucket        = bucketFactory.Create(name, type);

            try
            {
                await bucket.BootstrapAsync(node);

                RegisterBucket(bucket);
            }
            catch (Exception e)
            {
                Log.LogError(e, $"Could not bootstrap bucket {type}/{name}");
                UnRegisterBucket(bucket);
            }
            return(bucket);
        }
        public async Task InitializeAsync()
        {
            // DNS-SRV
            if (ClusterOptions.IsValidDnsSrv())
            {
                try
                {
                    var bootstrapUri = ClusterOptions.ConnectionString.GetDnsBootStrapUri();
                    var servers      = await ClusterOptions.DnsResolver.GetDnsSrvEntriesAsync(bootstrapUri);

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

            foreach (var server in ClusterOptions.Servers)
            {
                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);        //GCCP is not supported - pre-6.5 server fall back to CCCP like SDK 2
                }
                else
                {
                    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();
                            AddNode(node);
                        }
                        else
                        {
                            var endpoint = nodeAdapter.GetIpEndPoint(ClusterOptions.UseSsl);
                            var newNode  = await ClusterNode.CreateAsync(this, endpoint);

                            newNode.BootstrapUri = server;
                            newNode.NodesAdapter = nodeAdapter;
                            newNode.BuildServiceUris();
                            AddNode(newNode);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public async Task <IBucket> BootstrapBucketAsync(string name, Uri uri, BucketType type)
        {
            var node = GetUnassignedNode(uri, ClusterOptions.EnableIPV6Addressing);

            if (node == null)
            {
                var endpoint = uri.GetIpEndPoint(ClusterOptions.KvPort, ClusterOptions.UseInterNetworkV6Addresses);
                node = await ClusterNode.CreateAsync(this, endpoint);

                node.BootstrapUri = uri;
                AddNode(node);
            }

            BucketBase bucket = null;

            switch (type)
            {
            case BucketType.Couchbase:
            case BucketType.Ephemeral:
                bucket = new CouchbaseBucket(name, this);
                break;

            case BucketType.Memcached:
                bucket = new MemcachedBucket(name, this);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            try
            {
                await bucket.BootstrapAsync(node);

                RegisterBucket(bucket);
                return(bucket);
            }
            catch (Exception e)
            {
                Log.LogError(e, @"Could not bootstrap {name}");
                UnRegisterBucket(bucket);
                throw;
            }
        }
        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);
        }