mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test: require verify options and stable HEAD observations
This commit is contained in:
1 parent
b0b0a6ebb7
commit
56286ab004
2 files changed
+52
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
@@ -227,3 +228,15 @@ func TestOpsChunk_VerifyStartCheckIsBoundedByTheTimeout(t *testing.T) {
|
||||
t.Errorf("verify: exit %d, out %q; want a retryable remote_unavailable refusal", code, out.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpsChunkVerifyRefusesUnsupportedFlagsBeforeDial(t *testing.T) {
|
||||
old := dialChunkFiler
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return nil, nil, fmt.Errorf("unsupported option reached dial") }
|
||||
t.Cleanup(func(){ dialChunkFiler = old })
|
||||
for _, arg := range []string{"--snapshot=s1", "--all-snapshots", "--all-snapshots=false", "--concurrency=1", "--bytes-per-sec=0"} {
|
||||
t.Run(arg, func(t *testing.T){
|
||||
code,out,_ := runChunk("verify", "--volume=v1", "--chunk-filer=f:1", arg)
|
||||
if code != 2 || chunkErrorOut(t,out).Code != codeBadRequestCLI || !strings.Contains(out,"unsupported") { t.Fatalf("exit=%d out=%s",code,out) }
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -152,3 +152,42 @@ func snapshotStore(fb filerBlobs) string {
|
||||
puts, _, stored := fb.fakeBlobs.counts()
|
||||
return fmt.Sprintf("puts=%d stored=%d %s", puts, stored, strings.Join(keys, ","))
|
||||
}
|
||||
|
||||
type verifyChangingHead struct { filerBlobs; reads int; mode string }
|
||||
func (f *verifyChangingHead) LookupEntry(ctx context.Context, dir, name string) (*filerpb.Entry,error) {
|
||||
e,err := f.filerBlobs.LookupEntry(ctx,dir,name)
|
||||
if name != layout.HeadName || err != nil { return e,err }
|
||||
f.reads++
|
||||
e=proto.Clone(e).(*filerpb.Entry)
|
||||
if f.reads >= 2 {
|
||||
switch f.mode {
|
||||
case "advance": e.Extended[layoutGen]=[]byte("2")
|
||||
case "absent": return nil,ErrNotFound
|
||||
case "error": return nil,fmt.Errorf("injected confirmation failure")
|
||||
case "unknown": delete(e.Extended,layoutGen)
|
||||
}
|
||||
}
|
||||
return e,nil
|
||||
}
|
||||
func TestVerifyLayoutRequiresStableHeadForMissingAndOrphans(t *testing.T) {
|
||||
for _,mode := range []string{"stable","advance","absent","error","unknown"} {
|
||||
t.Run(mode,func(t *testing.T){
|
||||
fb,id:=verifyFixtureVolume(t)
|
||||
hp:=path.Join("/blocks",layout.VolumeDir("v",id),layout.HeadName)
|
||||
fb.fakeFiler.entries[hp].Extended=map[string][]byte{layoutKind:[]byte("head"),layoutVolume:[]byte(id.String()),layoutGen:[]byte("1")}
|
||||
c:=layout.NameChunk(0,[]byte(strings.Repeat("a",64)))
|
||||
delete(fb.fakeFiler.entries,path.Join("/blocks",layout.VolumeDir("v",id),c.Path()))
|
||||
extra:=layout.NameChunk(9,[]byte("orphan"))
|
||||
putFile(t,fb.fakeFiler,path.Join("/blocks",layout.VolumeDir("v",id),extra.Path()),[]byte("orphan"))
|
||||
f:=&verifyChangingHead{filerBlobs:fb,mode:mode}
|
||||
r,err:=VerifyLayout(context.Background(),f,"/blocks",layout.VolumeDir("v",id),layout.VerifyOptions{Orphans:true})
|
||||
if err != nil { t.Fatal(err) }
|
||||
if mode=="stable" {
|
||||
if !r.Complete || len(r.Findings)!=2 || f.reads!=2 { t.Fatalf("stable: %+v reads=%d",r,f.reads) }
|
||||
} else {
|
||||
for _,finding:=range r.Findings { if finding.Class==layout.FindMissing || finding.Class==layout.FindOrphan { t.Fatalf("unstable HEAD published finding: %+v reads=%d",r,f.reads) } }
|
||||
if r.Complete || r.OrphansChecked || r.Incomplete=="" { t.Fatalf("unstable pass looks complete: %+v",r) }
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user