MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / GetIndexPartitionCount

Function GetIndexPartitionCount

db/util_testing.go:776–812  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
776func 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.
815func (db *DatabaseContext) GetMutationListener(t *testing.T) *changeListener {

Callers 3

TestPartitionedIndexesFunction · 0.92
TestPartitionedIndexesFunction · 0.92

Calls 10

TestCtxFunction · 0.92
MgmtRequestFunction · 0.92
JSONUnmarshalFunction · 0.92
GetGoCBAgentMethod · 0.80
GetCredentialsMethod · 0.65
HttpClientMethod · 0.65
BucketNameMethod · 0.65
EqualMethod · 0.45
CollectionNameMethod · 0.45
ScopeNameMethod · 0.45

Tested by 3

TestPartitionedIndexesFunction · 0.74
TestPartitionedIndexesFunction · 0.74