Reputation: 1367
When trying to update a couchbase document that was previously deleted the update call fails with a CASResponse.EXISTS code rather than a CASResponse.NOT_FOUND. However a call to get the previously deleted key immediately after the delete is complete returns null as expected:
def main(args: Array[String]){
val uris = List(URI.create("http://localhost:8091/pools"))
val client = new CouchbaseClient(uris, "test", "password")
client.add("asdf", "qwer").get
client.delete("asdf").get
val result = client.asyncGets("asdf").get
assert(result == null)
val response = client.asyncCAS("asdf", 1, "bar").get
response match {
case CASResponse.NOT_FOUND => println("Document Not Found")
case CASResponse.EXISTS => println("Document exists")
}
}
Adding Thread.sleep(1000) before the update call fixes the problem, so my question is this the expected behaviour of Couchbase?
Couchbase version is 2.2.0 enterprise edition (build-821), using the Java client version 1.2.1 in Scala 2.10.2.
Thanks
Upvotes: 0
Views: 247
Reputation: 2474
I think you probably want to do:
client.delete(key, PersistTo.MASTER).get();
You can change the enum PersistTo to other options such as ONE,TWO,THREE (i.e. Master plus additional numbers of nodes). I tested your example with only one node and the above worked for me.
Upvotes: 1
Reputation: 530
Have you tried use client.gets() instead of client.asyncGets().get() and client.cas() instead of client.asyncCAS().get()? I think it can solve your problem.
Upvotes: 0