Beispiel #1
0
 public async Task <IPingReport> PingAsync(PingOptions?options = null)
 {
     ThrowIfBootStrapFailed();
     options ??= new PingOptions();
     return(await DiagnosticsReportProvider.CreatePingReportAsync(Context, BucketConfig, options)
            .ConfigureAwait(false));
 }
Beispiel #2
0
        public async Task <IPingReport> PingAsync(PingOptions?options = null)
        {
            options ??= new PingOptions();

            return(await DiagnosticsReportProvider.
                   CreatePingReportAsync(_context, _context.GlobalConfig, options).
                   ConfigureAwait(false));
        }
Beispiel #3
0
        public async Task WaitUntilReadyAsync(TimeSpan timeout, WaitUntilReadyOptions?options = null)
        {
            if (!_context.IsGlobal)
            {
                throw new NotSupportedException(
                          "Cluster level WaitUntilReady is only supported by Couchbase Server 6.5 or greater. " +
                          "If you think this exception is caused by another error, please check your SDK logs for detail.");
            }

            options ??= new WaitUntilReadyOptions();
            if (options.DesiredStateValue == ClusterState.Offline)
            {
                throw new ArgumentException(nameof(options.DesiredStateValue));
            }

            var token = options.CancellationTokenValue;
            CancellationTokenSource?tokenSource = null;

            if (token == CancellationToken.None)
            {
                tokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
                tokenSource.CancelAfter(timeout);
                token = tokenSource.Token;
            }

            try
            {
                token.ThrowIfCancellationRequested();
                while (!token.IsCancellationRequested)
                {
                    var pingReport =
                        await DiagnosticsReportProvider.CreatePingReportAsync(_context, _context.GlobalConfig,
                                                                              new PingOptions
                    {
                        ServiceTypesValue = options.ServiceTypesValue
                    }).ConfigureAwait(false);

                    var status = new Dictionary <string, bool>();
                    foreach (var service in pingReport.Services)
                    {
                        var failures = service.Value.Any(x => x.State != ServiceState.Ok);
                        if (failures)
                        {
                            //mark a service as failed
                            status.Add(service.Key, failures);
                        }
                    }

                    //everything is up
                    if (status.Count == 0)
                    {
                        _clusterState = ClusterState.Online;
                        return;
                    }

                    //determine if completely offline or degraded
                    _clusterState = status.Count == pingReport.Services.Count ? ClusterState.Offline : ClusterState.Degraded;
                    if (_clusterState == options.DesiredStateValue)
                    {
                        return;
                    }

                    await Task.Delay(100, token).ConfigureAwait(false);
                }
            }
            catch (OperationCanceledException e)
            {
                throw new UnambiguousTimeoutException($"Timed out after {timeout}.", e);
            }
            catch (Exception e)
            {
                throw new CouchbaseException("An error has occurred, see the inner exception for details.", e);
            }
            finally
            {
                tokenSource?.Dispose();
            }
        }