Possible threading issue?

I’ve been using the couchbase api 2.1.4 library and been running into an issue related to incorrect data.
In the code, I’m using the non-blocking pattern (rxJava) + Twitter Future.

  • Fetch a set of data for a set of keys
    -subscribe to the results and once completed set the twitter promise.
    -Compare the request keys and the result keys and the keys are different. The result appears to be from a different request.

For every ~150k queries, we find one request would hit the scenario above and so it’s very rare.
Any suggestions or help would be great.

A few data points:
-The bucket is shared between all threads
-The env and cluster was created once
-Couchbase Server 3.0.1

hi @chanoo
can you share your async code? (all three steps)

hi @simonbasle

code to fetch data and subscribe:

  private def batchGet(ids: Iterable[String], keySpace: String): Future[Seq[JsonDocument]] = {
    val promise = new Promise[Seq[JsonDocument]]()
    val errorLogs = {
      .flatMap(new Func1[String, Observable[JsonDocument]]() {
      override def call(id: String): Observable[JsonDocument] = {
      .subscribe(new Action1[java.util.List[JsonDocument]] {
      override def call(t1: java.util.List[JsonDocument]): Unit = {
    }, errorAction(promise, Seq.empty, keySpace, BATCHGET_STAT_TYPE, errorLogs), completeAction(promise, errorLogs))

Calling method:

batchGet(keyMapping.keys, keySpace).map { seq =>
        seq.map { jsonDoc =>
          (keyMapping.get(jsonDoc.id()).getOrElse {
            val msg = "missing key: " + jsonDoc.id() + ". available keys: " + keyMapping.keySet
            logger.warning(msg)       //We're find examples where the keys doesn't match the request in the log
            throw new CacheResultMisMatchException(msg)
          } ->
            (parseDoc(jsonDoc), jsonDoc))

All our data types are immutable other than the twitter promise. The keyMapping.keys are used to fetch the items from Couchbase but we found results from Couchbase where the id wasn’t in the set of keys that was requested. In the logs, it clearly shows it is unrelated (and not a mismatch in casing or spacing).


I see, nothing stands out of the scala code…
could you raise a bug in the Couchbase Jira with this code sample and the rough frequency at which you observed mismatches, so that we can track and investigate?

created. thanks!