java client 1.0.1: Exception using CouchbaseClient in a servlet filter
When using any CouchbaseClient method in a ServletFilter (tested in Tomcat 6 and OC4J) I get the following Exception:
java.lang.NullPointerException com.couchbase.client.CouchbaseConnection.addOperation(CouchbaseConnection.java:142) net.spy.memcached.MemcachedConnection.enqueueOperation(MemcachedConnection.java:639) net.spy.memcached.MemcachedClient.asyncGet(MemcachedClient.java:835) net.spy.memcached.MemcachedClient.get(MemcachedClient.java:997) net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1018) it.almaviva..........
the exactly same code works fine when called in a standalone java program or Junit test.
Here some snippets from the code I use to connect to a 2 node COuchbase 1.8 server
CouchbaseClient current = null; ... try { current = new CouchbaseClient(uris, currentBucket, currentBucketPassword); } catch (Exception e) { System.out.println("Error connecting to Couchbase: " + e.getMessage()); } ...
and this is one of the operation calls that generate the exception when called in a ServletFilter
public String findCurrentCookieVal(String user) { return cookie = (String) current.get(user); }
When I get the exception, in the console of the application server, I see these errors from couchbase cleintlibrary:
2012-03-09 12:21:10.005 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
The node locator does not have a primary for key mario. Wanted vbucket 605 whic
h should be on server lucianompc:11210.
2012-03-09 12:21:10.023 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
List of nodes has 4 entries:
2012-03-09 12:21:10.028 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
MemcachedNode for 10.100.8.75:11210 is {QA sa=lucianomPC/10.100.8.75:11210, #Rop
s=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2012-03-09 12:21:10.036 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
MemcachedNode for centos.lucianompc:11210 is {QA sa=centos.lucianompc/192.168.56
.10:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interes
ted=0}
2012-03-09 12:21:10.041 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
MemcachedNode for lucianomPC:11210 is {QA sa=lucianomPC/10.100.8.75:11210, #Rops
=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2012-03-09 12:21:10.045 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
MemcachedNode for 192.168.56.10:11210 is {QA sa=centos.lucianompc/192.168.56.10:
11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=
0}
2012-03-09 12:21:10.051 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
{QA sa=lucianomPC/10.100.8.75:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWo
p=null, toWrite=0, interested=0}
2012-03-09 12:21:10.058 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
{QA sa=centos.lucianompc/192.168.56.10:11210, #Rops=0, #Wops=0, #iq=0, topRop=nu
ll, topWop=null, toWrite=0, interested=0}
2012-03-09 12:21:10.063 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
{QA sa=lucianomPC/10.100.8.75:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWo
p=null, toWrite=0, interested=0}
2012-03-09 12:21:10.067 ERROR com.couchbase.client.vbucket.VBucketNodeLocator:
{QA sa=centos.lucianompc/192.168.56.10:11210, #Rops=0, #Wops=0, #iq=0, topRop=nu
ll, topWop=null, toWrite=0, interested=0}is there something specific I miss when using Couchbase java client 1.0.1 in a servlet environment?
Thanks
Luciano
I found the origin of the problem in the name of one of my Couchbase server nodes. The name of the node contains uppercase characters.
For some not still determined reason the class VBucketNodeLocator when running in a Servlet container use the exact node name when inserting the node in his list of nodes, while using a lowercased name when searching the node in the list.
Changing the name of node to all lowercase characters solved the problem.
Luciano
We should probably look to normalize everything to lower case. I've filed an issue to track this: http://www.couchbase.com/issues/browse/JCBC-18
Great detail, thanks so much for letting us know what you've found!
A clarification:
the problem seems only present when client interacts with Couchbase bucket type, while with Memcached bucket type the ServletFilter works as expected (warning: I did limited testing with Memcahced bucket type until now).
Luciano