Skip to content

Commit

Permalink
feat(jans-orm): add CB cluster option waitUntilReady support #9570 (#…
Browse files Browse the repository at this point in the history
…9571)

* feat(jans-orm): add CB cluster option waitUntilReady support

Signed-off-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>

* feat(jans-orm): add CB cluster option waitUntilReady support

Signed-off-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>

---------

Signed-off-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>
  • Loading branch information
yurem authored Sep 24, 2024
1 parent 8dcb12b commit 779582f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
servers: %(couchbase_query_node)s

# Waits specified number of seconds until SDK bootstrap is complete and the desired ClusterState is observed
# Default waitUntilReady is -1 which means that it's turned off
connection.wait-until-ready-time: -1

# The connect timeout is used when a Bucket is opened.
# If you feel the urge to change this value to something higher, there is a good chance that your network is not properly set up.
# Connecting to the server should in practice not take longer than a second on a reasonably fast network.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package io.jans.orm.couchbase.operation.impl;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -137,7 +138,9 @@ protected void init() {
}

private void openWithWaitImpl() {
String connectionMaxWaitTime = props.getProperty("connection.connection-max-wait-time");
int waitUntilReadyTimeSeconds = StringHelper.toInteger(props.getProperty("connection.wait-until-ready-time"), -1);

String connectionMaxWaitTime = props.getProperty("connection.connection-max-wait-time");
int connectionMaxWaitTimeSeconds = 30;
if (StringHelper.isNotEmpty(connectionMaxWaitTime)) {
connectionMaxWaitTimeSeconds = Integer.parseInt(connectionMaxWaitTime);
Expand All @@ -156,7 +159,7 @@ private void openWithWaitImpl() {
}

try {
open();
open(waitUntilReadyTimeSeconds);
if (isConnected()) {
break;
} else {
Expand All @@ -182,7 +185,7 @@ private void openWithWaitImpl() {
}
}

private void open() {
private void open(int waitUntilReadyTimeSeconds) {
this.bucketToBaseNameMapping = new HashMap<String, BucketMapping>();
this.baseNameToBucketMapping = new HashMap<String, BucketMapping>();

Expand All @@ -193,12 +196,21 @@ private void open() {

this.cluster = Cluster.connect(connectionString, clusterOptions);

if (waitUntilReadyTimeSeconds > 0) {
LOG.info("Uwe waitUntilReady cluster SDK option: '{}'", waitUntilReadyTimeSeconds);
this.cluster.waitUntilReady(Duration.ofSeconds(waitUntilReadyTimeSeconds));
}

// Open required buckets
for (String bucketName : buckets) {
String baseNamesProp = props.getProperty(String.format("bucket.%s.mapping", bucketName), "");
String[] baseNames = StringHelper.split(baseNamesProp, ",");

Bucket bucket = this.cluster.bucket(bucketName);
if (waitUntilReadyTimeSeconds > 0) {
LOG.info("Uwe waitUntilReady bucket SDK option: '{}'", waitUntilReadyTimeSeconds);
bucket.waitUntilReady(Duration.ofSeconds(waitUntilReadyTimeSeconds));
}

BucketMapping bucketMapping = new BucketMapping(bucketName, bucket);

Expand Down

0 comments on commit 779582f

Please sign in to comment.