Reputation: 1553
We are running Couchbase Community Edition 4.5.1, and recently went through the process of adding a TTL to documents were none previously existed. After doing so, we pulled the csv backup of the database and noticed a large number of the document are still returning an expiration of 0. We aren't sure if the issue is a failure to update, or in the data pull.
Unfortunately, Couchbase has an issue where expiration does not return in the metadata for N1QL, so we have been unable to independently confirm whether the csv is correct for any given document.
Is there another way to get the current TTL of a document, either through the Console UI or an API call?
Upvotes: 0
Views: 864
Reputation: 1894
You can use the cbc utility included in libcouchbase to fetch the TTL with --keystats. For example:
$ cbc-stats --keystats -u Administrator -P - -U couchbase://localhost/travel-sample airline
_112
Bucket password:
localhost:11210 key_is_dirty false
localhost:11210 key_exptime 0
localhost:11210 key_flags 33554432 (cbc: converted via htonl)
localhost:11210 key_cas 1503621971151421440
localhost:11210 key_vb_state active
And note that in Couchbase Server 5.0, the Sub-Document API has been enhanced so you can fetch the TTL as a virtual XATTR. For example:
$ cbc-subdoc -u Administrator -P - -U couchbase://localhost/travel-sample
Bucket password:
subdoc> get -x $document airline_112
airline_112 CAS=0x14ddf0375af40000
0. Size=188, RC=0x00 Success (Not an error)
{"CAS":"0x14ddf0375af40000","vbucket_uuid":"0x0000e976b253ad5c","seqno":"0x0000000000000001","exptime":0,"value_bytes":118,"datatype":["json"],"deleted":false,"last_modified":"1503621971"}
1. Size=118, RC=0x00 Success (Not an error)
{"callsign":"FLYSTAR","country":"United Kingdom","iata":"5W","icao":"AEU","id":112,"name":"Astraeus","type":"airline"}
subdoc> get -x $document.exptime airline_112
airline_112 CAS=0x14ddf0375af40000
0. Size=1, RC=0x00 Success (Not an error)
0
1. Size=118, RC=0x00 Success (Not an error)
{"callsign":"FLYSTAR","country":"United Kingdom","iata":"5W","icao":"AEU","id":112,"name":"Astraeus","type":"airline"}
subdoc> get -x $document.exptime -x $document.value_bytes airline_112
airline_112 CAS=0x14ddf0375af40000
0. Size=1, RC=0x00 Success (Not an error)
0
1. Size=3, RC=0x00 Success (Not an error)
118
2. Size=118, RC=0x00 Success (Not an error)
{"callsign":"FLYSTAR","country":"United Kingdom","iata":"5W","icao":"AEU","id":112,"name":"Astraeus","type":"airline"}
You can fetch these XATTRs programmatically too from an SDK which might be handy for unit tests. Documentation of these features is available.
Upvotes: 2