mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-08 15:41:15 +02:00
* volume: drop stale volume-location cache on under-replication A replicated write looks up the volume's locations and caches them for 10 minutes. When the master briefly reports fewer replicas than the copy count (e.g. a stale heartbeat drops a just-added volume), that under-replicated result got cached, so every write failed with "replicating operations is less than replication copy count" until the entry expired -- long after the master re-registered the replica. Invalidate the cached entry when the location count is below the copy count, so the next write re-queries the master and recovers as soon as it heals. * volume: mirror the replication copy-count guard in seaweed-volume do_replicated_request accepted a write even when the master reported fewer locations than the volume's copy count, silently under-replicating. Reject it, matching Go's GetWritableRemoteReplications. lookup_volume is uncached, so the next write recovers as soon as the missing replica re-registers.
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package operation
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCaching(t *testing.T) {
|
|
var (
|
|
vc VidCache
|
|
)
|
|
var locations []Location
|
|
locations = append(locations, Location{Url: "a.com:8080"})
|
|
vc.Set("123", locations, time.Second)
|
|
ret, _ := vc.Get("123")
|
|
if ret == nil {
|
|
t.Fatal("Not found vid 123")
|
|
}
|
|
fmt.Printf("vid 123 locations = %v\n", ret)
|
|
time.Sleep(2 * time.Second)
|
|
ret, _ = vc.Get("123")
|
|
if ret != nil {
|
|
t.Fatal("Not found vid 123")
|
|
}
|
|
}
|
|
|
|
// a stale under-replicated result must not linger for the full cache TTL
|
|
func TestCachingDelete(t *testing.T) {
|
|
var vc VidCache
|
|
locations := []Location{{Url: "a.com:8080"}}
|
|
vc.Set("123", locations, time.Minute)
|
|
if ret, _ := vc.Get("123"); ret == nil {
|
|
t.Fatal("expected vid 123 to be cached")
|
|
}
|
|
vc.Delete("123")
|
|
if ret, _ := vc.Get("123"); ret != nil {
|
|
t.Fatal("expected vid 123 to be evicted after Delete")
|
|
}
|
|
// deleting a missing or out-of-range id must not panic
|
|
vc.Delete("123")
|
|
vc.Delete("4294967296")
|
|
}
|
|
|
|
// a single large volume id must not allocate an entry per id below it
|
|
func TestCachingLargeVolumeId(t *testing.T) {
|
|
var vc VidCache
|
|
locations := []Location{{Url: "a.com:8080"}}
|
|
vc.Set("32000000", locations, time.Minute)
|
|
if got := len(vc.cache); got != 1 {
|
|
t.Fatalf("expected 1 cached entry, got %d", got)
|
|
}
|
|
if ret, _ := vc.Get("32000000"); ret == nil {
|
|
t.Fatal("Not found vid 32000000")
|
|
}
|
|
|
|
// ids beyond uint32 are not real volume ids and must not wrap into the cache
|
|
vc.Set("4294967296", locations, time.Minute)
|
|
if got := len(vc.cache); got != 1 {
|
|
t.Fatalf("out-of-range id must not be cached, got %d entries", got)
|
|
}
|
|
if ret, _ := vc.Get("4294967296"); ret != nil {
|
|
t.Fatal("out-of-range vid 4294967296 should not be found")
|
|
}
|
|
}
|