Getting continuous warning for bucket is not present when used bucket.waitUntilReady();

In my application I am initializing the all buckets on application startup as in below code

        List<String> bucketList = Arrays.asList("Bucket1", "Bucket2", "Bucket3");
        long totalTime = 0L;
        for (String bucketName : bucketList) {
            try {
                long startTime = System.currentTimeMillis();
                bucket = cluster.bucket(bucketName);
                // get a collection reference
                Collection collection = bucket.defaultCollection();
                bucket.waitUntilReady(Duration.ofSeconds(10));
                collectionMap.put(bucketName, collection);
                long timeTaken = System.currentTimeMillis() - startTime;
                totalTime += timeTaken;
                System.out.println("## Time taken to initialized the bucket:" + bucketName + " = " + timeTaken);
            } catch (Exception e) {
                System.out.println(">>>>>>>>>>>Exception in initialization : " + e);
            }
        }

Here bucket.waitUntilReady is causing the issue when any bucket not present in Couchbase server from list

i.e in above code if ‘Bucket2’ is not present then it throw the exception com.couchbase.client.core.error.UnambiguousTimeoutException: WaitUntilReady timed out for Bucket2

Due to Bucket2 does not exist in Couchbase, in next iteration of loop when try to initialized Bucket3(which available) also throw com.couchbase.client.core.error.UnambiguousTimeoutException: WaitUntilReady timed out even bucket is available due to bucket.waitUntilReady.

It keep attempting to connect to Bucket2 continuous even after timeout in bucket.waitUntilReady(Duration.ofSeconds(10)); as below

WARNING: [com.couchbase.endpoint][EndpointConnectionFailedEvent][190ms] Connect attempt 12 failed because of AuthenticationFailureException: Either the bucket with name “Bucket2” is not present or the user does not have the right privileges to access it {“bucket”:“Bucket2”,“circuitBreaker”:“DISABLED”,“coreId”:“0xe38db72200000001”,“remote”:“10.60.32.61:11210”,“status”:“NO_ACCESS”,“type”:“KV”} {“bucket”:“Bucket2”,“circuitBreaker”:“DISABLED”,“coreId”:“0xe38db72200000001”,“remote”:“10.60.32.61:11210”,“type”:“KV”}
com.couchbase.client.core.error.AuthenticationFailureException: Either the bucket with name “Bucket2” is not present or the user does not have the right privileges to access it {“bucket”:“Bucket2”,“circuitBreaker”:“DISABLED”,“coreId”:“0xe38db72200000001”,“remote”:“10.60.32.61:11210”,“status”:“NO_ACCESS”,“type”:“KV”}
at com.couchbase.client.core.io.netty.kv.SelectBucketHandler.channelRead(SelectBucketHandler.java:172)
at com.couchbase.client.core.io.netty.kv.MemcacheProtocolVerificationHandler.channelRead(MemcacheProtocolVerificationHandler.java:85)
at java.lang.Thread.run(Thread.java:748)

Could you please help how to stop attempting in case of bucket is not available on Couchbase server

Hi @hgbalar
bucket.waitUntilReady will wait for the SDK to be able to connect to that bucket, so yes if the bucket does not exist then this call is expected to timeout.

You do not have to use waitUntilReady, you can just return and use the Collection and perform KV operations etc. on it. (Of course, these will timeout if you use the Collection on the non-existent bucket).

Agree timeout expected as configured but my question here is once it time out then also it is attempting to connect the bucket so once it timeout then I don’t want to allow re-attempt the bucket connection as shown in WARNING in my previous post.

I have kept bucket.waitUntilReady to avoid the bucket not ready exception in case of any operation perform before bucket is ready

Hi @hgbalar
Ah, understood. The assumption is that if you ask the SDK to open a bucket then that bucket either exists or will be created later, so there is no way to stop the SDK from continuously trying to connect to the bucket. This does result in a warning because generally the bucket would exist and we want to advise users that something unexpected has happened.

If you want to check if the bucket exists prior to trying to open it, this is possible with

    try {
      cluster.buckets().getBucket("bucketName");
      // app logic here
    }
    catch (BucketNotFoundException err) {
      // app logic here
    }

Hi @graham.pople

Thanks for confirming

Apart from that I have also observed that if Couchbase server is down and request get the data from Couchbase through Java SDK 3.x it will get time out as per timeout time configured however it’s continues retry as I can see multiple log as below

2024-06-19 14:46:17,406 DEBUG [com.couchbase.request] (cb-events) [com.couchbase.request][RequestRetryScheduledEvent][500ms] Request GetRequest retry scheduled per RetryStrategy (Reason: ENDPOINT_NOT_AVAILABLE) {“completed”:false,“coreId”:“0xaefe91b000000001”,“idempotent”:true,“lastDispatchedTo”:“10.60.32.61”,“requestId”:48125,“requestType”:“GetRequest”,“retried”:14,“retryReasons”:[“ENDPOINT_NOT_AVAILABLE”],“service”:{“bucket”:“Bucket1”,“collection”:“_default”,“documentId”:“3#1#1#userCustomConfigDetails”,“opaque”:“0xbc7f”,“scope”:“_default”,“type”:“kv”,“vbucket”:49},“timeoutMs”:5000}

Here I don’t want to retry in case Couchbase server is down.

Could you please guide how we can prevent the retry in get/upsert requests in case of Couchbase server is down

The retries are controlled by the RetryStrategy which can be configured in the ClusterEnvironment. The default is BestEffort (i.e. retry if possible). There is also FailFastRetryStrategy which may be more to your liking.