Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
399 lines
14 KiB
Go
399 lines
14 KiB
Go
package erasure_coding
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/volume_info"
|
|
)
|
|
|
|
// readEcxSizeField returns the size field of the .ecx entry for needleId, or
|
|
// (false) if the id is absent. Entries are fixed-width (id, offset, size).
|
|
func readEcxSizeField(t *testing.T, ecxPath string, needleId types.NeedleId) (types.Size, bool) {
|
|
t.Helper()
|
|
data, err := os.ReadFile(ecxPath)
|
|
if err != nil {
|
|
t.Fatalf("read ecx: %v", err)
|
|
}
|
|
entry := types.NeedleIdSize + types.OffsetSize + types.SizeSize
|
|
for off := 0; off+entry <= len(data); off += entry {
|
|
id := types.BytesToNeedleId(data[off : off+types.NeedleIdSize])
|
|
if id == needleId {
|
|
return types.BytesToSize(data[off+types.NeedleIdSize+types.OffsetSize : off+entry]), true
|
|
}
|
|
}
|
|
return 0, false
|
|
}
|
|
|
|
func writeEcxEntries(t *testing.T, ecxPath string, ids []types.NeedleId) {
|
|
t.Helper()
|
|
var buf []byte
|
|
for i, id := range ids {
|
|
b := make([]byte, types.NeedleIdSize+types.OffsetSize+types.SizeSize)
|
|
types.NeedleIdToBytes(b[0:types.NeedleIdSize], id)
|
|
// A plausible non-zero offset/size; the fold only rewrites the size field.
|
|
types.OffsetToBytes(b[types.NeedleIdSize:types.NeedleIdSize+types.OffsetSize], types.ToOffset(int64((i+1)*1024)))
|
|
types.SizeToBytes(b[types.NeedleIdSize+types.OffsetSize:], types.Size(100))
|
|
buf = append(buf, b...)
|
|
}
|
|
if err := os.WriteFile(ecxPath, buf, 0644); err != nil {
|
|
t.Fatalf("write ecx: %v", err)
|
|
}
|
|
}
|
|
|
|
func packEcjIds(ids []types.NeedleId) []byte {
|
|
var buf []byte
|
|
for _, id := range ids {
|
|
b := make([]byte, types.NeedleIdSize)
|
|
types.NeedleIdToBytes(b, id)
|
|
buf = append(buf, b...)
|
|
}
|
|
return buf
|
|
}
|
|
|
|
// TestRebuildEcxFile_AppliesTombstonesAndRemovesJournal: a clean fold marks the
|
|
// journaled needle deleted in .ecx and removes the journal.
|
|
func TestRebuildEcxFile_AppliesTombstonesAndRemovesJournal(t *testing.T) {
|
|
base := filepath.Join(t.TempDir(), "vol")
|
|
writeEcxEntries(t, base+".ecx", []types.NeedleId{1, 2, 3})
|
|
if err := os.WriteFile(base+".ecj", packEcjIds([]types.NeedleId{2}), 0644); err != nil {
|
|
t.Fatalf("write ecj: %v", err)
|
|
}
|
|
|
|
if err := RebuildEcxFile(base); err != nil {
|
|
t.Fatalf("RebuildEcxFile: %v", err)
|
|
}
|
|
|
|
if _, err := os.Stat(base + ".ecj"); !os.IsNotExist(err) {
|
|
t.Errorf(".ecj should be removed after a clean fold, stat err=%v", err)
|
|
}
|
|
if sz, ok := readEcxSizeField(t, base+".ecx", 2); !ok || sz != types.TombstoneFileSize {
|
|
t.Errorf("needle 2 should be tombstoned in .ecx, got size=%d ok=%v", sz, ok)
|
|
}
|
|
for _, live := range []types.NeedleId{1, 3} {
|
|
if sz, ok := readEcxSizeField(t, base+".ecx", live); !ok || sz == types.TombstoneFileSize {
|
|
t.Errorf("needle %d should remain live, got size=%d ok=%v", live, sz, ok)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestRebuildEcxFile_TornJournalAborts: a journal whose tail is a partial record
|
|
// (e.g. interrupted append) must abort the fold and leave .ecj in place for a
|
|
// retry, rather than silently dropping the remaining tombstones before unlink.
|
|
func TestRebuildEcxFile_TornJournalAborts(t *testing.T) {
|
|
base := filepath.Join(t.TempDir(), "vol")
|
|
writeEcxEntries(t, base+".ecx", []types.NeedleId{1, 2, 3})
|
|
// One full id followed by a truncated trailing record.
|
|
torn := append(packEcjIds([]types.NeedleId{2}), []byte{0x01, 0x02, 0x03}...)
|
|
if err := os.WriteFile(base+".ecj", torn, 0644); err != nil {
|
|
t.Fatalf("write ecj: %v", err)
|
|
}
|
|
|
|
if err := RebuildEcxFile(base); err == nil {
|
|
t.Fatal("expected an error folding a torn journal, got nil")
|
|
}
|
|
if _, err := os.Stat(base + ".ecj"); err != nil {
|
|
t.Errorf(".ecj must be retained after a torn-journal abort, stat err=%v", err)
|
|
}
|
|
}
|
|
|
|
// TestRebuildEcxFile_NoJournalNoop: with no .ecj the fold is a no-op and does
|
|
// not error (idempotent re-run after a prior successful fold).
|
|
func TestRebuildEcxFile_NoJournalNoop(t *testing.T) {
|
|
base := filepath.Join(t.TempDir(), "vol")
|
|
writeEcxEntries(t, base+".ecx", []types.NeedleId{1, 2, 3})
|
|
before, _ := os.ReadFile(base + ".ecx")
|
|
|
|
if err := RebuildEcxFile(base); err != nil {
|
|
t.Fatalf("RebuildEcxFile with no journal: %v", err)
|
|
}
|
|
after, _ := os.ReadFile(base + ".ecx")
|
|
if len(before) != len(after) {
|
|
t.Errorf(".ecx changed despite no journal: %d -> %d bytes", len(before), len(after))
|
|
}
|
|
}
|
|
|
|
// makeRebuildInputs creates `present` equal-size input shard files of `size`
|
|
// bytes and one missing output file, returning slices sized to ctx.Total().
|
|
func makeRebuildInputs(t *testing.T, dir string, present, missingIdx int, size int) ([]bool, []*os.File, []*os.File) {
|
|
t.Helper()
|
|
ctx := NewDefaultECContext("", 0)
|
|
shardHasData := make([]bool, ctx.Total())
|
|
inputFiles := make([]*os.File, ctx.Total())
|
|
outputFiles := make([]*os.File, ctx.Total())
|
|
for i := 0; i < present; i++ {
|
|
p := filepath.Join(dir, "in"+ToExt(i))
|
|
if err := os.WriteFile(p, make([]byte, size), 0644); err != nil {
|
|
t.Fatalf("write input %d: %v", i, err)
|
|
}
|
|
f, err := os.Open(p)
|
|
if err != nil {
|
|
t.Fatalf("open input %d: %v", i, err)
|
|
}
|
|
t.Cleanup(func() { f.Close() })
|
|
inputFiles[i] = f
|
|
shardHasData[i] = true
|
|
}
|
|
outPath := filepath.Join(dir, "out"+ToExt(missingIdx))
|
|
of, err := os.OpenFile(outPath, os.O_CREATE|os.O_RDWR, 0644)
|
|
if err != nil {
|
|
t.Fatalf("open output: %v", err)
|
|
}
|
|
t.Cleanup(func() { of.Close() })
|
|
outputFiles[missingIdx] = of
|
|
shardHasData[missingIdx] = false
|
|
return shardHasData, inputFiles, outputFiles
|
|
}
|
|
|
|
// TestRebuildEcFiles_TruncatedInputErrorsWithoutPublishing: a truncated input
|
|
// shard must abort the rebuild before any output is written, rather than
|
|
// reconstructing over a zero-padded tail and publishing a corrupt shard.
|
|
func TestRebuildEcFiles_TruncatedInputErrorsWithoutPublishing(t *testing.T) {
|
|
dir := t.TempDir()
|
|
ctx := NewDefaultECContext("", 0)
|
|
const size = 4096
|
|
shardHasData, inputFiles, outputFiles := makeRebuildInputs(t, dir, ctx.Total()-1, ctx.Total()-1, size)
|
|
|
|
// Truncate one present input to half.
|
|
if err := os.Truncate(filepath.Join(dir, "in"+ToExt(5)), size/2); err != nil {
|
|
t.Fatalf("truncate: %v", err)
|
|
}
|
|
|
|
err := rebuildEcFiles(shardHasData, inputFiles, outputFiles, ctx)
|
|
if err == nil {
|
|
t.Fatal("expected an error on a truncated input shard, got nil")
|
|
}
|
|
if fi, _ := os.Stat(filepath.Join(dir, "out"+ToExt(ctx.Total()-1))); fi != nil && fi.Size() != 0 {
|
|
t.Errorf("output shard must not be published on a truncated input, got %d bytes", fi.Size())
|
|
}
|
|
}
|
|
|
|
// TestRebuildEcFiles_ZeroSizeInputsErrors: all-empty input shards must error
|
|
// rather than producing and publishing zero-length output shards.
|
|
func TestRebuildEcFiles_ZeroSizeInputsErrors(t *testing.T) {
|
|
dir := t.TempDir()
|
|
ctx := NewDefaultECContext("", 0)
|
|
shardHasData, inputFiles, outputFiles := makeRebuildInputs(t, dir, ctx.Total()-1, ctx.Total()-1, 0)
|
|
|
|
if err := rebuildEcFiles(shardHasData, inputFiles, outputFiles, ctx); err == nil {
|
|
t.Fatal("expected an error on zero-size input shards, got nil")
|
|
}
|
|
}
|
|
|
|
// TestRebuildEcFiles_HappyPathRebuildsByteIdentical: a real encode, drop one
|
|
// shard, rebuild, and confirm the regenerated shard is byte-identical. The tiny
|
|
// .dat exercises the sub-1MB final-block path (the guard must not false-positive
|
|
// on a legitimate short tail).
|
|
func TestRebuildEcFiles_HappyPathRebuildsByteIdentical(t *testing.T) {
|
|
dir := t.TempDir()
|
|
base := filepath.Join(dir, "vol")
|
|
ctx := NewDefaultECContext("", 0)
|
|
writeRandomDat(t, base, 7000)
|
|
|
|
if _, err := generateEcFiles(base, 256*1024, ErasureCodingLargeBlockSize, ErasureCodingSmallBlockSize, ctx); err != nil {
|
|
t.Fatalf("generateEcFiles: %v", err)
|
|
}
|
|
const dropped = 5
|
|
want, err := os.ReadFile(base + ToExt(dropped))
|
|
if err != nil {
|
|
t.Fatalf("read shard %d: %v", dropped, err)
|
|
}
|
|
if err := os.Remove(base + ToExt(dropped)); err != nil {
|
|
t.Fatalf("remove shard: %v", err)
|
|
}
|
|
|
|
if _, err := RebuildEcFiles(base, ctx, true); err != nil {
|
|
t.Fatalf("RebuildEcFiles: %v", err)
|
|
}
|
|
got, err := os.ReadFile(base + ToExt(dropped))
|
|
if err != nil {
|
|
t.Fatalf("read rebuilt shard: %v", err)
|
|
}
|
|
if string(got) != string(want) {
|
|
t.Errorf("rebuilt shard %d differs from original (%d vs %d bytes)", dropped, len(got), len(want))
|
|
}
|
|
}
|
|
|
|
// TestRebuildEcFiles_ZeroSizedShardRegeneratedInPlace: a zero-sized shard file
|
|
// (residue of a failed operation, issue 10730) must be excluded from the
|
|
// rebuild inputs and regenerated byte-identical over the empty file, instead
|
|
// of failing the whole rebuild with an input size mismatch.
|
|
func TestRebuildEcFiles_ZeroSizedShardRegeneratedInPlace(t *testing.T) {
|
|
dir := t.TempDir()
|
|
base := filepath.Join(dir, "vol")
|
|
ctx := NewDefaultECContext("", 0)
|
|
writeRandomDat(t, base, 7000)
|
|
|
|
if _, err := generateEcFiles(base, 256*1024, ErasureCodingLargeBlockSize, ErasureCodingSmallBlockSize, ctx); err != nil {
|
|
t.Fatalf("generateEcFiles: %v", err)
|
|
}
|
|
|
|
const emptied = 2
|
|
want, err := os.ReadFile(base + ToExt(emptied))
|
|
if err != nil {
|
|
t.Fatalf("read shard %d: %v", emptied, err)
|
|
}
|
|
if err := os.Truncate(base+ToExt(emptied), 0); err != nil {
|
|
t.Fatalf("truncate shard: %v", err)
|
|
}
|
|
|
|
generated, err := RebuildEcFiles(base, ctx, true)
|
|
if err != nil {
|
|
t.Fatalf("RebuildEcFiles with a zero-sized shard: %v", err)
|
|
}
|
|
found := false
|
|
for _, id := range generated {
|
|
if id == emptied {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("shard %d not reported as regenerated: %v", emptied, generated)
|
|
}
|
|
got, err := os.ReadFile(base + ToExt(emptied))
|
|
if err != nil {
|
|
t.Fatalf("read regenerated shard: %v", err)
|
|
}
|
|
if string(got) != string(want) {
|
|
t.Errorf("regenerated shard %d differs from original (%d vs %d bytes)", emptied, len(got), len(want))
|
|
}
|
|
}
|
|
|
|
// TestRebuildEcFiles_CustomRatioRebuildsByteIdentical: the same for a 9+3 ratio,
|
|
// confirming no 10+4 assumption leaks into the destructive rebuild path.
|
|
func TestRebuildEcFiles_CustomRatioRebuildsByteIdentical(t *testing.T) {
|
|
dir := t.TempDir()
|
|
base := filepath.Join(dir, "vol")
|
|
ctx := &ECContext{DataShards: 9, ParityShards: 3}
|
|
writeRandomDat(t, base, 9000)
|
|
|
|
if _, err := generateEcFiles(base, 256*1024, ErasureCodingLargeBlockSize, ErasureCodingSmallBlockSize, ctx); err != nil {
|
|
t.Fatalf("generateEcFiles: %v", err)
|
|
}
|
|
const dropped = 7
|
|
want, err := os.ReadFile(base + ToExt(dropped))
|
|
if err != nil {
|
|
t.Fatalf("read shard %d: %v", dropped, err)
|
|
}
|
|
if err := os.Remove(base + ToExt(dropped)); err != nil {
|
|
t.Fatalf("remove shard: %v", err)
|
|
}
|
|
|
|
if _, err := RebuildEcFiles(base, ctx, true); err != nil {
|
|
t.Fatalf("RebuildEcFiles: %v", err)
|
|
}
|
|
got, err := os.ReadFile(base + ToExt(dropped))
|
|
if err != nil {
|
|
t.Fatalf("read rebuilt shard: %v", err)
|
|
}
|
|
if string(got) != string(want) {
|
|
t.Errorf("rebuilt 9+3 shard %d differs (%d vs %d bytes)", dropped, len(got), len(want))
|
|
}
|
|
// No shard position beyond the 9+3 layout must have been created.
|
|
if _, err := os.Stat(base + ToExt(12)); err == nil {
|
|
t.Errorf("unexpected shard .ec12 for a 9+3 volume")
|
|
}
|
|
}
|
|
|
|
// With no .vif, the bitrot sidecar is the surviving record of the volume's
|
|
// geometry. Defaulting to 10+4 and the legacy block layout instead would
|
|
// reconstruct a custom-ratio volume from the wrong matrix — and would make the
|
|
// sidecar look like it disagrees, silently skipping every checksum check.
|
|
func TestRebuildEcFiles_ResolvesGeometryFromSidecarWithoutVif(t *testing.T) {
|
|
if !BitrotProtectionEnabled {
|
|
t.Skip("bitrot protection is compiled out")
|
|
}
|
|
dir := t.TempDir()
|
|
base := filepath.Join(dir, "vol")
|
|
ctx := &ECContext{DataShards: 12, ParityShards: 4}
|
|
writeRandomDat(t, base, 7000)
|
|
|
|
prot, err := WriteEcFiles(base, ctx)
|
|
if err != nil {
|
|
t.Fatalf("WriteEcFiles: %v", err)
|
|
}
|
|
if err := SaveBitrotSidecar(BitrotSidecarPath(base, 0), prot); err != nil {
|
|
t.Fatalf("save sidecar: %v", err)
|
|
}
|
|
// No .vif at all: the sidecar has to answer.
|
|
const dropped = 11
|
|
want, err := os.ReadFile(base + ToExt(dropped))
|
|
if err != nil {
|
|
t.Fatalf("read shard: %v", err)
|
|
}
|
|
if err := os.Remove(base + ToExt(dropped)); err != nil {
|
|
t.Fatalf("remove shard: %v", err)
|
|
}
|
|
|
|
// nil ctx: the production RPC's BackgroundECContext path.
|
|
if _, err := RebuildEcFiles(base, nil, false); err != nil {
|
|
t.Fatalf("RebuildEcFiles: %v", err)
|
|
}
|
|
got, err := os.ReadFile(base + ToExt(dropped))
|
|
if err != nil {
|
|
t.Fatalf("read rebuilt shard: %v", err)
|
|
}
|
|
if string(got) != string(want) {
|
|
t.Errorf("rebuilt shard %d differs; the rebuild used the wrong geometry", dropped)
|
|
}
|
|
// The 12+4 shards past the default ratio must still be there.
|
|
for _, id := range []int{14, 15} {
|
|
if _, err := os.Stat(base + ToExt(id)); err != nil {
|
|
t.Errorf("shard %d missing after rebuild: %v", id, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A split -dir/-dir.idx layout keeps the .vif with the index, and a multi-disk
|
|
// server may leave this disk holding only shards. Probing just the data base
|
|
// resolves such a volume to the default ratio and the legacy block layout.
|
|
func TestRebuildEcFiles_FindsVifInAnAdditionalDir(t *testing.T) {
|
|
dataDir := t.TempDir()
|
|
idxDir := t.TempDir()
|
|
base := filepath.Join(dataDir, "vol")
|
|
ctx := &ECContext{DataShards: 12, ParityShards: 4}
|
|
writeRandomDat(t, base, 7000)
|
|
|
|
if _, err := WriteEcFiles(base, ctx); err != nil {
|
|
t.Fatalf("WriteEcFiles: %v", err)
|
|
}
|
|
// The volume's .vif lives with the index, not the shards.
|
|
if err := volume_info.SaveVolumeInfo(filepath.Join(idxDir, "vol")+".vif", &volume_server_pb.VolumeInfo{
|
|
Version: uint32(needle.GetCurrentVersion()),
|
|
EcShardConfig: &volume_server_pb.EcShardConfig{
|
|
DataShards: 12, ParityShards: 4, BlockSize: ctx.BlockSize,
|
|
},
|
|
}); err != nil {
|
|
t.Fatalf("save .vif: %v", err)
|
|
}
|
|
|
|
const dropped = 11
|
|
want, err := os.ReadFile(base + ToExt(dropped))
|
|
if err != nil {
|
|
t.Fatalf("read shard: %v", err)
|
|
}
|
|
if err := os.Remove(base + ToExt(dropped)); err != nil {
|
|
t.Fatalf("remove shard: %v", err)
|
|
}
|
|
|
|
if _, err := RebuildEcFiles(base, nil, true, idxDir); err != nil {
|
|
t.Fatalf("RebuildEcFiles: %v", err)
|
|
}
|
|
got, err := os.ReadFile(base + ToExt(dropped))
|
|
if err != nil {
|
|
t.Fatalf("read rebuilt shard: %v", err)
|
|
}
|
|
if string(got) != string(want) {
|
|
t.Errorf("rebuilt shard %d differs; the rebuild used the wrong geometry", dropped)
|
|
}
|
|
for _, id := range []int{14, 15} {
|
|
if _, err := os.Stat(base + ToExt(id)); err != nil {
|
|
t.Errorf("shard %d missing after rebuild: %v", id, err)
|
|
}
|
|
}
|
|
}
|