mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* volume: report the encode run in VolumeEcShardsInfo Go and Rust volume servers now fill EcShardConfig.encode_ts_ns from the mounted EC volume's .vif, next to the block layout they already report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * erasure_coding: keep the source when holders serve different encode runs VerifyShardsAcrossServers records each holder's encode run, and RequireAgreedEncodeRun fails when holders that report one disagree. The encoder checks it before deleting the source volume, so a shard set that only looks complete by shard ids does not replace the source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * erasure_coding: refuse a holder that reports more than one encode run A holder whose disks serve shards of different encode runs reports MixedEncodeRuns, and RequireAgreedEncodeRun fails on it even when no other holder answers or every other holder agrees on one run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: report mixed encode runs across local disks in VolumeEcShardsInfo The reply listed shards from every disk under the first disk's encode run. When the shard-bearing disks of a volume hold different nonzero runs, Go and Rust volume servers now report MixedEncodeRuns instead, so the source-deletion check sees the conflict. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: refuse an EC shard copy of another encode run than the mounted one VolumeEcShardsCopy committed the copied .vif and reopened replaced shards without updating the mounted volume's encode run, so the holder kept reporting the old run while serving the new bytes. Go and Rust volume servers now stage the .vif before anything is committed and fail with FailedPrecondition when it names a nonzero run different from a run this server mounts for the volume. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: list only mounted shards of every disk in Rust VolumeEcShardsInfo The Rust reply listed every shard slot of the first disk's runtime, with unmounted slots as size-0 entries, and skipped shards mounted on other disks. Callers build each holder's shard bits from this list, so a Rust holder counted as holding shards it did not have. The reply now lists the mounted shards of every local disk, each id once, as Go does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: check the source encode run of an EC shard copy without a .vif A copy that leaves out the .vif could still replace a mounted shard with another encode run's bytes. Fetch the source .vif for the run check in every copy, and install it only when asked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: refuse to serve EC files of a volume held from two encode runs CopyFile looks each requested file up on its own, so a server that holds a volume's shards on one disk from one encode run and its .vif on another disk from a different run would hand a copier mismatched files. Refuse the copy when the .vif files of this server disagree on a nonzero run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ec: refuse a rebuild whose holders serve different encode runs The rebuild groups holders by volume id and collection only. When they serve two encode runs, the copied shards land beside the first run's .vif and .ecx and the rebuild regenerates from the mixed set. Before copying, ask every holder for its run and refuse unless they agree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ec: bound each holder query in the rebuild's encode-run check A holder that accepts the connection but never answers VolumeEcShardsInfo kept the rebuild waiting forever. Give each holder its own deadline; one that times out is skipped like an unreachable holder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ec: check only the rebuilder and copy sources for the encode run The rebuild copies each shard from its first listed holder. Extra copies are never read, so asking them for their run only adds servers that can stall the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ec: do not copy from a source whose encode run went unchecked A copy source whose VolumeEcShardsInfo query fails or times out has an unknown run. The copy fence on the rebuilder compares a source's run with the run the rebuilder mounts, so on a rebuilder that holds none of the volume's shards nothing checks it, and its shards could join a rebuild of another run. The rebuild now skips such a source like a failed copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ec: leave holders of shards the rebuilder has out of the run check The rebuild uses a shard the rebuilder already holds and never reads its other listed holders, but the run check still asked the first of them. A stale replica listed first for such a shard refused a rebuild that would not touch it. Pick the holders to check the way prepareDataToRecover picks its copy sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
167 lines
5.9 KiB
Go
167 lines
5.9 KiB
Go
package erasure_coding
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRequireRecoverableShardSet_AllPresent(t *testing.T) {
|
|
var bits ShardBits
|
|
for id := 0; id < TotalShardsCount; id++ {
|
|
bits = bits.Set(ShardId(id))
|
|
}
|
|
degraded, err := RequireRecoverableShardSet(42, bits, DataShardsCount, TotalShardsCount)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error for full set: %v", err)
|
|
}
|
|
if degraded {
|
|
t.Error("full set must not be reported as degraded")
|
|
}
|
|
}
|
|
|
|
func TestRequireRecoverableShardSet_DegradedButRecoverable(t *testing.T) {
|
|
// 12 of 14 shards: enough to reconstruct (>= 10), so the source may be
|
|
// deleted, but the caller is told to warn and schedule a rebuild.
|
|
var bits ShardBits
|
|
for id := 0; id < TotalShardsCount; id++ {
|
|
if id == 3 || id == 7 {
|
|
continue
|
|
}
|
|
bits = bits.Set(ShardId(id))
|
|
}
|
|
degraded, err := RequireRecoverableShardSet(42, bits, DataShardsCount, TotalShardsCount)
|
|
if err != nil {
|
|
t.Fatalf("recoverable set must not error: %v", err)
|
|
}
|
|
if !degraded {
|
|
t.Error("missing shards must be reported as degraded")
|
|
}
|
|
}
|
|
|
|
func TestRequireRecoverableShardSet_BelowDataShards(t *testing.T) {
|
|
// 9 of 14 shards: one short of reconstructable; the source must be kept.
|
|
var bits ShardBits
|
|
for id := 0; id < DataShardsCount-1; id++ {
|
|
bits = bits.Set(ShardId(id))
|
|
}
|
|
_, err := RequireRecoverableShardSet(42, bits, DataShardsCount, TotalShardsCount)
|
|
if err == nil {
|
|
t.Fatal("expected error for unrecoverable set, got nil")
|
|
}
|
|
msg := err.Error()
|
|
if !strings.Contains(msg, "volume 42") {
|
|
t.Errorf("error should name the volume id: %s", msg)
|
|
}
|
|
if !strings.Contains(msg, "9/14") {
|
|
t.Errorf("error should report 9/14 shards present: %s", msg)
|
|
}
|
|
if !strings.Contains(msg, "[9 10 11 12 13]") {
|
|
t.Errorf("error should list the missing ids: %s", msg)
|
|
}
|
|
}
|
|
|
|
func TestRequireRecoverableShardSet_EmptyBitmap(t *testing.T) {
|
|
_, err := RequireRecoverableShardSet(1, 0, DataShardsCount, TotalShardsCount)
|
|
if err == nil {
|
|
t.Fatal("expected error for empty bitmap")
|
|
}
|
|
if !strings.Contains(err.Error(), "0/14") {
|
|
t.Errorf("error should report 0/14 shards: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestRequireRecoverableShardSet_CustomRatio(t *testing.T) {
|
|
// 6+3 ratio: total=9, all present
|
|
var bits ShardBits
|
|
for id := 0; id < 9; id++ {
|
|
bits = bits.Set(ShardId(id))
|
|
}
|
|
if degraded, err := RequireRecoverableShardSet(7, bits, 6, 9); err != nil || degraded {
|
|
t.Fatalf("full 6+3 set: degraded=%v err=%v", degraded, err)
|
|
}
|
|
|
|
// 6+3, missing shard 5: 8 >= 6 remain, recoverable but degraded
|
|
bits = bits.Clear(5)
|
|
if degraded, err := RequireRecoverableShardSet(7, bits, 6, 9); err != nil || !degraded {
|
|
t.Fatalf("8/9 shards of 6+3: degraded=%v err=%v", degraded, err)
|
|
}
|
|
|
|
// 6+3, only 5 shards left: below dataShards, must error
|
|
bits = ShardBits(0)
|
|
for id := 0; id < 5; id++ {
|
|
bits = bits.Set(ShardId(id))
|
|
}
|
|
_, err := RequireRecoverableShardSet(7, bits, 6, 9)
|
|
if err == nil {
|
|
t.Fatal("expected error with 5/9 shards in 6+3 ratio")
|
|
}
|
|
if !strings.Contains(err.Error(), "5/9") {
|
|
t.Errorf("error should report 5/9: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestRequireRecoverableShardSet_RejectsInvalidParams(t *testing.T) {
|
|
if _, err := RequireRecoverableShardSet(1, 0, DataShardsCount, 0); err == nil {
|
|
t.Error("expected error for totalShards=0")
|
|
}
|
|
if _, err := RequireRecoverableShardSet(1, 0, DataShardsCount, MaxShardCount+1); err == nil {
|
|
t.Errorf("expected error for totalShards > MaxShardCount")
|
|
}
|
|
if _, err := RequireRecoverableShardSet(1, 0, 0, TotalShardsCount); err == nil {
|
|
t.Error("expected error for dataShards=0")
|
|
}
|
|
if _, err := RequireRecoverableShardSet(1, 0, TotalShardsCount+1, TotalShardsCount); err == nil {
|
|
t.Error("expected error for dataShards > totalShards")
|
|
}
|
|
}
|
|
|
|
func TestSummarizeShardInventory_Deterministic(t *testing.T) {
|
|
perServer := map[string]ServerShardInventory{
|
|
"10.0.0.2:8080": {Bits: ShardBits(0).Set(4).Set(5).Set(6)},
|
|
"10.0.0.1:8080": {Bits: ShardBits(0).Set(0).Set(1).Set(2).Set(3)},
|
|
}
|
|
got := SummarizeShardInventory(perServer)
|
|
want := "10.0.0.1:8080=[0 1 2 3] 10.0.0.2:8080=[4 5 6]"
|
|
if got != want {
|
|
t.Errorf("summary mismatch\n got: %q\n want: %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestSummarizeShardInventory_IncludesError(t *testing.T) {
|
|
perServer := map[string]ServerShardInventory{
|
|
"10.0.0.1:8080": {Bits: ShardBits(0).Set(0).Set(1), QueryError: errStr("dial timeout")},
|
|
}
|
|
got := SummarizeShardInventory(perServer)
|
|
if !strings.Contains(got, "ERR:dial timeout") {
|
|
t.Errorf("expected error tag in summary, got %q", got)
|
|
}
|
|
}
|
|
|
|
type errStr string
|
|
|
|
func (e errStr) Error() string { return string(e) }
|
|
|
|
func TestRequireAgreedEncodeRun(t *testing.T) {
|
|
stale := ShardBits(0).Set(0).Set(8)
|
|
fresh := ShardBits(0x3FFF).Clear(0).Clear(8)
|
|
for _, tc := range []struct {
|
|
name string
|
|
perServer map[string]ServerShardInventory
|
|
wantErr bool
|
|
}{
|
|
{"one run", map[string]ServerShardInventory{"a": {Bits: stale, EncodeTsNs: 200}, "b": {Bits: fresh, EncodeTsNs: 200}}, false},
|
|
{"two runs", map[string]ServerShardInventory{"a": {Bits: stale, EncodeTsNs: 100}, "b": {Bits: fresh, EncodeTsNs: 200}}, true},
|
|
{"mixed holder alone", map[string]ServerShardInventory{"a": {Bits: stale | fresh, EncodeTsNs: MixedEncodeRuns}}, true},
|
|
{"mixed holder beside agreeing run", map[string]ServerShardInventory{"a": {Bits: stale, EncodeTsNs: MixedEncodeRuns}, "b": {Bits: fresh, EncodeTsNs: 200}}, true},
|
|
{"unreported run skipped", map[string]ServerShardInventory{"a": {Bits: stale}, "b": {Bits: fresh, EncodeTsNs: 200}}, false},
|
|
{"no shards skipped", map[string]ServerShardInventory{"a": {EncodeTsNs: 100}, "b": {Bits: fresh, EncodeTsNs: 200}}, false},
|
|
{"unreachable skipped", map[string]ServerShardInventory{"a": {Bits: stale, EncodeTsNs: 100, QueryError: errors.New("down")}, "b": {Bits: fresh, EncodeTsNs: 200}}, false},
|
|
} {
|
|
err := RequireAgreedEncodeRun(147, tc.perServer)
|
|
if (err != nil) != tc.wantErr {
|
|
t.Errorf("%s: err = %v, want error %v", tc.name, err, tc.wantErr)
|
|
}
|
|
}
|
|
}
|