(t *testing.T)
| 2241 | } |
| 2242 | |
| 2243 | func TestRing_ShuffleShard_ConsistencyOnShardSizeChanged(t *testing.T) { |
| 2244 | // Create 30 instances in 3 zones. |
| 2245 | ringInstances := map[string]InstanceDesc{} |
| 2246 | for i := 0; i < 30; i++ { |
| 2247 | name, desc, _ := generateRingInstance(initTokenGenerator(t), i, i%3, 128, nil) |
| 2248 | ringInstances[name] = desc |
| 2249 | } |
| 2250 | |
| 2251 | // Init the ring. |
| 2252 | ringDesc := &Desc{Ingesters: ringInstances} |
| 2253 | ring := newRingForTesting(Config{ |
| 2254 | HeartbeatTimeout: time.Hour, |
| 2255 | ZoneAwarenessEnabled: true, |
| 2256 | }, false) |
| 2257 | ring.setRingStateFromDesc(ringDesc, false, false, false) |
| 2258 | |
| 2259 | // Get the replication set with shard size = 3. |
| 2260 | firstShard := ring.ShuffleShard("tenant-id", 3) |
| 2261 | assert.Equal(t, 3, firstShard.InstancesCount()) |
| 2262 | |
| 2263 | firstSet, err := firstShard.GetAllHealthy(Read) |
| 2264 | require.NoError(t, err) |
| 2265 | |
| 2266 | // Increase shard size to 6. |
| 2267 | secondShard := ring.ShuffleShard("tenant-id", 6) |
| 2268 | assert.Equal(t, 6, secondShard.InstancesCount()) |
| 2269 | |
| 2270 | secondSet, err := secondShard.GetAllHealthy(Read) |
| 2271 | require.NoError(t, err) |
| 2272 | |
| 2273 | for _, firstInstance := range firstSet.Instances { |
| 2274 | assert.True(t, secondSet.Includes(firstInstance.Addr), "new replication set is expected to include previous instance %s", firstInstance.Addr) |
| 2275 | } |
| 2276 | |
| 2277 | // Increase shard size to 9. |
| 2278 | thirdShard := ring.ShuffleShard("tenant-id", 9) |
| 2279 | assert.Equal(t, 9, thirdShard.InstancesCount()) |
| 2280 | |
| 2281 | thirdSet, err := thirdShard.GetAllHealthy(Read) |
| 2282 | require.NoError(t, err) |
| 2283 | |
| 2284 | for _, secondInstance := range secondSet.Instances { |
| 2285 | assert.True(t, thirdSet.Includes(secondInstance.Addr), "new replication set is expected to include previous instance %s", secondInstance.Addr) |
| 2286 | } |
| 2287 | |
| 2288 | // Decrease shard size to 6. |
| 2289 | fourthShard := ring.ShuffleShard("tenant-id", 6) |
| 2290 | assert.Equal(t, 6, fourthShard.InstancesCount()) |
| 2291 | |
| 2292 | fourthSet, err := fourthShard.GetAllHealthy(Read) |
| 2293 | require.NoError(t, err) |
| 2294 | |
| 2295 | // We expect to have the same exact instances we had when the shard size was 6. |
| 2296 | for _, secondInstance := range secondSet.Instances { |
| 2297 | assert.True(t, fourthSet.Includes(secondInstance.Addr), "new replication set is expected to include previous instance %s", secondInstance.Addr) |
| 2298 | } |
| 2299 | |
| 2300 | // Decrease shard size to 3. |
nothing calls this directly
no test coverage detected