Java SDK to protect against Internal Couchbase Errors

Due to a possible bug in Couchbase 7.0.1 CE and both EE [1], we experience frequent crashes of the indexing service, which yields the following errors in the Java SDK after the indexer & query service crashes.

Internal Couchbase Server error
         "message":" dial tcp connect: connection refused from [] - cause:  dial tcp connect: connection refused from []"
      "statement":"SELECT b.* FROM `bucket`.`default`.`sescus-A_e` b WHERE clientID = $byField",

The query is executed as follows:

val f = $.cluster.query(
          s"SELECT b.* FROM ${$.scalaEntityCollection.from} b " +
            "WHERE " + name + " = $byField",
                "byField" -> value

We set the SELECT query to be idempotent, however, the SDK will not attempt any retries, possibly, because the type of error is not eligible for retry by the SDK. Therefore, we retry outside of the SDK as suggested by the SDK documentation. Below is an experimental implementation of the blocking retry mechanism:

protected[storage] def withComplementaryRetry[R](
    f: => R
  )(implicit couchbaseConfiguration: Couchbase.Configuration): R = {
    val querySuccess = new retry.Success[R](_.isInstanceOf[R])
      )(odelay.Timer.default, retry.Jitter.full(cap = 3.seconds)) {
        val future = Future(f)(Couchbase.complementaryRetryingThreadPool)
        future.onComplete {
          case Failure(exception) =>
              "Could not complete query successfully due to error [{}] with message [{}]!",
          case Success(_) => ()
      }(querySuccess, Couchbase.complementaryRetryingThreadPool),

When the above Internal Couchbase Server error is observed, the query by the withComplementaryRetry will be retried (because the SDK refuses to do so). However, even after Couchbase recovers from the indexer crash quickly, the SDK does not recover from Internal Couchbase Server error, even after 300 seconds. While the 300 seconds are ticking down and the withComplementaryRetry attempts, again and again, a new SDK instance constructed during the retrying can complete queries successfully, I think the SDK can not recover from these Internal Couchbase Server errors.

The above question is relevant because Couchbase 7.0.1 CE and EE have an issue with the indexing service [1], and protecting against these cases is now relevant.

Is there any way to force the SDK programmatically to recover from these errors for idempotent queries?

[1] Couchbase 7 release date - #29 by yogendra.acharya

Hi @zoltan.zvara
I’ve not got a concrete reply at this point, but just wanted to let you know that I’ve raised this internally for discussion. The initial thought is that since you’ve set the readonly flag then this should indeed be retried, but please don’t take that as definitive until we’ve had a chance to look further.

1 Like