(t *testing.T)
| 2311 | } |
| 2312 | |
| 2313 | func TestRing_ShuffleShard_ConsistencyOnZonesChanged(t *testing.T) { |
| 2314 | // Create 20 instances in 2 zones. |
| 2315 | ringInstances := map[string]InstanceDesc{} |
| 2316 | for i := 0; i < 20; i++ { |
| 2317 | name, desc, _ := generateRingInstance(initTokenGenerator(t), i, i%2, 128, nil) |
| 2318 | ringInstances[name] = desc |
| 2319 | } |
| 2320 | |
| 2321 | // Init the ring. |
| 2322 | ringDesc := &Desc{Ingesters: ringInstances} |
| 2323 | ring := newRingForTesting(Config{ |
| 2324 | HeartbeatTimeout: time.Hour, |
| 2325 | ZoneAwarenessEnabled: true, |
| 2326 | }, false) |
| 2327 | ring.setRingStateFromDesc(ringDesc, false, false, false) |
| 2328 | |
| 2329 | // Get the replication set with shard size = 2. |
| 2330 | firstShard := ring.ShuffleShard("tenant-id", 2) |
| 2331 | assert.Equal(t, 2, firstShard.InstancesCount()) |
| 2332 | |
| 2333 | firstSet, err := firstShard.GetAllHealthy(Read) |
| 2334 | require.NoError(t, err) |
| 2335 | |
| 2336 | // Increase shard size to 4. |
| 2337 | secondShard := ring.ShuffleShard("tenant-id", 4) |
| 2338 | assert.Equal(t, 4, secondShard.InstancesCount()) |
| 2339 | |
| 2340 | secondSet, err := secondShard.GetAllHealthy(Read) |
| 2341 | require.NoError(t, err) |
| 2342 | |
| 2343 | for _, firstInstance := range firstSet.Instances { |
| 2344 | assert.True(t, secondSet.Includes(firstInstance.Addr), "new replication set is expected to include previous instance %s", firstInstance.Addr) |
| 2345 | } |
| 2346 | |
| 2347 | // Scale up cluster, adding 10 instances in 1 new zone. |
| 2348 | for i := 20; i < 30; i++ { |
| 2349 | name, desc, _ := generateRingInstance(initTokenGenerator(t), i, 2, 128, nil) |
| 2350 | ringInstances[name] = desc |
| 2351 | } |
| 2352 | |
| 2353 | ringDesc.Ingesters = ringInstances |
| 2354 | ring.setRingStateFromDesc(ringDesc, false, false, false) |
| 2355 | |
| 2356 | // Increase shard size to 6. |
| 2357 | thirdShard := ring.ShuffleShard("tenant-id", 6) |
| 2358 | assert.Equal(t, 6, thirdShard.InstancesCount()) |
| 2359 | |
| 2360 | thirdSet, err := thirdShard.GetAllHealthy(Read) |
| 2361 | require.NoError(t, err) |
| 2362 | |
| 2363 | for _, secondInstance := range secondSet.Instances { |
| 2364 | assert.True(t, thirdSet.Includes(secondInstance.Addr), "new replication set is expected to include previous instance %s", secondInstance.Addr) |
| 2365 | } |
| 2366 | |
| 2367 | // Increase shard size to 9. |
| 2368 | fourthShard := ring.ShuffleShard("tenant-id", 9) |
| 2369 | assert.Equal(t, 9, fourthShard.InstancesCount()) |
| 2370 |
nothing calls this directly
no test coverage detected