mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
test: write failover read files until every volume server backs one (#13391)
TestReadWithVolumeServerDown wrote three files and required each volume server to hold a chunk of one of them. When the mount starts before the master is elected, the first writes can all land on the volumes one server lacks, and the test stopped before stopping anything. Write three more at a time, up to twelve, until every server backs a file. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5f252ef863
commit
e16d6c7b11
2 files changed
+43
-11
No files matched your search
@@ -499,6 +499,26 @@ func (c *failoverCluster) FileIsOn(path, serverAddress string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// everyVolumeServerBacksOneOf reports whether each volume server holds a
|
||||
// chunk of at least one of the given files.
|
||||
func (c *failoverCluster) everyVolumeServerBacksOneOf(t *testing.T, names []string) bool {
|
||||
for i := range c.volumePorts {
|
||||
backed := false
|
||||
for _, name := range names {
|
||||
on, err := c.FileIsOn("/"+name, c.VolumeServerAddress(i))
|
||||
require.NoError(t, err, "resolve placement of %s", name)
|
||||
if on {
|
||||
backed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !backed {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *failoverCluster) masterAddress() string {
|
||||
return string(pb.NewServerAddress("127.0.0.1", c.masterPort, c.masterGrpcPort))
|
||||
}
|
||||
|
||||
@@ -140,16 +140,26 @@ func TestReadWithVolumeServerDown(t *testing.T) {
|
||||
|
||||
const fileSize = 8 << 20
|
||||
payloads := make(map[string][]byte)
|
||||
for i := 0; i < 3; i++ {
|
||||
name := fmt.Sprintf("readfile-%d", i)
|
||||
data := make([]byte, fileSize)
|
||||
_, err := rand.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(c.MountDir(0), name), data, 0644))
|
||||
payloads[name] = data
|
||||
var names []string
|
||||
// Placement decides which two of the three servers hold each volume, and
|
||||
// early writes can all land on the volumes one server lacks, so write
|
||||
// more files until every server backs one of them.
|
||||
for len(names) < 12 {
|
||||
for i := 0; i < 3; i++ {
|
||||
name := fmt.Sprintf("readfile-%d", len(names))
|
||||
data := make([]byte, fileSize)
|
||||
_, err := rand.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(c.MountDir(0), name), data, 0644))
|
||||
payloads[name] = data
|
||||
names = append(names, name)
|
||||
}
|
||||
// Let the filer commit the last chunks before anything is torn down.
|
||||
time.Sleep(2 * time.Second)
|
||||
if c.everyVolumeServerBacksOneOf(t, names) {
|
||||
break
|
||||
}
|
||||
}
|
||||
// Let the filer commit the last chunks before anything is torn down.
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
t.Logf("topology before chaos:\n%s", c.MasterGet("/dir/status?pretty=y"))
|
||||
|
||||
@@ -161,8 +171,10 @@ func TestReadWithVolumeServerDown(t *testing.T) {
|
||||
// earlier iteration has read, whose chunks the reader has not cached.
|
||||
name := ""
|
||||
for _, allowRead := range []bool{false, true} {
|
||||
for i := 0; i < 3 && name == ""; i++ {
|
||||
candidate := fmt.Sprintf("readfile-%d", i)
|
||||
for _, candidate := range names {
|
||||
if name != "" {
|
||||
break
|
||||
}
|
||||
if alreadyRead[candidate] && !allowRead {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user