3

I am using spring-data-couchbase 2.1.2 with spring-boot 1.4.0.RC1 and couchbase-spring-cache

It works fine when caching is disabled as it returns NULL object When caching is enabled and try to find a non-existing document in the bucket it throws an exception:

com.couchbase.client.java.error.DocumentDoesNotExistException: null
    at com.couchbase.client.java.CouchbaseAsyncBucket$22.call(CouchbaseAsyncBucket.java:684) ~[java-client-2.2.8.jar:na]
    at com.couchbase.client.java.CouchbaseAsyncBucket$22.call(CouchbaseAsyncBucket.java:671) ~[java-client-2.2.8.jar:na]
    at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54) ~[rxjava-1.0.17.jar:1.0.17]
    at rx.observers.Subscribers$5.onNext(Subscribers.java:234) ~[rxjava-1.0.17.jar:1.0.17]
    at rx.subjects.SubjectSubscriptionManager$SubjectObserver.onNext(SubjectSubscriptionManager.java:223) ~[rxjava-1.0.17.jar:1.0.17]
    at rx.subjects.AsyncSubject.onCompleted(AsyncSubject.java:101) ~[rxjava-1.0.17.jar:1.0.17]
    at com.couchbase.client.core.endpoint.AbstractGenericHandler.completeResponse(AbstractGenericHandler.java:354) ~[core-io-1.2.9.jar:na]
    at com.couchbase.client.core.endpoint.AbstractGenericHandler.access$000(AbstractGenericHandler.java:72) ~[core-io-1.2.9.jar:na]
    at com.couchbase.client.core.endpoint.AbstractGenericHandler$1.call(AbstractGenericHandler.java:372) ~[core-io-1.2.9.jar:na]
    at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) ~[rxjava-1.0.17.jar:1.0.17]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_80]
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) ~[na:1.7.0_80]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) ~[na:1.7.0_80]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) ~[na:1.7.0_80]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_80]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_80]
    at java.lang.Thread.run(Thread.java:745) ~[na:1.7.0_80]
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.core.message.kv.RemoveResponse.class
    at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:109) ~[rxjava-1.0.17.jar:1.0.17]
    at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:188) ~[rxjava-1.0.17.jar:1.0.17]
    at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:56) ~[rxjava-1.0.17.jar:1.0.17]
    ... 14 common frames omitted

Is it because of AsyncBucket? Is it possible to disable AsyncBucket?

Source code https://github.com/maverickmicky/spring-couchbase-cache

Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108
mickygo
  • 107
  • 1
  • 10
  • could you share some code? are you sure it happens when loading the document (ie. happens even if only using simple `@Cacheable`)? – Simon Baslé Jul 26 '16 at 14:59
  • I don't think it is because of `AsyncBucket`, and it cannot be disabled as it is the foundation for the Couchbase SDK – Simon Baslé Jul 26 '16 at 15:00
  • added source code, u need to have couchbase running locally with bucket name 'player' – mickygo Jul 27 '16 at 09:50

2 Answers2

5

This is an issue indeed... As soon as an eviction attempt for a key that isn't in cache is made, the exception will be thrown :(

I've created an issue for this (with work arounds).

edit: To work around the issue, you should be able to declare a CacheErrorHandler that has a handleCacheEvictError method that simply catches DocumentDoesNotExistException. See the documentation section on configuring the cache abstraction here and the CachingConfigurer javadoc.

Simon Baslé
  • 27,105
  • 5
  • 69
  • 70
  • in Spring Boot 1.4, a lot of what you did with your `Database` class is redundant and can be autoconfigured. instead you'll just need the proper entries in `application.property` + a `@Configuration` `@EnableCaching` class that extends `CachingConfigurerSupport` and provides the `CacheErrorHandler` implementation. – Simon Baslé Jul 27 '16 at 13:14
  • Ok. But the issue I face is during the fetching. When i call 'findOne' on the document which is does not exist then it throws the exception. Any sample for autoconfiguration? – mickygo Jul 27 '16 at 13:20
  • I saw ur commits in git. I will try the cache handler. Is it possible to get those properties from environment variables? I am deploying this in docker and couchbase params are configured through entrypoint.sh – mickygo Jul 27 '16 at 13:31
  • ah I see why: you call an `@Cacheable` annotated method, which updates the cache after getting the data from canonical source. so it ends up doing a `put(null)` and the `CouchbaseCache` will interpret that as an eviction (which may be a bad design decision on my part). You can use `unless = "#result == null"` on `@Cacheable` to work around this one – Simon Baslé Jul 27 '16 at 13:35
  • to get properties from the environment, refer to http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html – Simon Baslé Jul 27 '16 at 13:35
  • did another PR for the `getPlayer` triggering the issue – Simon Baslé Jul 27 '16 at 13:48
  • ok, so if I use 'spring.couchbase.bootstrap-hosts' as the param in my entrypoint it will be available to spring from env variables? – mickygo Jul 27 '16 at 13:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/118460/discussion-between-mickygo-and-simon-basle). – mickygo Jul 27 '16 at 15:47
  • @SimonBaslé, I am not using caching, but still, I am getting above mentioned error.I am using couchbase 6.0 with springboot webflux. – Bifrost Jan 30 '20 at 09:29
1

I am across the same exception and use case is I am caching the resource which return null, for example:

@Override
@Cacheable(value = "EMPLOYEE_", key = "#id")
public Employee getEmployee(int id) {
    return null;
}

And fixed it using the unless attribute of @Cacheable which is available as of Spring 3.2, as follows:

@Override
@Cacheable(value = "EMPLOYEE_", key = "#id", unless = "#result == null")
public Employee getEmployee(int id) {
    return null;
}

Have written an article as well which describe my problem and fix for the same - Fixing com.couchbase.client.java.error.DocumentDoesNotExistException – Couchbase

Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108