mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-30 08:50:48 +01:00
ec.rebuild: remount shards the rebuild replaced, keep regenerated copies (#12193)
* volume: remount ec shards the rebuild replaced under a mounted handle Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ec.rebuild: keep copied shards the rebuild regenerated in place Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * volume: reopen regenerated ec shards in place instead of remounting UnmountEcShards and MountEcShards send deltas through separate buffered channels, so a remount can reach the master as add-then-delete and drop the repaired shard from lookups until the next full EC heartbeat. ReopenEcShard swaps the mounted shard's descriptor under the volume lock instead: registration, disk type, and heartbeat state never flip, and readers holding the old shard degrade to a clean error the parity path already recovers from. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * rust volume: reopen rebuilt ec shards in place, mirroring Go volume_ec_shards_rebuild recreates a shard file under a mounted handle whose descriptor still serves the detached inode (a mounted shard whose file was deleted under it). DiskLocation::reopen_ec_shard swaps the mounted descriptor for a fresh open, matching Go's ReopenEcShard — the registration and heartbeat view never flip. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * volume: fail ec rebuild when a regenerated shard cannot be reopened * rust volume: fail ec shards rebuild when a rebuilt shard cannot be reopened * volume: repoint mounted ec shards after rebuild across disks A mounted shard whose file was deleted under the mount is "missing" to the rebuild: the regenerated file lands on the rebuild location while the handle keeps serving the detached inode on another disk. Reopening the mounted disk then failed the whole RPC, so the caller never saw the rebuilt ids and its deferred cleanup deleted the regenerated copies. Repoint every mounted handle of the rebuilt volume instead of only this run's outputs: reopen in place when the rebuilt file is on the mounted disk, otherwise drop the stale handle and remount the shard from whichever local disk holds the file via a delta-free load split out of MountEcShards — a same-server move, so the master's registration never flips. A shard that can be neither reopened nor remounted is left unmounted rather than serving replaced bytes, and the repoint step no longer fails the RPC, so RebuiltShardIds always reaches the caller. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * rust volume: repoint mounted ec shards after rebuild across disks Mirror the Go repoint loop: iterate every mounted shard of the rebuilt volume, reopen in place when the rebuilt file is on the mounted disk, and otherwise drop the stale handle and remount the shard from whichever local disk holds it. The repoint no longer fails the RPC, so rebuilt_shard_ids still reaches the caller and its copy cleanup keeps the regenerated shards. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * rust volume: still rebuild ecx and repoint mounts when no shard is missing * master: keep a node in an ec shard's lookup while a disk still holds it A rebuild that relocates a mounted shard between a node's disks reports the move as a delete on the source disk plus an add on the destination. Registering first is a no-op because shard lookups key on the node, then the unregister dropped the node outright — and steady-state heartbeats never restore it, so readers and later rebuilds lose the repaired copy. Skip the delete while another disk on the node still holds the shard. UnregisterDataNode now clears the node's own ec records before dropping its registrations, so the retained-shard check cannot skip the teardown, and each unregister gets a ShardsInfo copy since DeleteEcShard drains the shared one. * rust volume: fold the journal on a mounted index instead of rewriting it The rebuild handler regenerated .ecx through File::create even while the volume was mounted, truncating the index under readers that search the open descriptor with its old size — a live lookup could hit EOF mid-scan. Go folds the deletion journal in place on a mounted volume; do the same through rebuild_ecx_from_journal and reserve the full regen for the unmounted path, where nothing holds the file open to interrupt. * volume, rust volume: report rebuilt shards on late failures, fix rust corrupt discovery Two review findings the repoint rework left open: - A RebuildEcxFile failure still returns a plain error after shards were regenerated, so the caller discards the response holding the rebuilt ids and the deferred cleanup deletes copies the rebuild regenerated in place. The Go handler now packs the ids into the gRPC status details and the shell pulls them back out on error; the Rust handler carries them in grpc-status-details-bin the same way. - The Rust rebuild still counted a sidecar-corrupt shard as present, so it fed bad bytes into reconstruction and never regenerated the shard. Discovery now loads the generation-0 .ecsum the way Go does, verifies every present shard, and reclassifies mismatches (and zero-size residue) as rebuild targets written to a .rebuilding temp file, verified, and atomically renamed over the original only after every output passes the sidecar check. Honors unsafe_ignore_sidecar, added to VolumeEcShardsRebuildRequest to match the Go proto. * volume: repoint sibling journals sharing a folded .ecj after rebuild RebuildEcxFile unlinks the deletion journal and the mounted path only reopens its own handle — a sibling mount journaling into the same file keeps appending to the detached inode, and those deletes never reach a path-based reader again. Reopen every mounted volume sharing the index base before leaving the rebuild. * rust volume: repoint sibling journals sharing a folded .ecj after rebuild rebuild_ecx_from_journal replaces the journal and reopens only its own handle; mounts on sibling disks sharing that .ecj keep the detached handle, so their next appends are lost at restart. Adopt the folded journal on every mounted runtime sharing the path before releasing the store lock, clearing their in-memory set — every journaled id is now an .ecx tombstone. * ec: swap the deletion journal handle only after the new file opens A failed reopen left ecjFile nil, so every later delete returned "ec volume closed". Open first, then close and swap — mirroring the Rust adopt_folded_journal ordering. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ec.rebuild: fail the rebuild when a sibling journal cannot be repointed A warning left the sibling mount journaling to a detached inode while the RPC reported success. Propagate the error like the Rust handler's adopt_folded_journal map_err. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ec: keep deletes loud when the journal reopen cannot open the replacement Reverts the swap-on-success ordering: a detached handle kept on failure lets deletes append and sync to the removed inode, then vanish at restart. Closing first also frees the descriptor before the open. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * rust volume: drop the folded journal handle before reopening it adopt_folded_journal and the post-fold recreate now clear ecj_file before opening the replacement, so a failed reopen leaves deletes erroring instead of appending to the detached inode. Mirrors Go's ReopenDeletionJournal. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ec: drop the cached journal size when its reopen fails Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
5c92a54a12
commit
2c510cc30e
17 files changed
+1202
-110
No files matched your search
@@ -255,6 +255,59 @@ func (l *DiskLocation) loadEcShardWithIdxDir(collection string, vid needle.Volum
|
||||
return ecVolume, nil
|
||||
}
|
||||
|
||||
// ReopenEcShard swaps the mounted shard's descriptor for a fresh open of its
|
||||
// on-disk file while leaving the volume's registration — and therefore the
|
||||
// master's view — untouched. It exists for the in-place rebuild path:
|
||||
// RebuildEcFiles renames a regenerated shard over the file a mounted handle is
|
||||
// still serving, and reopening repoints reads at the repaired file without
|
||||
// the delete/add heartbeat flip-flop an unmount+remount would send.
|
||||
func (l *DiskLocation) ReopenEcShard(vid needle.VolumeId, shardId erasure_coding.ShardId) (bool, error) {
|
||||
l.ecVolumesLock.Lock()
|
||||
defer l.ecVolumesLock.Unlock()
|
||||
|
||||
ecVolume, found := l.ecVolumes[vid]
|
||||
if !found {
|
||||
return false, nil
|
||||
}
|
||||
var oldShard *erasure_coding.EcVolumeShard
|
||||
position := -1
|
||||
for i, s := range ecVolume.Shards {
|
||||
if s.ShardId == shardId {
|
||||
position = i
|
||||
oldShard = s
|
||||
break
|
||||
}
|
||||
}
|
||||
if oldShard == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
newShard, err := erasure_coding.NewEcVolumeShard(oldShard.DiskType, l.Directory, oldShard.Collection, vid, shardId)
|
||||
if err != nil {
|
||||
return true, fmt.Errorf("reopen ec shard %d.%d: %w", vid, shardId, err)
|
||||
}
|
||||
ecVolume.Shards[position] = newShard
|
||||
|
||||
// Readers that already resolved the old shard keep their object; its Close
|
||||
// turns their next ReadAt into a clean error recovered via parity, the same
|
||||
// contract eviction relies on. Mount/Unmount balance out, so the shard
|
||||
// gauge does not move.
|
||||
oldShard.Unmount()
|
||||
oldShard.Close()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// MountedEcShardIds returns the ids of shards this disk currently serves for
|
||||
// the volume, or nil when the volume is not mounted here.
|
||||
func (l *DiskLocation) MountedEcShardIds(vid needle.VolumeId) []erasure_coding.ShardId {
|
||||
l.ecVolumesLock.RLock()
|
||||
defer l.ecVolumesLock.RUnlock()
|
||||
if ecVolume, found := l.ecVolumes[vid]; found {
|
||||
return ecVolume.ShardIdList()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *DiskLocation) UnloadEcShard(vid needle.VolumeId, shardId erasure_coding.ShardId) bool {
|
||||
|
||||
l.ecVolumesLock.Lock()
|
||||
|
||||
@@ -132,6 +132,7 @@ func (ev *EcVolume) ReopenDeletionJournal() error {
|
||||
}
|
||||
ecjFile, err := backend.OpenVolumeFile(ev.FileName(".ecj"), os.O_RDWR|os.O_CREATE)
|
||||
if err != nil {
|
||||
ev.ecjFileSize = 0
|
||||
return fmt.Errorf("reopen ec volume journal %s: %w", ev.FileName(".ecj"), err)
|
||||
}
|
||||
ev.ecjFile = ecjFile
|
||||
|
||||
+39
-26
@@ -253,6 +253,41 @@ func (s *Store) CollectErasureCodingHeartbeat() *master_pb.Heartbeat {
|
||||
}
|
||||
|
||||
func (s *Store) MountEcShards(collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, sourceDiskType string) error {
|
||||
ecVolume, diskId, err := s.LoadEcShardAcrossDisks(collection, vid, shardId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
glog.V(0).Infof("MountEcShards %d.%d on disk ID %d", vid, shardId, diskId)
|
||||
|
||||
// Apply the orchestrator-supplied source disk type so the EC
|
||||
// volume reports under it instead of the location's. Empty means
|
||||
// "fall back to location's disk type" (#9423).
|
||||
if sourceDiskType != "" {
|
||||
ecVolume.SetDiskType(types.ToDiskType(sourceDiskType))
|
||||
}
|
||||
|
||||
si := erasure_coding.NewShardsInfo()
|
||||
si.Set(erasure_coding.NewShardInfo(shardId, erasure_coding.ShardSize(ecVolume.ShardSize())))
|
||||
s.NewEcShardsChan <- &master_pb.VolumeEcShardInformationMessage{
|
||||
Id: uint32(vid),
|
||||
Collection: collection,
|
||||
EcIndexBits: uint32(si.Bitmap()),
|
||||
ShardSizes: si.SizesInt64(),
|
||||
DiskType: string(ecVolume.DiskType()),
|
||||
ExpireAtSec: ecVolume.ExpireAtSec,
|
||||
DiskId: uint32(diskId),
|
||||
EncodeTsNs: ecVolume.EncodeTsNs,
|
||||
}
|
||||
s.UpdateMaxVolumeIdSeen(vid)
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadEcShardAcrossDisks mounts shardId on whichever local disk holds its
|
||||
// file and returns the mounted volume plus the disk it landed on. It emits
|
||||
// no heartbeat delta — callers that change the master's view do that
|
||||
// themselves (MountEcShards), while same-server repoints that must not flip
|
||||
// the master's registration use it directly.
|
||||
func (s *Store) LoadEcShardAcrossDisks(collection string, vid needle.VolumeId, shardId erasure_coding.ShardId) (*erasure_coding.EcVolume, uint32, error) {
|
||||
// The .ecx index file may live on a different disk than the one
|
||||
// holding the .ec?? shard being mounted: ec.balance / ec.rebuild can
|
||||
// place the .ecx on one local disk while later distributing shards
|
||||
@@ -292,29 +327,7 @@ func (s *Store) MountEcShards(collection string, vid needle.VolumeId, shardId er
|
||||
}
|
||||
ecVolume, err := location.loadEcShardWithIdxDir(collection, vid, shardId, idxDir)
|
||||
if err == nil {
|
||||
glog.V(0).Infof("MountEcShards %d.%d on disk ID %d", vid, shardId, diskId)
|
||||
|
||||
// Apply the orchestrator-supplied source disk type so the EC
|
||||
// volume reports under it instead of the location's. Empty means
|
||||
// "fall back to location's disk type" (#9423).
|
||||
if sourceDiskType != "" {
|
||||
ecVolume.SetDiskType(types.ToDiskType(sourceDiskType))
|
||||
}
|
||||
|
||||
si := erasure_coding.NewShardsInfo()
|
||||
si.Set(erasure_coding.NewShardInfo(shardId, erasure_coding.ShardSize(ecVolume.ShardSize())))
|
||||
s.NewEcShardsChan <- &master_pb.VolumeEcShardInformationMessage{
|
||||
Id: uint32(vid),
|
||||
Collection: collection,
|
||||
EcIndexBits: uint32(si.Bitmap()),
|
||||
ShardSizes: si.SizesInt64(),
|
||||
DiskType: string(ecVolume.DiskType()),
|
||||
ExpireAtSec: ecVolume.ExpireAtSec,
|
||||
DiskId: uint32(diskId),
|
||||
EncodeTsNs: ecVolume.EncodeTsNs,
|
||||
}
|
||||
s.UpdateMaxVolumeIdSeen(vid)
|
||||
return nil
|
||||
return ecVolume, uint32(diskId), nil
|
||||
}
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
// Shard or index not on this disk; another disk may own it.
|
||||
@@ -329,9 +342,9 @@ func (s *Store) MountEcShards(collection string, vid needle.VolumeId, shardId er
|
||||
// scanned for so the operator can tell "no .ecx anywhere" apart
|
||||
// from "shard not on this server".
|
||||
if !ecxFound {
|
||||
return fmt.Errorf("MountEcShards %d.%d: no .ecx index found on any local disk", vid, shardId)
|
||||
return nil, 0, fmt.Errorf("MountEcShards %d.%d: no .ecx index found on any local disk", vid, shardId)
|
||||
}
|
||||
return fmt.Errorf("MountEcShards %d.%d not found on disk", vid, shardId)
|
||||
return nil, 0, fmt.Errorf("MountEcShards %d.%d not found on disk", vid, shardId)
|
||||
}
|
||||
// Some disks returned a real (non-ENOENT) error. Report them all so
|
||||
// the caller can see whether the failures cluster around one disk
|
||||
@@ -343,7 +356,7 @@ func (s *Store) MountEcShards(collection string, vid needle.VolumeId, shardId er
|
||||
}
|
||||
b = append(b, fmt.Sprintf("%s: %v", f.dir, f.err)...)
|
||||
}
|
||||
return fmt.Errorf("MountEcShards %d.%d load failures: %s", vid, shardId, string(b))
|
||||
return nil, 0, fmt.Errorf("MountEcShards %d.%d load failures: %s", vid, shardId, string(b))
|
||||
}
|
||||
|
||||
func (s *Store) UnmountEcShards(vid needle.VolumeId, shardId erasure_coding.ShardId, reqEncodeTsNs int64) error {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// A shard file the rebuild replaced under its mount keeps serving the old
|
||||
// inode through the open descriptor. ReopenEcShard must repoint the mounted
|
||||
// shard at the new file without dropping its registration.
|
||||
func TestReopenEcShardReadsReplacedFile(t *testing.T) {
|
||||
store := newEcTargetTestStore(t, 1)
|
||||
collection := "col"
|
||||
vid := needle.VolumeId(42)
|
||||
dataDir := store.Locations[0].Directory
|
||||
|
||||
writeEcShard0(t, dataDir, collection, vid)
|
||||
writeEcIndex(t, dataDir, collection, vid)
|
||||
|
||||
shardPath := erasure_coding.EcShardFileName(collection, dataDir, int(vid)) + erasure_coding.ToExt(0)
|
||||
content := make([]byte, calculateExpectedShardSize(1024*1024, 10))
|
||||
for i := range content {
|
||||
content[i] = 'A'
|
||||
}
|
||||
require.NoError(t, os.WriteFile(shardPath, content, 0o644))
|
||||
|
||||
require.NoError(t, store.MountEcShards(collection, vid, 0, ""))
|
||||
|
||||
readShard := func() []byte {
|
||||
shard, found := store.Locations[0].FindEcShard(vid, 0)
|
||||
require.True(t, found)
|
||||
buf := make([]byte, len(content))
|
||||
n, err := shard.ReadAt(buf, 0)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(content), n)
|
||||
return buf
|
||||
}
|
||||
require.True(t, bytes.Equal(content, readShard()))
|
||||
|
||||
for i := range content {
|
||||
content[i] = 'B'
|
||||
}
|
||||
rebuilt := shardPath + ".rebuilding"
|
||||
require.NoError(t, os.WriteFile(rebuilt, content, 0o644))
|
||||
require.NoError(t, os.Rename(rebuilt, shardPath))
|
||||
|
||||
stale := readShard()
|
||||
require.False(t, bytes.Equal(content, stale), "mounted shard should still read the replaced inode")
|
||||
|
||||
reopened, err := store.Locations[0].ReopenEcShard(vid, 0)
|
||||
require.NoError(t, err)
|
||||
require.True(t, reopened, "shard is mounted; reopen should find it")
|
||||
|
||||
require.True(t, bytes.Equal(content, readShard()), "reopened shard should read the regenerated file")
|
||||
|
||||
reopened, err = store.Locations[0].ReopenEcShard(vid, 7)
|
||||
require.NoError(t, err)
|
||||
require.False(t, reopened, "a shard that is not mounted should report false")
|
||||
}
|
||||
Reference in new issue
Block a user