public void RegisterBucket(BucketBase bucket) { if (Buckets.TryAdd(bucket.Name, bucket)) { _configHandler.Subscribe(bucket); } }
public void UnRegisterBucket(BucketBase bucket) { if (Buckets.TryRemove(bucket.Name, out var removedBucket)) { _configHandler.Unsubscribe(bucket); removedBucket.Dispose(); } }
public async Task ProcessClusterMapAsync(BucketBase bucket, BucketConfig config) { var ipEndPointService = ServiceProvider.GetRequiredService <IIpEndPointService>(); foreach (var nodeAdapter in config.GetNodes()) { var endPoint = await ipEndPointService.GetIpEndPointAsync(nodeAdapter, CancellationToken).ConfigureAwait(false); if (Nodes.TryGet(endPoint, out var bootstrapNode)) { if (bootstrapNode.Owner == null) { _logger.LogDebug( "Using existing node {endPoint} for bucket {bucket.Name} using rev#{config.Rev}", _redactor.SystemData(endPoint), _redactor.MetaData(bucket.Name), config.Rev); if (bootstrapNode.HasKv) { await bootstrapNode.SelectBucketAsync(bucket, CancellationToken).ConfigureAwait(false); } bootstrapNode.NodesAdapter = nodeAdapter; SupportsCollections = bootstrapNode.Supports(ServerFeatures.Collections); bucket.Nodes.Add(bootstrapNode); continue; } } if (bucket.Nodes.TryGet(endPoint, out var bucketNode)) { continue; } _logger.LogDebug("Creating node {endPoint} for bucket {bucket.Name} using rev#{config.Rev}", _redactor.SystemData(endPoint), _redactor.MetaData(bucket.Name), config.Rev); var node = await _clusterNodeFactory.CreateAndConnectAsync( // We want the BootstrapEndpoint to use the host name, not just the IP new HostEndpoint(nodeAdapter.Hostname, endPoint.Port), CancellationToken).ConfigureAwait(false); node.NodesAdapter = nodeAdapter; if (node.HasKv) { await node.SelectBucketAsync(bucket, CancellationToken).ConfigureAwait(false); } SupportsCollections = node.Supports(ServerFeatures.Collections); AddNode(node); bucket.Nodes.Add(node);//may remove } await PruneNodesAsync(config).ConfigureAwait(false); }
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(BucketBase bucket, BucketConfig config) { var ipEndPointService = ServiceProvider.GetRequiredService <IIpEndPointService>(); foreach (var nodeAdapter in config.GetNodes()) { //log any alternate address mapping _logger.LogInformation(nodeAdapter.ToString()); var endPoint = await ipEndPointService.GetIpEndPointAsync(nodeAdapter, CancellationToken).ConfigureAwait(false); if (Nodes.TryGet(endPoint, out var bootstrapNode)) { if (bootstrapNode.Owner == null && bucket.BucketType != BucketType.Memcached) { _logger.LogDebug( "Using existing node {endPoint} for bucket {bucket.Name} using rev#{config.Rev}", _redactor.SystemData(endPoint), _redactor.MetaData(bucket.Name), config.Rev); if (bootstrapNode.HasKv) { await bootstrapNode.SelectBucketAsync(bucket, CancellationToken).ConfigureAwait(false); SupportsCollections = bootstrapNode.Supports(ServerFeatures.Collections); } bootstrapNode.Owner = bucket; bootstrapNode.NodesAdapter = nodeAdapter; bucket.Nodes.Add(bootstrapNode); continue; } if (bootstrapNode.Owner != null && bootstrapNode.BucketType == BucketType.Memcached) { _logger.LogDebug("Adding memcached node for endpoint {endpoint} using rev#{revision} for bucket {bucketName}.", _redactor.SystemData(endPoint), config.Rev, _redactor.MetaData(config.Name)); bootstrapNode.NodesAdapter = nodeAdapter; bucket.Nodes.Add(bootstrapNode); continue; } } //If the node already exists for the endpoint, ignore it. if (bucket.Nodes.TryGet(endPoint, out var bucketNode)) { _logger.LogDebug("The node already exists for the endpoint {endpoint} using rev#{revision} for bucket {bucketName}.", _redactor.SystemData(endPoint), config.Rev, _redactor.MetaData(config.Name)); bucketNode.NodesAdapter = nodeAdapter; continue; } _logger.LogDebug("Creating node {endPoint} for bucket {bucketName} using rev#{revision}", _redactor.SystemData(endPoint), _redactor.MetaData(bucket.Name), config.Rev); var bucketType = config.NodeLocator == "ketama" ? BucketType.Memcached : BucketType.Couchbase; var node = await _clusterNodeFactory.CreateAndConnectAsync( // We want the BootstrapEndpoint to use the host name, not just the IP new HostEndpoint(nodeAdapter.Hostname, endPoint.Port), bucketType, nodeAdapter, CancellationToken).ConfigureAwait(false); if (node.HasKv) { await node.SelectBucketAsync(bucket, CancellationToken).ConfigureAwait(false); SupportsCollections = node.Supports(ServerFeatures.Collections); } AddNode(node); bucket.Nodes.Add(node);//may remove } await PruneNodesAsync(config).ConfigureAwait(false); }