using java sdk version 3.3.0, couchbase enterprise 6.6 , when i insert a document using collection.insert(id, content, insertOptions().expiry(Duration.ofHours(2))),
where insertOptions has expiry set, the document is getting inserted but the expiration is not getting reflected. From the couchbase console, metaData for the document shows zero (0) for expiration,
I tried debugging the couchbase sdk, InsertRequest is getting populated with expiration value before the request being sent, but not reflecting t server side.
Can you verify that the document is still present after the expiration that was specified? Maybe set the expiration to 5 seconds on insert, then wait 10 seconds and try to get() the document? The reason I ask is that there was a bug where the expiration was showing 0 when it was non-zero.
Hi @anilb
Checking the SDK code it certainly looks like the expiry value should be getting sent to the server…
Are you performing any other mutations to the document? One common gotcha is that, unless the expiry is re-specified on each mutation, it gets reset to 0. It’s the only thing I can think of that may be accounting for what you’re seeing. (Incidentally, Couchbase Server 7.0 adds a preserveExpiry feature to mitigate this.)
Hi @graham.pople you are correct, the document getting inserted and immediately getting updated. I have validated and can see the expiration after the document is inserted(had a break point immediately after it is inserted). So based on what I understood from above, every mutation after being inserted need to provide the expiration?
every mutation after being inserted need to provide the expiration?
Yes, or use the preserveExpiry option added in Couchbase 7. From the documentation:
Note that when updating the document, special care must be taken to avoid resetting the expiry to zero. If you are using Couchbase Server 7.0 or later, set the preserveExpiry option when updating the document:
Thank you for the quick response, we are evaluating one of those options. Is there a possibility to back port preseveExpiry option to 6.6.x? SDK has this option right now, it just that the server is not honoring it
Is there a possibility to back port preseveExpiry option to 6.6.x?
It’s not for me to say. Filing an issue with Couchbase Technical Support would be one way to get your feature request in front of the right eyes. If you’re not an Enterprise customer, you could start a new thread over here: Couchbase Server - Couchbase Forums
If I were in your shoes, I would push to upgrade to Couchbase 7. It brings lots of other great features. Scopes & Collections are a game changer, for example.