Ejemplo n.º 1
0
        public BucketTest()
        {
            Log.TruncateBinaryTypes = true;

            fileTable = R.Db(DbName).Table("fs_files");
            chunkTable = R.Db(DbName).Table("fs_chunk");
            db = R.Db(DbName);
            var opts = new BucketConfig();
            chunkIndex = opts.ChunkIndex;
            fileIndexPath = opts.FileIndex;
            fileTableName = "fs_files";
            chunkTableName = "fs_chunks";
        }
 public void PublishConfig(BucketConfig bucketConfig)
 {
     _configHandler.Publish(bucketConfig);
 }
        /// <summary>
        /// Loads the current configuration setting the internal state of this configuration context.
        /// </summary>
        /// <param name="bucketConfig"></param>
        /// <param name="force">True to force a reconfiguration.</param>
        /// <exception cref="CouchbaseBootstrapException">Condition.</exception>
        public override void LoadConfig(IBucketConfig bucketConfig, bool force = false)
        {
            if (bucketConfig == null)
            {
                throw new ArgumentNullException(nameof(bucketConfig));
            }

            var nodes = bucketConfig.GetNodes();

            if (BucketConfig == null || !nodes.AreEqual(BucketConfig.GetNodes()) || force)
            {
                var clientBucketConfig = ClientConfig.BucketConfigs[bucketConfig.Name];
                var servers            = new Dictionary <IPEndPoint, IServer>();

                Log.Info("o1-Creating the Servers {0} list using rev#{1}", nodes.Count, bucketConfig.Rev);
                foreach (var adapter in nodes)
                {
                    var endpoint = adapter.GetIPEndPoint(clientBucketConfig.UseSsl);
                    try
                    {
                        if (adapter.IsDataNode) //a data node so create a connection pool
                        {
                            if (Servers.TryGetValue(endpoint, out IServer cachedServer))
                            {
                                //The services list may have changed even though the
                                //connections can be reused so use the latest settings
                                cachedServer.LoadNodeAdapter(adapter);

                                servers.Add(endpoint, cachedServer);
                            }
                            else
                            {
                                var uri       = UrlUtil.GetBaseUri(adapter, clientBucketConfig);
                                var ioService = CreateIOService(clientBucketConfig.ClonePoolConfiguration(uri),
                                                                endpoint);
                                var server = new Core.Server(ioService, adapter, Transcoder, this);
                                servers.Add(endpoint, server);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("Could not add server {0}. Exception: {1}", endpoint, e);
                    }
                }

                //If servers is empty that means we could not initialize _any_ nodes
                //We fail-fast here so that the problem can be indentified and handled.
                if (!servers.Any())
                {
                    throw new CouchbaseBootstrapException(ExceptionUtil.BootStrapFailedMsg);
                }

                var newDataNodes = servers
                                   .Where(x => x.Value.IsDataNode)
                                   .Select(x => x.Value)
                                   .ToList();

                Interlocked.Exchange(ref DataNodes, newDataNodes);
                IsDataCapable = newDataNodes.Count > 0;

                SwapServers(servers);
            }
            Interlocked.Exchange(ref KeyMapper, new KetamaKeyMapper(Servers));
            Interlocked.Exchange(ref _bucketConfig, bucketConfig);
        }
Ejemplo n.º 4
0
        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.ServerFeatures.Collections;
                            SupportsPreserveTtl = bootstrapNode.ServerFeatures.PreserveTtl;
                        }

                        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.ServerFeatures.Collections;
                    SupportsPreserveTtl = node.ServerFeatures.PreserveTtl;
                }

                AddNode(node);
                bucket.Nodes.Add(node);//may remove
            }

            await PruneNodesAsync(config).ConfigureAwait(false);
        }
Ejemplo n.º 5
0
 public void PublishConfig(BucketConfig bucketConfig)
 {
     _logger.LogDebug(LoggingEvents.ConfigEvent, JsonConvert.SerializeObject(bucketConfig));
     _configHandler.Publish(bucketConfig);
 }
Ejemplo n.º 6
0
 public override Task ConfigUpdatedAsync(BucketConfig config)
 {
     throw new NotImplementedException();
 }
        internal static CouchbaseConfigContext GetCouchbaseContext(ClientConfiguration clientConfig)
        {
            var bucketConfig = new BucketConfig();

            return(GetCouchbaseContext(clientConfig, bucketConfig));
        }
Ejemplo n.º 8
0
        internal static async Task <IPingReport> CreatePingReportAsync(ClusterContext context, BucketConfig config, PingOptions options)
        {
            var clusterNodes = context.GetNodes(config.Name);
            var endpoints    =
                await GetEndpointDiagnosticsAsync(context, clusterNodes, true, options.ServiceTypesValue,
                                                  options.Token).ConfigureAwait(false);

            return(new PingReport(options.ReportIdValue ?? Guid.NewGuid().ToString(), config.Rev, endpoints));
        }