0

I have a couchbase key K which stores a JsonLongDocument V.

Whenever I see an event E at time T, I increment the V by 1 with an updated expiry of T+n(sec) using the following java client function :

bucket.counter(K, 1, 1, n)

I also occasionally have to get the value V using key K by calling the following java client function :

bucket.get(K, classOf[JsonLongDocument]) 

But whenever I'm calling simple 'get', the couchbase is changing the expiry of the document and setting it to 0 which means persist forever.

How can I still do the 'get' on my value without changing its expiry?

borrrden
  • 33,256
  • 8
  • 74
  • 109
N A
  • 831
  • 2
  • 8
  • 28

1 Answers1

0

Getting a document by its key does not change the document's expiry.

You must use bucket.touch(K, n) to update the expiry after incrementing the counter. The expiry passed to bucket.counter(K, 1, 1, n) is only used if the counter document does not exist.

The expiry returned in the JsonLongDocument is either the expiry value passed to the method or zero. It does not reflect the actual expiry timestamp stored in Couchbase. I'm not sure why the SDKs behave this way, but it is expected behavior.

To see the real expiry timestamp you can use N1QL as described here or you can inspect the counter's data file.

Steps to get a document's expiry from a data file:

  1. Determine in which vbucket and server the document resides, vbucket 8 and localhost in the example below (requires libcouchbase, the Couchbase C SDK)

    > cbc-hash test-counter-1
    test-counter-1: [vBucket=8, Index=0] 
        Server: localhost:11210, CouchAPI: http://localhost:8092/default
    Replica #0: Index=-1, Host=N/A
    
  2. Extract the counter document information from the vbucket data file, 8.couch.1 in this example

    > couch_dbdump 8.couch.1 | grep -B 2 -A 6 test-counter-1
    Dumping "8.couch.1":
    Doc seq: 63
         id: test-counter-1
         rev: 63
         content_meta: 128
         size (on disk): 11
         cas: 1501205424364060672, expiry: 1501205459, flags: 0, datatype: 1
         size: 1
         data: (snappy) 2
    

    See File Locations or the Disk Storage section of your server node information to locate the 'data' directory where data files are stored. The vbucket files will be in a subdirectory of 'data' named after your bucket.

Jeff Kurtz
  • 651
  • 4
  • 8