mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
storage: red test, an unclean-stop upgrade leaves no unknown chunk after the pass
TestV11UncleanUpgradeLeavesNoUnknownAfterThePass: a v1.0.x store attached on the v1.1 format with no clean-stop proof (an unclean stop) opens with every whole local chunk unknown; the attach must then run the compare pass, which leaves none unknown: chunks equal to HEAD end published with HEAD's hash, a chunk that differs never with HEAD's hash. Fails on main: after 20 s all 16 chunks are still unknown, because the pass has no production caller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d14cf47fdf
commit
ccb9215f75
1 file changed
+86
@@ -0,0 +1,86 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/chunkkernel"
|
||||
)
|
||||
|
||||
// After an unclean stop there is no clean-stop proof, so the v1.0.x upgrade
|
||||
// leaves every whole local chunk unknown (U). The attach then runs the
|
||||
// compare pass, which leaves none unknown: a chunk equal to HEAD becomes
|
||||
// hash-known and published with HEAD's hash; a chunk that differs from HEAD
|
||||
// stays a candidate, never with HEAD's hash.
|
||||
//
|
||||
// HEAD names chunks 1, 2 and 3; the store holds chunks 1 and 2 as HEAD has
|
||||
// them and chunk 3 with other bytes; every other chunk is zero on both sides.
|
||||
//
|
||||
// The wait below is a bound on a pass over 16 chunks; once the pass reports
|
||||
// its completion, that signal can replace it.
|
||||
func TestV11UncleanUpgradeLeavesNoUnknownAfterThePass(t *testing.T) {
|
||||
withV11Format(t)
|
||||
s, _ := v11Store(t)
|
||||
if err := s.SetLayoutIdentity("claim-a", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
n := int(s.NumBlocks())
|
||||
head := make([]byte, n*ctBlockSize)
|
||||
for lba := ctChunkBlocks; lba < 4*ctChunkBlocks; lba++ { // chunks 1, 2, 3 in HEAD
|
||||
copy(head[lba*ctBlockSize:], makeBlock(ctBlockSize, byte(0x40+lba)))
|
||||
}
|
||||
for lba := ctChunkBlocks; lba < 4*ctChunkBlocks; lba++ {
|
||||
b := head[lba*ctBlockSize : (lba+1)*ctBlockSize]
|
||||
if lba >= 3*ctChunkBlocks { // chunk 3 differs locally
|
||||
b = makeBlock(ctBlockSize, byte(0x90+lba))
|
||||
}
|
||||
if _, err := s.Write(uint32(lba), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f := newFakeChunkRemote()
|
||||
f.seedHead(t, head, syncedPos(s), 1)
|
||||
cfg := ctConfig(2)
|
||||
cfg.Bitmap = nil // and no CleanStop: an unclean stop
|
||||
l := mustAttach(t, s, f, cfg).(*chunkLayerImpl)
|
||||
|
||||
if k := shadowKind(l, 1); k != chunkkernel.Unknown {
|
||||
t.Fatalf("the control needs an upgrade without a seed: chunk 1 opened %s, want U", k)
|
||||
}
|
||||
bound := 20 * time.Second
|
||||
for deadline := time.Now().Add(bound); ; time.Sleep(50 * time.Millisecond) {
|
||||
var unknown []uint64
|
||||
for c := uint64(0); c < l.numChunks; c++ {
|
||||
if shadowKind(l, c) == chunkkernel.Unknown {
|
||||
unknown = append(unknown, c)
|
||||
}
|
||||
}
|
||||
if len(unknown) == 0 {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("after %s chunks %v are still unknown: no compare pass ran over the upgraded store", bound, unknown)
|
||||
}
|
||||
}
|
||||
hashOf := func(c uint64) [32]byte {
|
||||
l.shadow.rec.mu.Lock()
|
||||
defer l.shadow.rec.mu.Unlock()
|
||||
return l.shadow.rec.hashes[c]
|
||||
}
|
||||
for _, c := range []uint64{1, 2} {
|
||||
first := int(c) * ctChunkBlocks * ctBlockSize
|
||||
want := sha256.Sum256(head[first : first+ctChunkBlocks*ctBlockSize])
|
||||
if k, h := shadowKind(l, c), hashOf(c); k != chunkkernel.HashPublished || h != want {
|
||||
t.Fatalf("chunk %d equal to HEAD ended %s with hash %x, want HP with HEAD's %x", c, k, h[:4], want[:4])
|
||||
}
|
||||
}
|
||||
first := 3 * ctChunkBlocks * ctBlockSize
|
||||
headSum := sha256.Sum256(head[first : first+ctChunkBlocks*ctBlockSize])
|
||||
if k, h := shadowKind(l, 3), hashOf(3); k == chunkkernel.HashPublished && h == headSum {
|
||||
t.Fatal("chunk 3, which differs from HEAD, ended published with HEAD's hash")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user