mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
* volume: report mounted EC shards whose file on disk is gone, replaced or resized
Each EC heartbeat tick stats every mounted shard file and compares it with the
open descriptor: a missing path or a different file is a ghost, a size other
than the mounted one is stale_size. Mismatches are logged per shard and counted
in SeaweedFS_volumeServer_ec_shard_disk_mismatch{reason}.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume(rs): report mounted EC shards whose file on disk is gone, replaced or resized
Mirror of the Go check: each EC heartbeat tick compares every mounted shard
with its file (missing or another inode = ghost, other size = stale_size),
warns per shard and sets SeaweedFS_volumeServer_ec_shard_disk_mismatch{reason}.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* metrics: chart EC shards that disagree with their file on disk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume(rs): tell a replaced EC shard file apart on non-unix hosts
Without inode numbers, compare the creation and modification times of the
path and of the open handle.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume: check mounted EC shards off the heartbeat loop
A stat stuck on a stalled disk no longer holds up heartbeats or shutdown; at
most one check runs at a time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume(rs): check mounted EC shards off the heartbeat loop
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume(rs): compare file ids to tell a replaced EC shard file apart on Windows
Timestamps can match on a replacement file. Use the volume serial and
file index from GetFileInformationByHandle there, and dev/inode on
unix, the same identity Go's os.SameFile compares.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume(rs): copy mounted EC shard state out before checking the disk
The check held the store read guard across its file system calls, so a
stalled disk kept the guard and a waiting writer could then stall the
heartbeat's own read. Copy each shard's path, size and file id under
the guard and check them after it is released. The id is recorded when
the shard opens, so no extra handle is held for the check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume(rs): run the EC shard disk check on a detached thread
Dropping the runtime waits for spawn_blocking tasks, so a stat stuck on
a hung disk could hold up shutdown. A plain thread is not waited on.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume(rs): stat the EC shard path instead of opening it
A replacement the server cannot read failed the open and was never
counted as a ghost. Compare device, inode and length from the path's
metadata, as the Go side does with os.Stat; on Windows open it with no
access rights.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume(rs): test the EC tick past a stalled disk check
The check thread start takes the check to run, so a test can stall one
after its snapshot and show that a writer still gets the store, the tick
still reports, and no second check starts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* volume: keep VolumeServer int64 counters 8-byte aligned on 32-bit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
194 lines
5.0 KiB
Go
194 lines
5.0 KiB
Go
package erasure_coding
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/backend"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
)
|
|
|
|
type ShardId uint8
|
|
|
|
// Converts a slice of uint32s to ShardId.
|
|
func Uint32ToShardIds(ids []uint32) []ShardId {
|
|
res := make([]ShardId, len(ids))
|
|
for i, id := range ids {
|
|
res[i] = ShardId(id)
|
|
}
|
|
return res
|
|
}
|
|
|
|
// Converts a slice of ShardIds to uint32
|
|
func ShardIdsToUint32(ids []ShardId) []uint32 {
|
|
res := make([]uint32, len(ids))
|
|
for i, id := range ids {
|
|
res[i] = uint32(id)
|
|
}
|
|
return res
|
|
}
|
|
|
|
// Returns a slice of all possible ShardIds.
|
|
func AllShardIds() []ShardId {
|
|
res := make([]ShardId, TotalShardsCount)
|
|
for i := range res {
|
|
res[i] = ShardId(i)
|
|
}
|
|
return res
|
|
}
|
|
|
|
// Compares a pair of EcShardInfo protos for sorting.
|
|
func CmpEcShardInfo(a, b *volume_server_pb.EcShardInfo) int {
|
|
if a.VolumeId < b.VolumeId {
|
|
return -1
|
|
}
|
|
if a.VolumeId > b.VolumeId {
|
|
return 1
|
|
}
|
|
if a.ShardId < b.ShardId {
|
|
return -1
|
|
}
|
|
if a.ShardId > b.ShardId {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
type EcVolumeShard struct {
|
|
VolumeId needle.VolumeId
|
|
ShardId ShardId
|
|
Collection string
|
|
dir string
|
|
ecdFile *os.File
|
|
ecdFileSize int64
|
|
DiskType types.DiskType
|
|
}
|
|
|
|
func NewEcVolumeShard(diskType types.DiskType, dirname string, collection string, id needle.VolumeId, shardId ShardId) (v *EcVolumeShard, e error) {
|
|
|
|
v = &EcVolumeShard{dir: dirname, Collection: collection, VolumeId: id, ShardId: shardId, DiskType: diskType}
|
|
|
|
baseFileName := v.FileName()
|
|
|
|
// open ecd file
|
|
if v.ecdFile, e = backend.OpenVolumeFile(baseFileName+ToExt(int(shardId)), os.O_RDONLY); e != nil {
|
|
if e == os.ErrNotExist || strings.Contains(e.Error(), "no such file or directory") {
|
|
return nil, os.ErrNotExist
|
|
}
|
|
return nil, fmt.Errorf("cannot read ec volume shard %s%s: %v", baseFileName, ToExt(int(shardId)), e)
|
|
}
|
|
ecdFi, statErr := v.ecdFile.Stat()
|
|
if statErr != nil {
|
|
_ = v.ecdFile.Close()
|
|
return nil, fmt.Errorf("can not stat ec volume shard %s%s: %v", baseFileName, ToExt(int(shardId)), statErr)
|
|
}
|
|
v.ecdFileSize = ecdFi.Size()
|
|
|
|
v.Mount()
|
|
|
|
return
|
|
}
|
|
|
|
func (shard *EcVolumeShard) Mount() {
|
|
stats.VolumeServerVolumeGauge.WithLabelValues(shard.Collection, "ec_shards").Inc()
|
|
}
|
|
|
|
func (shard *EcVolumeShard) Unmount() {
|
|
stats.VolumeServerVolumeGauge.WithLabelValues(shard.Collection, "ec_shards").Dec()
|
|
}
|
|
|
|
func (shard *EcVolumeShard) Size() int64 {
|
|
return shard.ecdFileSize
|
|
}
|
|
|
|
const (
|
|
EcShardGhost = "ghost"
|
|
EcShardStaleSize = "stale_size"
|
|
)
|
|
|
|
// DiskMismatch names how the shard file on disk disagrees with the mount:
|
|
// EcShardGhost when the path is gone or names another file than the open one,
|
|
// EcShardStaleSize when the file size changed since the mount, "" otherwise.
|
|
func (shard *EcVolumeShard) DiskMismatch() string {
|
|
onDisk, err := os.Stat(shard.FileName() + ToExt(int(shard.ShardId)))
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return EcShardGhost
|
|
}
|
|
return ""
|
|
}
|
|
if open, err := shard.ecdFile.Stat(); err == nil && !os.SameFile(onDisk, open) {
|
|
return EcShardGhost
|
|
}
|
|
if onDisk.Size() != shard.ecdFileSize {
|
|
return EcShardStaleSize
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (shard *EcVolumeShard) String() string {
|
|
return fmt.Sprintf("ec shard %v:%v, dir:%s, Collection:%s", shard.VolumeId, shard.ShardId, shard.dir, shard.Collection)
|
|
}
|
|
|
|
func (shard *EcVolumeShard) FileName() (fileName string) {
|
|
return EcShardFileName(shard.Collection, shard.dir, int(shard.VolumeId))
|
|
}
|
|
|
|
func EcShardFileName(collection string, dir string, id int) (fileName string) {
|
|
idString := strconv.Itoa(id)
|
|
if collection == "" {
|
|
fileName = path.Join(dir, idString)
|
|
} else {
|
|
fileName = path.Join(dir, collection+"_"+idString)
|
|
}
|
|
return
|
|
}
|
|
|
|
func EcShardBaseFileName(collection string, id int) (baseFileName string) {
|
|
baseFileName = strconv.Itoa(id)
|
|
if collection != "" {
|
|
baseFileName = collection + "_" + baseFileName
|
|
}
|
|
return
|
|
}
|
|
|
|
func (shard *EcVolumeShard) Close() {
|
|
// Close the fd but do NOT nil it: a reader resolves the shard under the
|
|
// ecVolumesLock then calls ReadAt after the lock is released, so a
|
|
// concurrent eviction that nils the field would race that read and panic.
|
|
// Leaving the field set means ReadAt hits a closed fd and returns a clean
|
|
// error (the caller recovers from parity) with no data race on the field.
|
|
if shard.ecdFile != nil {
|
|
_ = shard.ecdFile.Close()
|
|
}
|
|
}
|
|
|
|
func (shard *EcVolumeShard) Destroy() {
|
|
shard.Unmount()
|
|
os.Remove(shard.FileName() + ToExt(int(shard.ShardId)))
|
|
}
|
|
|
|
func (shard *EcVolumeShard) ReadAt(buf []byte, offset int64) (int, error) {
|
|
n, err := shard.ecdFile.ReadAt(buf, offset)
|
|
if err == io.EOF && n == len(buf) {
|
|
err = nil
|
|
}
|
|
return n, err
|
|
}
|
|
|
|
func (shard *EcVolumeShard) ToEcShardInfo() *volume_server_pb.EcShardInfo {
|
|
return &volume_server_pb.EcShardInfo{
|
|
ShardId: uint32(shard.ShardId),
|
|
Size: int64(shard.Size()),
|
|
Collection: shard.Collection,
|
|
VolumeId: uint32(shard.VolumeId),
|
|
}
|
|
}
|