Accessing Design Documents with Java SDK

Hello,

My first attempt at posting this seems to have disappeared.

I am trying to access Design Documents on a remote Couchbase server. This is using server Version: 3.0.1 Community Edition (build-1444) with Java SDK version com.couchbase.client:java-client:jar:2.1.1:compile (from Maven dependency tree).

First, I open the connection…

Cluster aCluster = CouchbaseCluster.create(“my remote IP”);

…then I get the default bucket…

Bucket aBucket = aCluster.openBucket(“default”)

…so far so good. I then get the BucketManager and attempt to call getDesignDocuments()…

BucketManager aBucketManager = aBucket.bucketManager();
aBucketManager.getDesignDocuments()

…it’s this last line that causes the problem. I get a ConnectionException due to a connection being attempted to localhost:8092.

I see that two ports are used to get things done, 8091 and 8092 (maybe there are others). Why is it trying to reach localhost when I have already provided my remote IP. Do I need to specify an IP per port?

Thanks,

Matthew

Having debugged the Couchbase source code, there appears to be a problem in com.couchbase.client.core.config.DefaultPortInfo where null is being passed in as the hostname into the constructor. As a result of this…

this.hostname = InetAddress.getByName(hostname);

…defaults to localhost.

This constructor appears to be populated by JSON (based on the presence of @JsonProperty annotations). At this point am assuming that the BucketManager::getDesignDocuments() call is being done relative to the Bucket, which, of course, is on the same host.

It would appear a section of the JSON being deserialized contains the following…

"nodesExt": [
    {
        "services": {
            "mgmt": 8091,
            "capi": 8092,
            "moxi": 11211,
            "kv": 11210
        }
    }
]

…in order to correctly populate the DefaultPortInfo object, the above JSON would have to read as follows…

"nodesExt": [
    {
        "hostname": "my host name",
        "services": {
            "mgmt": 8091,
            "capi": 8092,
            "moxi": 11211,
            "kv": 11210
        }
    }
]

…however, I notice that the correct host name is actually included elsewhere in the JSON.

Can you please share the DEBUG or TRACE logs so we can see the config you get back from the server? Thanks!

My suspicion is that your server might be configured incorrectly (its hostname is configured to 127.0.0.1 which is returned in the config from the server and then the client can’t connect properly anymore).

oh I see what’s going on. 3.0.2 has the hostname in there but 3.0.1 doesn’t. I’ll fix it for the next java release, you can go to 3.0.2 I’m sure it will work.

@couchbaseuser024 I found it and will be sure to get it into 2.1.2 - http://review.couchbase.org/#/c/48238/

Great, thanks for taking care of this. Any idea as to when the update will be available for download? Will give 3.0.2 a try (although Maven seems to be having trouble finding it).

In general we do rolling releases every first tuesday of the month (so 7th april would be next), but we’re currently evaluating if we might do this one earlier. I’ll let you know as soon as it’s out - but you can also build it on your own if you want to try it out!

If you have an Enterprise Subscription, there’s also the possibility of requesting a build from support. I can’t guarantee one, but usually they can accommodate giving you a build they’d support pending testing.

Hi,

we’ve published a developer preview of 2.1.2 to get quicker feedback if the bug is properly fixed and your issues are addressed. You can get it from our couchbase repository like all pre-releases, the 2.1.2 GA release will be published to maven central as usual.

You can get it like this:

<dependencies>
    <dependency>
        <groupId>com.couchbase.client</groupId>
        <artifactId>java-client</artifactId>
        <version>2.1.2-dp</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>couchbase</id>
        <name>couchbase repo</name>
        <url>http://files.couchbase.com/maven2</url>
        <snapshots><enabled>false</enabled></snapshots>
    </repository>
</repositories>

It includes this change which should resolve the issue: https://github.com/couchbase/couchbase-jvm-core/commit/f6d5dd3f62f01a0d2ce48d5f925eefadf00c77d6

Keep in mind that this is not an officially tested release since it has not gone trough extensive QE testing yet. Please let us know if it works and upgrade to 2.1.2 as soon as it is released.

Thanks!

There also appears to be a similar problem (trying to connect to localhost) when upserting a document to a bucket that was previously opened on a remote host. This is still using the 2.1.1 library. Will see whether the new library has fixed this.

New library appears to be working both with view access and creation as well as the afore mentioned bucket upserts. The only problem now appears to be that the views don’t seem to accurately reflect the contents of a bucket (seems similar to this issue; Views not updating)

Using the Stale.FALSE flag seems to have taken care of the view update issue, eg…

ViewQuery.from(design, view).key(key).stale(Stale.FALSE);

1 Like

@couchbaseuser024 it appears your first post was weirdly caught into the forum’s spam filter. now that I’ve unflagged it and it’s a dupe, I’ll just delete it :smile:
glad the issue was resolved for you Matthew!