requireNumSGIndexPartitions ensures that the number of partitions for SG indexes is as expected. Some indexes aren't partitioned.
(t testing.TB, database *db.DatabaseContext)
| 193 | |
| 194 | // requireNumSGIndexPartitions ensures that the number of partitions for SG indexes is as expected. Some indexes aren't partitioned. |
| 195 | func assertNumSGIndexPartitions(t testing.TB, database *db.DatabaseContext) { |
| 196 | gocbBucket, err := base.AsGocbV2Bucket(database.Bucket) |
| 197 | require.NoError(t, err) |
| 198 | re := regexp.MustCompile(`sg_(?:allDocs|channels)_x1(?:_p(\d+))?$`) |
| 199 | for _, dsName := range []sgbucket.DataStoreName{db.GetSingleDatabaseCollection(t, database).GetCollectionDatastore(), database.MetadataStore} { |
| 200 | allIndexes, err := gocbBucket.GetCluster().Bucket(gocbBucket.BucketName()).Scope(dsName.ScopeName()).Collection(dsName.CollectionName()).QueryIndexes().GetAllIndexes(nil) |
| 201 | require.NoError(t, err) |
| 202 | require.Greaterf(t, len(allIndexes), 0, "expected at least one index for datastore %s", dsName) |
| 203 | for _, index := range allIndexes { |
| 204 | // only two SG indexes are partitioned currently |
| 205 | partitionsFromNameStrs := re.FindStringSubmatch(index.Name) |
| 206 | if len(partitionsFromNameStrs) > 1 && partitionsFromNameStrs[1] != "" { |
| 207 | expectedPartitionsFromName, err := strconv.ParseInt(partitionsFromNameStrs[1], 10, 64) |
| 208 | require.NoError(t, err) |
| 209 | require.Greaterf(t, int(expectedPartitionsFromName), 1, "expected at least one partition for %s", index.Name) |
| 210 | assert.NotEqualf(t, "", index.Partition, "expected partition clause for %s", index.Name) |
| 211 | assert.Equal(t, int(expectedPartitionsFromName), int(db.GetIndexPartitionCount(t, gocbBucket, dsName, index.Name))) |
| 212 | } else { |
| 213 | assert.Equal(t, "", index.Partition) |
| 214 | assert.True(t, strings.HasSuffix(index.Name, "_x1"), "expected no partitions for %+v", index) |
| 215 | assert.Equal(t, 1, int(db.GetIndexPartitionCount(t, gocbBucket, dsName, index.Name))) |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | func TestChangeIndexPartitionsErrors(t *testing.T) { |
| 222 | tests := []struct { |
no test coverage detected