mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test: prepare versioned manifests for catalog caller fixtures
This commit is contained in:
1 parent
ba3db132b0
commit
a8eab7b361
7 files changed
+114
-12
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
type manifestFixtureFiler struct {
|
||||
chunkstore.Filer
|
||||
mu sync.Mutex
|
||||
blobs map[string][]byte
|
||||
}
|
||||
|
||||
func newManifestFixtureFiler(f chunkstore.Filer) *manifestFixtureFiler {
|
||||
return &manifestFixtureFiler{Filer: f, blobs: map[string][]byte{}}
|
||||
}
|
||||
|
||||
func (f *manifestFixtureFiler) Put(_ context.Context, b []byte) (string, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
id := fmt.Sprintf("fixture-%d", len(f.blobs))
|
||||
f.blobs[id] = append([]byte(nil), b...)
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (f *manifestFixtureFiler) Get(_ context.Context, id string) ([]byte, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
b, ok := f.blobs[id]
|
||||
if !ok {
|
||||
return nil, chunkstore.ErrNotFound
|
||||
}
|
||||
return append([]byte(nil), b...), nil
|
||||
}
|
||||
|
||||
func prepareFixtureHead(t *testing.T, f *manifestFixtureFiler, h storage.ChunkHead) storage.ChunkHead {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
r, err := chunkstore.NewChunkRemote(f, f, defaultChunkPathCLI+"/v1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h, intents, err := r.PrepareManifest(ctx, storage.ChunkHead{}, h, 8*4096)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// These fixtures hand the completed cut directly to the catalog; the
|
||||
// snapshot/fork operations establish their own reachability intents.
|
||||
for _, id := range intents {
|
||||
if err := r.DeleteIntent(ctx, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return h
|
||||
}
|
||||
@@ -41,10 +41,11 @@ func (f *failingFiler) UpdateEntry(ctx context.Context, dir string, e *filerpb.E
|
||||
func TestOpsChunk_RetainReportsPartialProgress(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ff := &failingFiler{MemFiler: chunkstore.NewMemFiler()}
|
||||
fm := newManifestFixtureFiler(ff)
|
||||
prev := dialChunkFiler
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return ff, func() error { return nil }, nil }
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return fm, func() error { return nil }, nil }
|
||||
t.Cleanup(func() { dialChunkFiler = prev })
|
||||
cat, err := chunkstore.NewCatalog(ff, defaultChunkPathCLI)
|
||||
cat, err := chunkstore.NewCatalog(fm, defaultChunkPathCLI)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -54,6 +55,7 @@ func TestOpsChunk_RetainReportsPartialProgress(t *testing.T) {
|
||||
base := time.Now().Add(-48 * time.Hour)
|
||||
head := storage.ChunkHead{Gen: 2, Epoch: 1, Holder: "s1/r1", RemoteLSN: 42, State: storage.ChunkHeadActive,
|
||||
Chunks: map[uint64]storage.ChunkRef{0: {Key: "chunks/e1/c0/k"}}}
|
||||
head = prepareFixtureHead(t, fm, head)
|
||||
for i := 0; i < 4; i++ {
|
||||
at := base.Add(time.Duration(i) * time.Minute)
|
||||
cat.SetClock(func() time.Time { return at })
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestOpsChunk_SnapshotPinAndExpires(t *testing.T) {
|
||||
// dry-run, apply, and see the accounting follow.
|
||||
func TestOpsChunk_UsageAndRetain(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mem := chunkstore.NewMemFiler()
|
||||
mem := newManifestFixtureFiler(chunkstore.NewMemFiler())
|
||||
prev := dialChunkFiler
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return mem, func() error { return nil }, nil }
|
||||
t.Cleanup(func() { dialChunkFiler = prev })
|
||||
@@ -59,6 +59,7 @@ func TestOpsChunk_UsageAndRetain(t *testing.T) {
|
||||
cat.SetClock(func() time.Time { return old })
|
||||
head := storage.ChunkHead{Gen: 2, Epoch: 1, Holder: "s1/r1", RemoteLSN: 42, State: storage.ChunkHeadActive,
|
||||
Chunks: map[uint64]storage.ChunkRef{0: {Key: "chunks/e1/c0/k"}}}
|
||||
head = prepareFixtureHead(t, mem, head)
|
||||
for i := 0; i < 5; i++ {
|
||||
if _, err := cat.CreateSnapshot(ctx, "v1", chunkstore.SnapshotRequest{Name: fmt.Sprintf("s%d", i), RequestID: fmt.Sprintf("r%d", i), Class: chunkstore.SnapshotClassSemantic}, head); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// either is null when it does not exist (B9 W2 appendix).
|
||||
func TestOpsChunk_Show(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mem := chunkstore.NewMemFiler()
|
||||
mem := newManifestFixtureFiler(chunkstore.NewMemFiler())
|
||||
prev := dialChunkFiler
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return mem, func() error { return nil }, nil }
|
||||
t.Cleanup(func() { dialChunkFiler = prev })
|
||||
@@ -27,6 +27,7 @@ func TestOpsChunk_Show(t *testing.T) {
|
||||
}
|
||||
head := storage.ChunkHead{Gen: 2, Epoch: 1, Holder: "s1/r1", RemoteLSN: 42, State: storage.ChunkHeadActive,
|
||||
Chunks: map[uint64]storage.ChunkRef{0: {Key: "chunks/e1/c0/k"}}}
|
||||
head = prepareFixtureHead(t, mem, head)
|
||||
if _, err := cat.CreateSnapshot(ctx, "v1", chunkstore.SnapshotRequest{Name: "s1", RequestID: "r"}, head); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -157,6 +157,15 @@ func TestOpsChunk_FilerCommands(t *testing.T) {
|
||||
}
|
||||
head := storage.ChunkHead{Gen: 2, Epoch: 1, Holder: "r1", RemoteLSN: 42, State: storage.ChunkHeadActive,
|
||||
Chunks: map[uint64]storage.ChunkRef{0: {Key: "chunks/e1/c0/k"}}}
|
||||
manifestMem := newManifestFixtureFiler(mem)
|
||||
cat, err = chunkstore.NewCatalog(manifestMem, defaultChunkPathCLI)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) {
|
||||
return manifestMem, func() error { return nil }, nil
|
||||
}
|
||||
head = prepareFixtureHead(t, manifestMem, head)
|
||||
if _, err := cat.CreateSnapshot(ctx, "v1", chunkstore.SnapshotRequest{Name: "s1", RequestID: "r"}, head); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -449,13 +449,7 @@ func headEntry(h storage.ChunkHead) (*filerpb.Entry, error) {
|
||||
if len(h.Chunks) != 0 {
|
||||
return nil, errors.New("chunkstore: data HEAD requires a segmented manifest and geometry")
|
||||
}
|
||||
doc.Chunks = make(map[uint64]refDoc, len(h.Chunks))
|
||||
for idx, ref := range h.Chunks {
|
||||
if ref.Key == "" {
|
||||
return nil, fmt.Errorf("chunkstore: HEAD chunk %d has no key", idx)
|
||||
}
|
||||
doc.Chunks[idx] = refDoc{Key: ref.Key, SHA256: hex.EncodeToString(ref.SHA256[:])}
|
||||
}
|
||||
doc.Chunks = map[uint64]refDoc{}
|
||||
}
|
||||
if h.Segments != nil {
|
||||
if err := validateRoot(h); err != nil {
|
||||
|
||||
@@ -3,7 +3,9 @@ package volume
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
@@ -19,6 +21,30 @@ type fakeChunkProvider struct {
|
||||
lastMin uint64
|
||||
}
|
||||
|
||||
type adapterManifestFiler struct {
|
||||
chunkstore.Filer
|
||||
mu sync.Mutex
|
||||
blobs map[string][]byte
|
||||
}
|
||||
|
||||
func (f *adapterManifestFiler) Put(_ context.Context, b []byte) (string, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
id := fmt.Sprintf("fixture-%d", len(f.blobs))
|
||||
f.blobs[id] = append([]byte(nil), b...)
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (f *adapterManifestFiler) Get(_ context.Context, id string) ([]byte, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
b, ok := f.blobs[id]
|
||||
if !ok {
|
||||
return nil, chunkstore.ErrNotFound
|
||||
}
|
||||
return append([]byte(nil), b...), nil
|
||||
}
|
||||
|
||||
func (f *fakeChunkProvider) CutVolume(_ context.Context, _ string, minLSN uint64) (storage.ChunkCutResult, error) {
|
||||
f.cuts++
|
||||
f.lastMin = minLSN
|
||||
@@ -36,8 +62,17 @@ func adapterFixture(t *testing.T) (*fakeChunkProvider, ChunkControl) {
|
||||
t.Helper()
|
||||
head := storage.ChunkHead{Gen: 3, Epoch: 2, Holder: "r1", RemoteLSN: 9, State: storage.ChunkHeadActive,
|
||||
Chunks: map[uint64]storage.ChunkRef{0: {Key: "chunks/e2/c0/k1"}, 5: {Key: "chunks/e2/c5/k2"}}}
|
||||
f := &adapterManifestFiler{Filer: chunkstore.NewMemFiler(), blobs: map[string][]byte{}}
|
||||
r, err := chunkstore.NewChunkRemote(f, f, "/swblock/chunks/v1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
head, _, err = r.PrepareManifest(context.Background(), storage.ChunkHead{}, head, 8*4096)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fp := &fakeChunkProvider{cut: storage.ChunkCutResult{H: 9, Head: head}}
|
||||
cat, err := chunkstore.NewCatalog(chunkstore.NewMemFiler(), "/swblock/chunks")
|
||||
cat, err := chunkstore.NewCatalog(f, "/swblock/chunks")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user