mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
test(durable): exercise mapped v3 stores through actual provider
This commit is contained in:
1 parent
52f8b7417f
commit
71e70dabaf
4 files changed
+172
-2
No files matched your search
@@ -180,6 +180,10 @@ type DurableProvider struct {
|
||||
// volume's handle and layer are resolved.
|
||||
testAfterChunkResolve func()
|
||||
|
||||
// testWALStoreFactory selects a dark store only in provider caller controls.
|
||||
// No production option, flag or environment variable installs it.
|
||||
testWALStoreFactory func(path string, create bool) (*storage.WALStore, error)
|
||||
|
||||
// walstore-chunk: closeCtx ends with Close and cancels in-flight
|
||||
// remote attachment; inflight counts RecoverVolume calls admitted
|
||||
// before Close, which Close waits for before closing any store.
|
||||
@@ -668,7 +672,13 @@ func (p *DurableProvider) openExisting(volumeID, path string, impl ImplName) (*v
|
||||
var s storage.LogicalStorage
|
||||
switch impl {
|
||||
case ImplWALStore, ImplWALStoreChunk:
|
||||
ws, err := storage.OpenWALStore(path)
|
||||
var ws *storage.WALStore
|
||||
var err error
|
||||
if p.testWALStoreFactory != nil {
|
||||
ws, err = p.testWALStoreFactory(path, false)
|
||||
} else {
|
||||
ws, err = storage.OpenWALStore(path)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("durable: OpenWALStore %s: %w", path, err)
|
||||
}
|
||||
@@ -714,7 +724,13 @@ func (p *DurableProvider) createFresh(volumeID, path string, impl ImplName) (*vo
|
||||
var s storage.LogicalStorage
|
||||
switch impl {
|
||||
case ImplWALStore, ImplWALStoreChunk:
|
||||
ws, err := storage.CreateWALStore(path, p.cfg.NumBlocks, p.cfg.BlockSize)
|
||||
var ws *storage.WALStore
|
||||
var err error
|
||||
if p.testWALStoreFactory != nil {
|
||||
ws, err = p.testWALStoreFactory(path, true)
|
||||
} else {
|
||||
ws, err = storage.CreateWALStore(path, p.cfg.NumBlocks, p.cfg.BlockSize)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("durable: CreateWALStore %s: %w", path, err)
|
||||
}
|
||||
|
||||
@@ -299,6 +299,10 @@ func (p *DurableProvider) newChunkLayer(ctx context.Context, volumeID string, h
|
||||
return nil
|
||||
},
|
||||
}
|
||||
if p.testWALStoreFactory != nil {
|
||||
// Dark mapped caller controls must not rely on the legacy C11 sidecar.
|
||||
cfg.Bitmap = nil
|
||||
}
|
||||
if !h.fresh {
|
||||
// An existing local volume is this holder's image only while HEAD is
|
||||
// still this holder's publication. Another holder's HEAD means the
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
//go:build swblock_format_v3_test
|
||||
|
||||
package durable
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
type formatV3View struct{}
|
||||
|
||||
func (formatV3View) Projection() frontend.Projection {
|
||||
return frontend.Projection{VolumeID: "v1", ReplicaID: "r1", Epoch: 3, EndpointVersion: 1, Healthy: true}
|
||||
}
|
||||
|
||||
func mappedProviderV3(t *testing.T, root string, remote storage.ChunkRemote) *DurableProvider {
|
||||
t.Helper()
|
||||
p, err := NewDurableProvider(ProviderConfig{
|
||||
Impl: ImplWALStoreChunk, StorageRoot: root, NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 4,
|
||||
WALRecoveryTestDisableFlusher: true,
|
||||
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil },
|
||||
}, formatV3View{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = p.Close() })
|
||||
p.testWALStoreFactory = func(path string, create bool) (*storage.WALStore, error) {
|
||||
if create {
|
||||
return storage.CreateMappedWALStoreV3Test(path, 64, 4096, 4)
|
||||
}
|
||||
return storage.OpenMappedWALStoreV3Test(path)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func TestDurableProviderV3_MappedCheckpointCaptureAndReopen(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
root := t.TempDir()
|
||||
remote := storage.NewMemChunkRemote()
|
||||
p := mappedProviderV3(t, root, remote)
|
||||
st, err := p.EnsureStorage("v1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = p.RecoverVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b := p.Backend("v1")
|
||||
data := bytes.Repeat([]byte{0x57}, 4096)
|
||||
if n, err := b.Write(ctx, 5*4096, data); err != nil || n != len(data) {
|
||||
t.Fatalf("Write: %d %v", n, err)
|
||||
}
|
||||
if err = b.Sync(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = storage.FlushMappedWALStoreV3Test(st.(*storage.WALStore)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = p.CaptureVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check := func(want []byte) {
|
||||
t.Helper()
|
||||
head, e := remote.GetHead(ctx)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
ref, ok := head.Chunks[1]
|
||||
if !ok {
|
||||
t.Fatal("capture omitted checkpointed chunk")
|
||||
}
|
||||
chunk, e := remote.Get(ctx, ref.Key)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if !bytes.Equal(chunk[4096:8192], want) {
|
||||
t.Fatal("published chunk bytes differ")
|
||||
}
|
||||
}
|
||||
check(data)
|
||||
raw, err := os.ReadFile(p.volumePath("v1"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if binary.LittleEndian.Uint32(raw[12:16]) != 3 {
|
||||
t.Fatal("provider did not open impl3")
|
||||
}
|
||||
if _, err = os.Stat(p.volumePath("v1") + ".chunkbitmap"); !os.IsNotExist(err) {
|
||||
t.Fatalf("legacy bitmap exists: %v", err)
|
||||
}
|
||||
if err = p.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p2 := mappedProviderV3(t, root, remote)
|
||||
st2, err := p2.EnsureStorage("v1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = p2.RecoverVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b2 := p2.Backend("v1")
|
||||
got := make([]byte, 4096)
|
||||
if n, err := b2.Read(ctx, 5*4096, got); err != nil || n != len(got) || !bytes.Equal(got, data) {
|
||||
t.Fatalf("reopen read %d %v equal=%v", n, err, bytes.Equal(got, data))
|
||||
}
|
||||
next := bytes.Repeat([]byte{0x93}, 4096)
|
||||
if _, err = b2.Write(ctx, 5*4096, next); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b2.Sync(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = storage.FlushMappedWALStoreV3Test(st2.(*storage.WALStore)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before := remote.Puts()
|
||||
if _, err = p2.CaptureVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if remote.Puts()-before != 1 {
|
||||
t.Fatalf("incremental capture uploaded %d chunks", remote.Puts()-before)
|
||||
}
|
||||
check(next)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//go:build swblock_format_v3_test
|
||||
|
||||
package storage
|
||||
|
||||
// CreateMappedWALStoreV3Test is available only to tagged cross-package caller
|
||||
// controls. Production Create/Open remain unchanged until the activation gate.
|
||||
func CreateMappedWALStoreV3Test(path string, blocks, blockSize, chunkBlocks uint32) (*WALStore, error) {
|
||||
return createMappedWALStoreV3ForTest(path, blocks, blockSize, 1<<20, WModeLagged, uint64(chunkBlocks))
|
||||
}
|
||||
|
||||
func OpenMappedWALStoreV3Test(path string) (*WALStore, error) {
|
||||
return openWALStoreV3ForTest(path)
|
||||
}
|
||||
|
||||
func FlushMappedWALStoreV3Test(s *WALStore) error {
|
||||
return s.flusher.flushOnce()
|
||||
}
|
||||
Reference in new issue
Block a user