mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test: restart the upgrade fence after a legacy publication
This commit is contained in:
1 parent
1b3a4b6a3e
commit
dd9ed22f0a
1 file changed
+57
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -151,3 +152,59 @@ func TestChunkStateUpgradeFailureNeverCompletesUntilReopen(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkStateUpgradeOldReaderPublicationRestartsTheFence(t *testing.T) {
|
||||
s, path := newMappedCheckpointStoreV3(t)
|
||||
oldPair := make([]byte, 2*slotSizeV3)
|
||||
if _, err := s.fd.ReadAt(oldPair, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// A crash after the first new slot leaves the old fallback readable.
|
||||
writes := 0
|
||||
s.v3.testBeforeSlotWrite = func() error {
|
||||
writes++
|
||||
if writes == 2 {
|
||||
return errors.New("crash before second slot")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := s.FenceChunkStateUpgrade(7); err == nil {
|
||||
t.Fatal("half fence succeeded")
|
||||
}
|
||||
_ = s.Close()
|
||||
// Model the old reader's metadata publication: it copies its old selected
|
||||
// descriptor (which has no marker) to both slots. It leaves map/WAL bytes
|
||||
// untouched. The actual legacy slot bytes were captured before the attempt.
|
||||
f, err := os.OpenFile(path, os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = f.WriteAt(oldPair, 0); err == nil {
|
||||
err = f.Sync()
|
||||
}
|
||||
closeErr := f.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if closeErr != nil {
|
||||
t.Fatal(closeErr)
|
||||
}
|
||||
next, err := openWALStoreV3MapInternalForTest(path, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer next.Close()
|
||||
if d := next.v3.pub.current(); d.ChunkStateFormat != 0 || d.LocalWorkEpoch != 0 {
|
||||
t.Fatal("new reader trusted the marker erased by an old publication")
|
||||
}
|
||||
// The page owner must rebuild from legacy presence before calling the
|
||||
// boundary again; the store must not remember completion in process memory.
|
||||
writes = 0
|
||||
next.v3.testBeforeSlotWrite = func() error { writes++; return nil }
|
||||
if err := next.FenceChunkStateUpgrade(7); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if writes != 2 {
|
||||
t.Fatalf("erased marker did not restart both-slot fence: %d writes", writes)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user