storage: fill a cold EC location cache from a partial lookup

A reply placing fewer than the data shards no longer reaches the cache
at all, so a cold cache stays empty and a read cannot go straight to a
shard whose holder is up, as it could before the guard counted placed
shards. Take the holders it names for shards the cache does not know,
without touching known shards or the refresh time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-22 10:38:36 -08:00
1 parent e23c665523
commit d674199290
2 files changed
+43

No files matched your search

+14
View File
@@ -1191,6 +1191,20 @@ func (s *Store) cachedLookupEcShardLocations(ecVolume *erasure_coding.EcVolume)
}
}
if located < ecCtx.DataShards {
// Too few to trust as the volume's map, but a cold cache can still
// read the shards it names directly: fill only the shards the cache
// does not know, and leave the refresh time alone.
ecVolume.ShardLocationsLock.Lock()
for _, shardIdLocations := range resp.ShardIdLocations {
shardId := erasure_coding.ShardId(shardIdLocations.ShardId)
if len(ecVolume.ShardLocations[shardId]) > 0 {
continue
}
for _, loc := range shardIdLocations.Locations {
ecVolume.ShardLocations[shardId] = append(ecVolume.ShardLocations[shardId], pb.NewServerAddressFromLocation(loc))
}
}
ecVolume.ShardLocationsLock.Unlock()
return fmt.Errorf("only %d shards found but %d required", located, ecCtx.DataShards)
}
@@ -198,6 +198,35 @@ func TestCachedLookupEcShardLocationsRefusesAReplyWithFewLocatedShards(t *testin
}
}
// A partial reply is no map to trust, but a cold cache takes the holders it
// names, so a read can still go straight to a shard whose holder is up.
func TestCachedLookupEcShardLocationsFillsAColdCacheFromAPartialReply(t *testing.T) {
master, masterAddr := startCountingMaster(t)
master.located.Store(7)
store := &Store{
MasterFn: func() pb.ServerAddress { return masterAddr },
grpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
}
ecVolume := &erasure_coding.EcVolume{
VolumeId: 9,
ShardLocations: make(map[erasure_coding.ShardId][]pb.ServerAddress),
}
if err := store.cachedLookupEcShardLocations(ecVolume); err == nil {
t.Error("a reply placing 7 of 14 shards was accepted")
}
ecVolume.ShardLocationsLock.RLock()
cached := len(ecVolume.ShardLocations)
refreshed := !ecVolume.ShardLocationsRefreshTime.IsZero()
stale := ecVolume.ShardLocationsStale
ecVolume.ShardLocationsLock.RUnlock()
if cached != 7 {
t.Errorf("the cold cache holds %d shards after the partial reply, want the 7 it placed", cached)
}
if refreshed || !stale {
t.Errorf("a partial reply must leave the map due a lookup: refreshed=%v stale=%v", refreshed, stale)
}
}
func TestEcShardLocationsTTL(t *testing.T) {
ecCtx := erasure_coding.NewDefaultECContext("", 1)
for _, tc := range []struct {