我们正在运行Couchbase Community Edition 4.5.1,并且最近经历了向之前不存在的文档添加TTL的过程。执行此操作后,我们撤消了数据库的csv备份,并注意到大量文档仍然返回0到期。我们不确定问题是更新失败还是数据拉动。
不幸的是,Couchbase存在一个问题,即N1QL的元数据中没有返回到期,因此我们无法独立确认csv对于任何给定文档是否正确。
是否有另一种方法可以通过Console UI或API调用获取文档的当前TTL?
答案 0 :(得分:2)
您可以使用libcouchbase中包含的cbc实用程序来获取带有--keystats的TTL。例如:
$ 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
请注意,在Couchbase Server 5.0中,Sub-Document API已得到增强,因此您可以将TTL作为virtual XATTR获取。例如:
$ 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"}
您也可以从SDK中以编程方式获取这些XATTR,这可能对单元测试很方便。 Documentation of these features is available