检查 Couchbase 中文档的过期时间
Checking Expiration of Document in Couchbase
我们是 运行 Couchbase Community Edition 4.5.1,最近完成了向 none 以前存在的文档添加 TTL 的过程。这样做之后,我们拉取了数据库的 csv 备份,发现大量文档仍然 return 过期为 0。我们不确定问题是更新失败,还是在数据拉。
不幸的是,Couchbase 存在一个问题,即 N1QL 的元数据中没有过期 return,因此我们无法独立确认任何给定文档的 csv 是否正确。
是否有其他方法可以通过控制台 UI 或 API 调用来获取文档的当前 TTL?
您可以使用 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, the Sub-Document API has been enhanced so you can fetch the TTL as a 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.
我们是 运行 Couchbase Community Edition 4.5.1,最近完成了向 none 以前存在的文档添加 TTL 的过程。这样做之后,我们拉取了数据库的 csv 备份,发现大量文档仍然 return 过期为 0。我们不确定问题是更新失败,还是在数据拉。
不幸的是,Couchbase 存在一个问题,即 N1QL 的元数据中没有过期 return,因此我们无法独立确认任何给定文档的 csv 是否正确。
是否有其他方法可以通过控制台 UI 或 API 调用来获取文档的当前 TTL?
您可以使用 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, the Sub-Document API has been enhanced so you can fetch the TTL as a 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.