GetIndexPartitionCount returns the number of partitions for a given index. This function queries index nodes directly and would not be suitable for production use, since this port is not generally accessible.
(t testing.TB, bucket *base.GocbV2Bucket, dsName sgbucket.DataStoreName, indexName string)
| 774 | |
| 775 | // GetIndexPartitionCount returns the number of partitions for a given index. This function queries index nodes directly and would not be suitable for production use, since this port is not generally accessible. |
| 776 | func GetIndexPartitionCount(t testing.TB, bucket *base.GocbV2Bucket, dsName sgbucket.DataStoreName, indexName string) uint32 { |
| 777 | agent, err := bucket.GetGoCBAgent() |
| 778 | require.NoError(t, err) |
| 779 | gsiEps := agent.GSIEps() |
| 780 | require.Greater(t, len(gsiEps), 0, "No available Couchbase Server nodes for GSI") |
| 781 | |
| 782 | var username, password string |
| 783 | if bucket.Spec.Auth != nil { |
| 784 | username, password, _ = bucket.Spec.Auth.GetCredentials() |
| 785 | } |
| 786 | ctx := base.TestCtx(t) |
| 787 | uri := "/getIndexStatus" |
| 788 | respBytes, statusCode, err := base.MgmtRequest(bucket.HttpClient(ctx), gsiEps[0], http.MethodGet, uri, "application/json", username, password, nil) |
| 789 | require.NoError(t, err) |
| 790 | require.Equal(t, http.StatusOK, statusCode, "unexpected status code for %s", respBytes) |
| 791 | var output struct { |
| 792 | Status []struct { |
| 793 | IndexName string `json:"indexName"` |
| 794 | Bucket string `json:"bucket"` |
| 795 | Collection string `json:"collection"` |
| 796 | Scope string `json:"scope"` |
| 797 | NumPartition uint32 `json:"numPartition"` |
| 798 | } `json:"status"` |
| 799 | } |
| 800 | require.NoError(t, base.JSONUnmarshal(respBytes, &output), "error unmarshalling %s", respBytes) |
| 801 | for _, idx := range output.Status { |
| 802 | if idx.Bucket != bucket.BucketName() || idx.Collection != dsName.CollectionName() || idx.Scope != dsName.ScopeName() { |
| 803 | continue |
| 804 | } |
| 805 | if idx.IndexName != indexName { |
| 806 | continue |
| 807 | } |
| 808 | return idx.NumPartition |
| 809 | } |
| 810 | require.Failf(t, "index not found", "index %s not found in %+v", indexName, output) |
| 811 | return 0 |
| 812 | } |
| 813 | |
| 814 | // GetMutationListener retrieves mutation listener form database context, to be used only for testing purposes. |
| 815 | func (db *DatabaseContext) GetMutationListener(t *testing.T) *changeListener { |