(identifier string, size int, zoneStableSharding bool, subring *Ring)
| 972 | } |
| 973 | |
| 974 | func (r *Ring) setCachedShuffledSubring(identifier string, size int, zoneStableSharding bool, subring *Ring) { |
| 975 | if subring == nil || r.cfg.SubringCacheDisabled { |
| 976 | return |
| 977 | } |
| 978 | |
| 979 | r.mtx.Lock() |
| 980 | defer r.mtx.Unlock() |
| 981 | |
| 982 | // Only cache if *this* ring hasn't changed since computing result |
| 983 | // (which can happen between releasing the read lock and getting read-write lock). |
| 984 | // Note that shuffledSubringCache can be only nil when set by test. |
| 985 | if r.shuffledSubringCache != nil && r.lastTopologyChange.Equal(subring.lastTopologyChange) { |
| 986 | r.shuffledSubringCache[subringCacheKey{identifier: identifier, shardSize: size, zoneStableSharding: zoneStableSharding}] = subring |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | func (r *Ring) CleanupShuffleShardCache(identifier string) { |
| 991 | if r.cfg.SubringCacheDisabled { |
no test coverage detected