mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d852d63e1 | ||
|
|
b7631e6a3b |
No files matched your search
@@ -0,0 +1,69 @@
|
||||
package layout
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// pausedAfterWindow is the store as a paused adopter sees it: its first HEAD
|
||||
// read returns the HEAD of that moment, and then, before the adopter acts on
|
||||
// it, the rest of the cluster moves on (pause).
|
||||
type pausedAfterWindow struct {
|
||||
*chainStore
|
||||
reads int
|
||||
pause func()
|
||||
}
|
||||
|
||||
func (s *pausedAfterWindow) ReadHead(ctx context.Context) (Head, bool, error) {
|
||||
h, found, err := s.chainStore.ReadHead(ctx)
|
||||
s.reads++
|
||||
if s.reads == 1 && s.pause != nil {
|
||||
s.pause()
|
||||
}
|
||||
return h, found, err
|
||||
}
|
||||
|
||||
// An adopter that passed its delete-intent window and then paused must not
|
||||
// re-tag the page once the window has moved on. During its pause a cleaner
|
||||
// pass moved the HEAD generation, the unlinked page was deleted, and another
|
||||
// executor of the same operation staged it again at the new base. Acting on
|
||||
// its stale window, the adopter would take over that new executor's page
|
||||
// under the old base's writer tag; it must refuse instead and leave the page
|
||||
// as the new executor staged it.
|
||||
func TestAPausedAdopterDoesNotRetagAPageStagedAgainAfterItsWindow(t *testing.T) {
|
||||
s, c, p := deleteIntentFixture(t)
|
||||
ctx := context.Background()
|
||||
base := s.h.Gen
|
||||
if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rel, err := c.Ref.Path()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paused := &pausedAfterWindow{chainStore: s, pause: func() {
|
||||
// A cleaner pass (two HEAD generations) removes the unlinked page,
|
||||
// then another executor stages it again at the new base.
|
||||
s.h.Gen = base + 2
|
||||
delete(s.objs, s.full(rel))
|
||||
if _, err := StageSnapshotDeletePage(ctx, s, base+2, p); err != nil {
|
||||
t.Errorf("the second executor's staging: %v", err)
|
||||
}
|
||||
}}
|
||||
adoptErr := adoptDeleteIntentPage(ctx, paused, s.volume, base, c.Ref)
|
||||
|
||||
meta, found, err := s.Stat(ctx, rel)
|
||||
if err != nil || !found {
|
||||
t.Fatalf("stat the page: %v %v", found, err)
|
||||
}
|
||||
if meta.Session != p.Producer || meta.Mark != "" {
|
||||
t.Fatalf("the paused adopter re-tagged the page staged at the new base: tags %+v (adopt: %v), want the second executor's %q", meta, adoptErr, p.Producer)
|
||||
}
|
||||
if adoptErr == nil {
|
||||
t.Fatal("the paused adopter acted on a window that had moved on: want a refusal")
|
||||
}
|
||||
if !errors.Is(adoptErr, ErrPrecondition) && !errors.Is(adoptErr, ErrBusy) {
|
||||
t.Fatalf("the paused adopter was refused with %v, want ErrPrecondition or ErrBusy", adoptErr)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package chunkstore
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
)
|
||||
|
||||
// betweenLookupAndUpdate runs before, once, ahead of the first UpdateEntry:
|
||||
// what other writers do while a stale one is between its lookup and its
|
||||
// conditional update.
|
||||
type betweenLookupAndUpdate struct {
|
||||
Filer
|
||||
once sync.Once
|
||||
before func()
|
||||
}
|
||||
|
||||
func (f *betweenLookupAndUpdate) UpdateEntry(ctx context.Context, dir string, e *filerpb.Entry, expected map[string][]byte) error {
|
||||
f.once.Do(f.before)
|
||||
return f.Filer.UpdateEntry(ctx, dir, e, expected)
|
||||
}
|
||||
|
||||
// A stale metadata change (a delete-intent page's adoption by an executor
|
||||
// that paused between its lookup and its update) must not write the entry it
|
||||
// looked up over an object that was deleted and created again with the same
|
||||
// tags in between: the update would put the deleted object's chunk list on
|
||||
// the new entry, and the filer frees the new entry's chunks.
|
||||
func TestAStaleMetadataChangeDoesNotOverwriteARecreatedObject(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
f, b := newFakeFiler(), newFakeBlobs()
|
||||
var id layout.VolumeID
|
||||
for i := range id {
|
||||
id[i] = 0x30 + byte(i)
|
||||
}
|
||||
others, err := NewLayoutStore(f, b, "/vol", id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hooked := &betweenLookupAndUpdate{Filer: f}
|
||||
stale, err := NewLayoutStore(hooked, b, "/vol", id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data := bytes.Repeat([]byte{0x5a}, 4096)
|
||||
rel := layout.NameChunk(1, data).Path()
|
||||
dir, name, err := others.object(rel)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fidOf := func() string {
|
||||
t.Helper()
|
||||
e, err := f.LookupEntry(ctx, dir, name)
|
||||
if err != nil || len(e.Chunks) != 1 {
|
||||
t.Fatalf("lookup %s: %+v %v", rel, e, err)
|
||||
}
|
||||
return e.Chunks[0].FileId
|
||||
}
|
||||
|
||||
if err := others.Create(ctx, rel, data, "producer-1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
first := fidOf()
|
||||
meta, found, err := others.Stat(ctx, rel)
|
||||
if err != nil || !found {
|
||||
t.Fatalf("stat: %v %v", found, err)
|
||||
}
|
||||
var second string
|
||||
hooked.before = func() {
|
||||
// While the stale writer is between lookup and update: a cleaner
|
||||
// marks and deletes the object, and another executor of the same
|
||||
// operation creates it again with the same producer tag.
|
||||
if err := others.Mark(ctx, rel, meta, "clean-1"); err != nil {
|
||||
t.Errorf("mark: %v", err)
|
||||
}
|
||||
if err := others.DeleteMarked(ctx, rel, "clean-1"); err != nil {
|
||||
t.Errorf("delete: %v", err)
|
||||
}
|
||||
if err := others.Create(ctx, rel, data, "producer-1"); err != nil {
|
||||
t.Errorf("re-create: %v", err)
|
||||
}
|
||||
second = fidOf()
|
||||
}
|
||||
reuseErr := stale.Reuse(ctx, rel, meta, "writer-1")
|
||||
|
||||
if second == "" || second == first {
|
||||
t.Fatalf("fixture: the object was not re-created with a new chunk (first %s, second %s)", first, second)
|
||||
}
|
||||
if got := fidOf(); got != second {
|
||||
t.Fatalf("the stale update wrote the deleted object's chunk %s over the re-created object's %s (Reuse: %v)", got, second, reuseErr)
|
||||
}
|
||||
if !errors.Is(reuseErr, layout.ErrPrecondition) {
|
||||
t.Fatalf("the stale update over a re-created object answered %v, want ErrPrecondition", reuseErr)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user