Files
seaweedfs/weed/storage/blockvol/adapter_test.go
T
Ping QiuandClaude Opus 4.6 80801b0fac feat: Phase 3 — performance tuning, iSCSI session refactor, store integration
Phase 3 delivers five checkpoints:

CP1 Engine Tuning: BlockVolConfig tunables, 256-shard DirtyMap, adaptive
group commit (low-watermark immediate flush), WAL pressure handling with
backpressure and ErrWALFull timeout.

CP2 iSCSI Session Refactor: RX/TX goroutine split with respCh (cap 64),
txLoop for serialized response writes, StatSN assignment modes. Login
phase stays single-goroutine; full-duplex after login.

CP3 Store Integration: BlockVolAdapter (iscsi.BlockDevice interface),
BlockVolumeStore management, BlockService in volume_server_block.go,
CLI flags (--block.listen/dir/iqn.prefix), sw-block-attach.sh helper.

CP5 Concurrency Hardening: WAL reuse guard (LSN validation in ReadLBA),
opsOutstanding counter with beginOp/endOp + Close drain, appendWithRetry
shared by WriteLBA and TrimLBA, flusher LSN guard in FlushOnce.

Bug fixes (P3-BUG-2–11): unbounded pending queue cap, Data-Out timeout,
flusher error logging, GroupCommitter panic recovery, Close vs concurrent
ops guard, target shutdown race, WAL-full retry vs Close, WRITE SAME(16)
for XFS, MODE SENSE(10) + VPD 0xB0/0xB2 for Linux kernel compatibility.

797 tests passing (517 engine + 280 iSCSI), go vet clean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 10:43:34 -08:00

71 lines
1.5 KiB
Go

package blockvol
import (
"path/filepath"
"testing"
"github.com/seaweedfs/seaweedfs/weed/storage/blockvol/iscsi"
)
func TestAdapterImplementsInterface(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "adapter_test.blk")
vol, err := CreateBlockVol(path, CreateOptions{
VolumeSize: 1024 * 4096, // 1024 blocks
BlockSize: 4096,
ExtentSize: 65536,
WALSize: 1 << 20,
})
if err != nil {
t.Fatal(err)
}
defer vol.Close()
adapter := NewBlockVolAdapter(vol)
// Verify it satisfies the interface.
var _ iscsi.BlockDevice = adapter
// Test basic operations through the adapter.
if adapter.BlockSize() != 4096 {
t.Fatalf("BlockSize: got %d, want 4096", adapter.BlockSize())
}
if adapter.VolumeSize() != 1024*4096 {
t.Fatalf("VolumeSize: got %d, want %d", adapter.VolumeSize(), 1024*4096)
}
if !adapter.IsHealthy() {
t.Fatal("expected healthy")
}
// Write and read back through adapter.
data := make([]byte, 4096)
for i := range data {
data[i] = 0xAB
}
if err := adapter.WriteAt(0, data); err != nil {
t.Fatal(err)
}
got, err := adapter.ReadAt(0, 4096)
if err != nil {
t.Fatal(err)
}
if len(got) != 4096 {
t.Fatalf("ReadAt length: got %d, want 4096", len(got))
}
if got[0] != 0xAB || got[4095] != 0xAB {
t.Fatal("data mismatch")
}
// SyncCache through adapter.
if err := adapter.SyncCache(); err != nil {
t.Fatal(err)
}
// Trim through adapter.
if err := adapter.Trim(0, 4096); err != nil {
t.Fatal(err)
}
}