A cluster can not open multiple buckets in Java SDK 2.0


#1

I’ve followed the Java SDK 2.0 documentation at http://docs.couchbase.com/developer/java-2.0/managing-connections.html. It says it’s possible to open more than one bucket at the same time with a Cluster. But, when I tried the following code snippet, java.util.ConcurrentModificationException is thrown.

Bucket bucket1 = cluster.openBucket(“bucket1”, “password”);
Bucket bucket2 = cluster.openBucket(“bucket2”, “password”);

I had to create a cluster per a bucket and share the CouchbaseEnvironment among the cluster instances to open multiple buckets. It will be helpful if someone can verify whether the documentation has typos or the SDK has a bug.


#2

I’ve just tried this example, and it works

public class Hello {
    public static void main(String[] args) {
        Cluster cluster = CouchbaseCluster.create();
        Bucket bucket1 = cluster.openBucket("bucket1", "password");
        Bucket bucket2 = cluster.openBucket("bucket2", "password");
        bucket1.upsert(JsonDocument.create("foo", JsonObject.create().put("foo", "bar")));
        bucket2.upsert(JsonDocument.create("bar", JsonObject.create().put("foo", "bar")));
    }
}

#3

Hi,

you’ve probably hit a bug. Can you share your logs here (exceptions,…) and/or open a ticket here? http://www.couchbase.com/issues/browse/JCBC This is expected to work. Thanks!


#4

Thank you for the quick response. I think the exception is thrown when cluster.disconnect() is called with open buckets.

The following code runs flawlessly:

public static void main(String[] args) {
    Cluster cluster = CouchbaseCluster.create();
    Bucket bucket1 = cluster.openBucket("default");
    Bucket bucket2 = cluster.openBucket("beer-sample");
    bucket1.close();
    bucket2.close();
    cluster.disconnect();
}

The following code throws the exception:

public static void main(String[] args) {
    Cluster cluster = CouchbaseCluster.create();
    Bucket bucket1 = cluster.openBucket("default");
    Bucket bucket2 = cluster.openBucket("beer-sample");
    cluster.disconnect();
}

Here is the log when the exception is thrown.

OS: Mac OS X 10.9.5
JVM: 1.8.0_0

[error] (run-main-6) java.util.ConcurrentModificationException
java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429)
	at java.util.HashMap$KeyIterator.next(HashMap.java:1453)
	at rx.internal.operators.OnSubscribeFromIterable$IterableProducer.request(OnSubscribeFromIterable.java:96)
	at rx.internal.operators.OperatorSubscribeOn$1$1$1$1.request(OperatorSubscribeOn.java:88)
	at rx.Subscriber.setProducer(Subscriber.java:143)
	at rx.Subscriber.setProducer(Subscriber.java:137)
	at rx.internal.operators.OperatorSubscribeOn$1$1$1.setProducer(OperatorSubscribeOn.java:81)
	at rx.internal.operators.OnSubscribeFromIterable.call(OnSubscribeFromIterable.java:47)
	at rx.internal.operators.OnSubscribeFromIterable.call(OnSubscribeFromIterable.java:33)
	at rx.Observable.unsafeSubscribe(Observable.java:7658)
	at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:62)
	at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:43)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
[debug] 	Thread run-main-6 exited.
[debug] Interrupting remaining threads (should be all daemons).
[debug] Interrupting thread cb-io-1-5
[debug] 	Interrupted cb-io-1-5
[debug] Interrupting thread RxComputationThreadPool-7
[debug] 	Interrupted RxComputationThreadPool-7
[debug] Interrupting thread cb-computations-8
[debug] 	Interrupted cb-computations-8
[debug] Interrupting thread RxComputationThreadPool-1
[debug] 	Interrupted RxComputationThreadPool-1
[debug] Interrupting thread RxComputationThreadPool-2
[debug] 	Interrupted RxComputationThreadPool-2
[debug] Interrupting thread cb-io-1-1
[debug] 	Interrupted cb-io-1-1
[debug] Interrupting thread cb-core-3-1
[debug] 	Interrupted cb-core-3-1
[debug] Interrupting thread cb-io-1-4
[debug] 	Interrupted cb-io-1-4
[debug] Interrupting thread RxComputationThreadPool-5
[debug] 	Interrupted RxComputationThreadPool-5
[debug] Interrupting thread cb-computations-3
[debug] 	Interrupted cb-computations-3
[debug] Interrupting thread RxComputationThreadPool-4
[debug] 	Interrupted RxComputationThreadPool-4
[debug] Interrupting thread RxComputationThreadPool-8
[debug] 	Interrupted RxComputationThreadPool-8
[debug] Interrupting thread cb-computations-1
[debug] 	Interrupted cb-computations-1
[debug] Interrupting thread RxComputationThreadPool-3
[debug] 	Interrupted RxComputationThreadPool-3
[debug] Interrupting thread cb-computations-2
[debug] 	Interrupted cb-computations-2
[debug] Interrupting thread cb-io-1-6
[debug] 	Interrupted cb-io-1-6
[debug] Interrupting thread cb-computations-7
[debug] 	Interrupted cb-computations-7
[debug] Interrupting thread cb-io-1-3
[debug] 	Interrupted cb-io-1-3
[debug] Interrupting thread cb-computations-5
[debug] 	Interrupted cb-computations-5
[debug] Interrupting thread cb-io-1-2
[debug] 	Interrupted cb-io-1-2
[debug] Interrupting thread threadDeathWatcher-4-1
[debug] 	Interrupted threadDeathWatcher-4-1
[debug] Interrupting thread RxComputationThreadPool-6
[debug] 	Interrupted RxComputationThreadPool-6
[debug] Interrupting thread cb-computations-4
[debug] 	Interrupted cb-computations-4
[debug] Interrupting thread cb-core-3-2
[debug] 	Interrupted cb-core-3-2
[debug] Interrupting thread cb-io-1-8
[debug] 	Interrupted cb-io-1-8
[debug] Interrupting thread cb-io-1-7
[debug] 	Interrupted cb-io-1-7
[debug] Interrupting thread cb-computations-6
[debug] 	Interrupted cb-computations-6
[debug] Sandboxed run complete..
[error] (cb-core-3-2) java.lang.RuntimeException: java.lang.InterruptedException
java.lang.RuntimeException: java.lang.InterruptedException
	at com.couchbase.client.deps.com.lmax.disruptor.FatalExceptionHandler.handleEventException(FatalExceptionHandler.java:45)
	at com.couchbase.client.deps.com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:147)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InterruptedException
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2048)
	at com.couchbase.client.deps.com.lmax.disruptor.BlockingWaitStrategy.waitFor(BlockingWaitStrategy.java:45)
	at com.couchbase.client.deps.com.lmax.disruptor.ProcessingSequenceBarrier.waitFor(ProcessingSequenceBarrier.java:55)
	at com.couchbase.client.deps.com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:123)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
	at java.lang.Thread.run(Thread.java:745)
java.lang.RuntimeException: Nonzero exit code: 1
	at scala.sys.package$.error(package.scala:27)
	at sbt.BuildCommon$$anonfun$toError$1.apply(Defaults.scala:1708)
	at sbt.BuildCommon$$anonfun$toError$1.apply(Defaults.scala:1708)
	at scala.Option.foreach(Option.scala:236)
	at sbt.BuildCommon$class.toError(Defaults.scala:1708)
	at sbt.Defaults$.toError(Defaults.scala:35)
	at sbt.Defaults$$anonfun$runTask$1$$anonfun$apply$36$$anonfun$apply$37.apply(Defaults.scala:688)
	at sbt.Defaults$$anonfun$runTask$1$$anonfun$apply$36$$anonfun$apply$37.apply(Defaults.scala:686)
	at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
	at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
	at sbt.std.Transform$$anon$4.work(System.scala:64)
	at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
	at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
	at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
	at sbt.Execute.work(Execute.scala:244)
	at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
	at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
	at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
[error] (compile:run) Nonzero exit code: 1

#5

Thanks! And to get more context:

  • Does it happen all the time?
  • Do you have any code after the two bucket openings (can you share the full code?)

#6

I just updated the previous post with new findings. Thank you again.


#7

Thank you, I guess I could reproduce it as well. If you want to follow the ticket -> http://www.couchbase.com/issues/browse/JVMCBC-43


#8

Can you try this 2.0.1-pre version and see if it works for you?

https://dl.dropboxusercontent.com/u/10007675/Couchbase-Java-Client-2.0.1-SNAPSHOT-b0921ce.zip


#9

It works. The multiple buckets are closed without problems now.
Thank you very much.


#10

Great that it works for you! Please don’t forget to upgrade once we ship 2.0.1