More than 1 Couchbase Environments found

I have 3 couchbase clusters and I create 3 CouchbaseCluster instances for each cluster on cb clients 2.0.2 .
At every starting tomcat, I got WARN message below.

Is there any problems about one more CouchbaseCluster ?

[com.couchbase.client.core.env.CoreEnvironment] - More than 1 Couchbase Environments found (3), this can have severe impact on performance and stability. Reuse environments!

I believe that’s likely safe to ignore. You’re likely seeing it because you have three clusters and the intent of the message is to warn people who might accidentally not be reusing the CouchbaseCluster against the same cluster. I’m sure @daschl or @avsej or @simonbasle can confirm.

We may be able to make that smarter by triggering the warning only if the arguments match or something.

1 Like

No, the warning is correct. The SDK has been designed to share precious resources even across cluster boundaries.

Just create one DefaultCouchbaseEnvironment and pass it to all 3 CouchbaseClusters on creation :slight_smile:

1 Like

@daschl @ingenthr

Wow… Thank you !
I resolved the WARN as your advice. It’s so cool :smile:

<bean id="couchbaseEnvironment" class="com.couchbase.client.java.env.DefaultCouchbaseEnvironment" factory-method="create"/>

<bean id="clusterBlog" class="com.couchbase.client.java.CouchbaseCluster" factory-method="create"
      destroy-method="disconnect">
    <constructor-arg name="environment" ref="couchbaseEnvironment" />
    <constructor-arg name="nodes">
        <list value-type="java.lang.String">
            <value>192.168.10.1</value>
        </list>
    </constructor-arg>
</bean>
<bean id="clusterCafe" class="com.couchbase.client.java.CouchbaseCluster" factory-method="create"
      destroy-method="disconnect">
    <constructor-arg name="environment" ref="couchbaseEnvironment" />
    <constructor-arg name="nodes">
        <list value-type="java.lang.String">
            <value>192.168.10.11</value>
        </list>
    </constructor-arg>
</bean>
<bean id="clusterHam" class="com.couchbase.client.java.CouchbaseCluster" factory-method="create"
      destroy-method="disconnect">
    <constructor-arg name="environment" ref="couchbaseEnvironment" />
    <constructor-arg name="nodes">
        <list value-type="java.lang.String">
            <value>192.168.10.21</value>
        </list>
    </constructor-arg>
</bean>
2 Likes

Great that it works for you!

1 Like

Oh and btw, you can read more about it in the docs under “Sharing Resources” https://developer.couchbase.com/documentation/server/3.x/developer/java-2.0/managing-connections.html

1 Like

@Sam_K @daschl @ingenthr
Hey i have a doubt. I am getting error while defining bean in the same way you created. It is not able to resolve “couchbaseEnvironment” while creating bean.
any help ??

are you sure you got the bean above in your own configuration? (first one in the config presented by Sam_K)

oops…I missed that…now its working fine upon including.
Thanks !! :slight_smile:

you’re welcome :sun_with_face:

one more help.
How do i create a bean for a particular bucket in that cluster from the cluster bean created ??

my spring-with-xml days are way past me, I’m not sure this can easily be done since the method for creation is neither a constructor nor a factory method on the Bucket class…
you’d have to look up if invoking another bean’s method + passing in bucket name and password is feasible in Spring (especially with xml configuration)…

ohh
@ingenthr @daschl @Sam_K
can anyone else help ??
i want to create bean for a bucket in my xml.

@akshay I recommend you to check out the spring documentation, creating beans is not something that strictly relates to couchbase. You might want to start here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-class-instance-factory-method by using instance factory methods.

ok…great
Thanks !! :slight_smile:

@akshay ~ I saw later. Try this

<bean id="couchbaseEnvironment" class="com.couchbase.client.java.env.DefaultCouchbaseEnvironment"
      factory-method="create"/>
<bean id="cluster" class="com.couchbase.client.java.CouchbaseCluster" factory-method="create"
      destroy-method="disconnect">
    <constructor-arg name="environment" ref="couchbaseEnvironment"/>
    <constructor-arg name="nodes">
        <list value-type="java.lang.String">
            <value>{TYPE COUCHBASE CLUSTER IP}</value>
        </list>
    </constructor-arg>
</bean>
<bean id="bucket" class="com.couchbase.client.java.Bucket" factory-bean="cluster"
      factory-method="openBucket">
    <constructor-arg name="name" value="{TYPE BUCKET NAME}"/>
</bean>
2 Likes

Thanks @Sam_K
i already did that.
I am facing another issue now. I have defined these beans in file named “applicationContext.xml” and when i am using
Bucket bucket = (Bucket) ( new ClassPathXmlApplicationContext(“applicationContext.xml”).getBean(“bucket”) );
in different classes.And it is creating different environments each time instead of reusing the same environment and giving the same “more than one couchbase environments found” warning.
What wrong am i doing ??

@akshay You are either creating more than one CouchbaseEnvironment or more CouchbaseCluster objects (without passing in the environment to share). Please see http://docs.couchbase.com/developer/java-2.1/managing-connections.html

yeah @daschl
I fixed that now. Thanks for the help !!

I’ve run into this as well… Basically we manage our own configuration and I’ve been able to track and re-use the duplicated cluster info. But… If the client itself detects a duplicate, why would it throw this warning out and not just mitigate the duplicate automagically? Or, is there a reason why one would want to have this behavior?