Index Statistics API and Replicas

Couchbase has an Index Statistics API (https://docs.couchbase.com/server/current/rest-api/rest-index-stats.html). The stats have just what I’m looking for, but I have run into an issue when an index has been created with replicas.

When created with replicas (e.g. WITH { "num_replica": 1}), then when using the Console or the API you’ll see multiple indexes that include the replica. This reflects the fact that different nodes are in play for the main index and the replica, especially when there are multiple indexers or partitioning. For example, you might have cdr_by_direction_and_time_v1 and cdr_by_direction_and_time_v1 (replica 1). Those are the ACTUAL names that come back from the API.

I want to be able to hit the Index Statistics API for each of those indexes to get back partition and node details on each separately. The problem is that the API doesn’t seem to be able to handle the two different names, and calls to the API for the name cdr_by_direction_and_time_v1 seem to sometimes return the primary, and sometimes return the data for the replica. Attempts to encode cdr_by_direction_and_time_v1 (replica 1) in the URL just cause calls to fail.

Has anyone been able to use these API’s predictably with replicas? To be able to get the stats on each of the two indexes?

Did you tried URL encoding the space, (,)

cdr_by_direction_and_time_v1%20%28replica%201%29

Yes. As an example, if I do:

curl -X GET -u <user>:<password> "http://n1ql10-theta.sightplan-ops.net:9102/api/v1/stats?pretty=true"

I’ll get back a JSON response that contains, among other things:

  • "sync_gateway_sw1:by_type_location_size_sg_idx_v2"
  • "sync_gateway_sw1:by_type_location_size_sg_idx_v2 (replica 1)"

And I notice the following:

  • A GET on /api/v1/stats/sync_gateway_sw1/by_type_location_size_sg_idx_v2 returns a 200 and the JSON you would expect.
  • A GET on /api/v1/stats/sync_gateway_sw1/by_type_location_size_sg_idx_v2%20%28replica%201%29 returns a 404 and echos back “/api/v1/stats/sync_gateway_sw1/by_type_location_size_sg_idx_v2 (replica 1)”

Separately, note that if you ask for detail on an index node that ONLY has the replica, but you ask with the non-replica name, you’ll get back the replica. In other words, if you as for “myindex” and the primary is on that node you’ll get it. If you ask for “myindex” and the replica is on that node only, you’ll get that.

I think it means you can’t get the replica data unless ONLY the replica is on the node. There is no way to pass that “(replica 1)” as part of the url. You just get back 404s. I think maybe this is a bug.

Hi @polfer,

Thanks for reporting this. I have opened Loading....

Please let me know the Couchbase Server version you are using.

Thanks.

Thank you, Amit. The Couchbase Server version is 6.5.1 build 6299, and we have not tested this problem on earlier versions.