diff --git a/other/metrics/grafana_seaweedfs.json b/other/metrics/grafana_seaweedfs.json index 85a4f9fed7..6f35148c7b 100644 --- a/other/metrics/grafana_seaweedfs.json +++ b/other/metrics/grafana_seaweedfs.json @@ -5451,6 +5451,102 @@ } ], "pluginVersion": "10.3.1" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "title": "EC Shard Copy Failures by reason", + "description": "Rate of failed EC shard copies into each volume server by collection and reason (source_not_found, empty_index, no_space, timeout, io_error, other). The volume server log names the volume, shards and source of each failure.", + "type": "timeseries", + "id": 269, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 142 + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 4, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "unit": "ops", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "options": { + "legend": { + "calcs": [ + "lastNotNull", + "max" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "desc" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum by (instance, collection, reason) (rate(SeaweedFS_volumeServer_ec_shard_copy_failures_total{cluster=~\"$cluster\"}[$__rate_interval]))", + "range": true, + "refId": "A", + "legendFormat": "{{instance}} {{collection}} {{reason}}" + } + ], + "pluginVersion": "10.3.1" } ] }, diff --git a/seaweed-volume/src/metrics.rs b/seaweed-volume/src/metrics.rs index 85093f3213..add010a324 100644 --- a/seaweed-volume/src/metrics.rs +++ b/seaweed-volume/src/metrics.rs @@ -280,6 +280,19 @@ pub static EC_RECONSTRUCTED_INTERVAL_COUNTER: LazyLock = LazyLock .expect("metric can be created") }); +/// Failed EC shard copies into this server, with labels `collection` and +/// `reason`. Mirrors Go's VolumeServerEcShardCopyFailures. +pub static EC_SHARD_COPY_FAILURES: LazyLock = LazyLock::new(|| { + IntCounterVec::new( + Opts::new( + "SeaweedFS_volumeServer_ec_shard_copy_failures_total", + "Counter of failed EC shard copies into this server by collection and reason.", + ), + &["collection", "reason"], + ) + .expect("metric can be created") +}); + /// Counter of storage read/write EIO errors on volumes and EC shards. /// Mirrors Go's VolumeServerStorageIoErrorCounter. pub static STORAGE_IO_ERROR_COUNTER: LazyLock = LazyLock::new(|| { @@ -392,6 +405,14 @@ pub const ERROR_WRITE_TO_LOCAL_DISK: &str = "errorWriteToLocalDisk"; pub const ERROR_UNMARSHAL_PAIRS: &str = "errorUnmarshalPairs"; pub const ERROR_WRITE_TO_REPLICAS: &str = "errorWriteToReplicas"; +// EC shard copy failure reasons (Go: stats.EcShardCopy*). +pub const EC_SHARD_COPY_SOURCE_NOT_FOUND: &str = "source_not_found"; +pub const EC_SHARD_COPY_EMPTY_INDEX: &str = "empty_index"; +pub const EC_SHARD_COPY_NO_SPACE: &str = "no_space"; +pub const EC_SHARD_COPY_TIMEOUT: &str = "timeout"; +pub const EC_SHARD_COPY_IO_ERROR: &str = "io_error"; +pub const EC_SHARD_COPY_OTHER: &str = "other"; + // Go volume heartbeat metric label values. pub const READ_ONLY_LABEL_IS_READ_ONLY: &str = "IsReadOnly"; pub const READ_ONLY_LABEL_NO_WRITE_OR_DELETE: &str = "noWriteOrDelete"; @@ -432,6 +453,7 @@ pub fn register_metrics() { Box::new(SCRUB_SHARD_FAILURES.clone()), Box::new(STORAGE_IO_ERROR_COUNTER.clone()), Box::new(EC_RECONSTRUCTED_INTERVAL_COUNTER.clone()), + Box::new(EC_SHARD_COPY_FAILURES.clone()), Box::new(IO_QUARANTINE_GAUGE.clone()), // Legacy metrics Box::new(VOLUMES_TOTAL.clone()), diff --git a/seaweed-volume/src/server/grpc_server.rs b/seaweed-volume/src/server/grpc_server.rs index 631458ad0c..0b11b738b5 100644 --- a/seaweed-volume/src/server/grpc_server.rs +++ b/seaweed-volume/src/server/grpc_server.rs @@ -52,6 +52,36 @@ fn scrub_mode_label(mode: i32) -> &'static str { } /// Go formats the id in decimal; fs.verify matches the "needle not found " prefix. +/// Maps a failed EC shard copy to a bounded reason label. Errors from the +/// source arrive as gRPC text, so it matches messages. Mirrors Go's +/// ecShardCopyFailureReason. +fn ec_shard_copy_failure_reason(status: &Status) -> &'static str { + use crate::metrics as m; + let code = status.code(); + let msg = status.message().to_lowercase(); + if msg.contains(".ecx is 0 bytes") { + m::EC_SHARD_COPY_EMPTY_INDEX + } else if code == tonic::Code::ResourceExhausted || msg.contains("no space left") { + m::EC_SHARD_COPY_NO_SPACE + } else if code == tonic::Code::DeadlineExceeded + || msg.contains("deadline exceeded") + || msg.contains("deadlineexceeded") + || msg.contains("deadline expired") + || msg.contains("deadline has elapsed") + || msg.contains("timeout") + || msg.contains("timed out") + { + m::EC_SHARD_COPY_TIMEOUT + } else if code == tonic::Code::NotFound || msg.contains("not found") || msg.contains("notfound") + { + m::EC_SHARD_COPY_SOURCE_NOT_FOUND + } else if msg.contains("input/output error") { + m::EC_SHARD_COPY_IO_ERROR + } else { + m::EC_SHARD_COPY_OTHER + } +} + fn needle_not_found(needle_id: NeedleId) -> Status { Status::not_found(format!("needle not found {}", needle_id.0)) } @@ -3931,16 +3961,42 @@ impl VolumeServer for VolumeGrpcService { state: self.state.clone(), }; let request_id = crate::server::request_id::current_request_id(); + let collection = req.collection.clone(); + let source = req.source_data_node.clone(); + let wire_shard_ids = req.shard_ids.clone(); + let report = move |status: &Status| { + let reason = ec_shard_copy_failure_reason(status); + crate::metrics::EC_SHARD_COPY_FAILURES + .with_label_values(&[collection.as_str(), reason]) + .inc(); + tracing::warn!( + "VolumeEcShardsCopy volume {} shards {:?} from {} failed ({}): {}", + vid, + wire_shard_ids, + source, + reason, + status.message() + ); + }; + let task_report = report.clone(); tokio::spawn(async move { let _lifecycle = lifecycle; let copy = svc.volume_ec_shards_copy_locked(req, vid, shard_ids); - match request_id { + let result = match request_id { Some(id) => crate::server::request_id::scope_request_id(id, copy).await, None => copy.await, + }; + if let Err(status) = &result { + task_report(status); } + result }) .await - .map_err(|e| Status::internal(format!("VolumeEcShardsCopy volume {}: {}", vid, e)))? + .map_err(|e| { + let status = Status::internal(format!("VolumeEcShardsCopy volume {}: {}", vid, e)); + report(&status); + status + })? } /// Allowed in maintenance mode: like `volume_delete` it only removes data, and @@ -8435,6 +8491,75 @@ mod tests { use tempfile::TempDir; use tokio_stream::StreamExt; + #[test] + fn test_ec_shard_copy_failure_reason() { + use crate::metrics as m; + let cases = [ + ( + Status::internal(format!( + "VolumeEcShardsCopy volume 7 copy .ec01: {}", + Status::not_found("No such file or directory (os error 2)") + )), + m::EC_SHARD_COPY_SOURCE_NOT_FOUND, + ), + ( + Status::internal( + "failed to copy /d/7.ec01 file: rpc error: code = NotFound desc = gone", + ), + m::EC_SHARD_COPY_SOURCE_NOT_FOUND, + ), + ( + Status::internal(format!( + "VolumeEcShardsCopy volume 7 copy .ec01: {}", + Status::deadline_exceeded("stream") + )), + m::EC_SHARD_COPY_TIMEOUT, + ), + ( + Status::internal( + "VolumeEcShardsCopy volume 7: failed to copy /d/7.ec01 file: CopyFile not found ec volume id 7", + ), + m::EC_SHARD_COPY_SOURCE_NOT_FOUND, + ), + ( + Status::not_found("volume 7"), + m::EC_SHARD_COPY_SOURCE_NOT_FOUND, + ), + ( + Status::failed_precondition("VolumeEcShardsCopy volume 7: source .ecx is 0 bytes"), + m::EC_SHARD_COPY_EMPTY_INDEX, + ), + (Status::internal("no space left"), m::EC_SHARD_COPY_NO_SPACE), + ( + Status::internal("write 7.ec01.copying: No space left on device (os error 28)"), + m::EC_SHARD_COPY_NO_SPACE, + ), + ( + Status::deadline_exceeded("stream"), + m::EC_SHARD_COPY_TIMEOUT, + ), + ( + Status::internal("copy 7.ec01: deadline has elapsed"), + m::EC_SHARD_COPY_TIMEOUT, + ), + ( + Status::unknown("context deadline exceeded"), + m::EC_SHARD_COPY_TIMEOUT, + ), + ( + Status::internal("write 7.ec01.copying: Input/output error (os error 5)"), + m::EC_SHARD_COPY_IO_ERROR, + ), + ( + Status::failed_precondition("copied shards are encode run 1 but /d mounts run 2"), + m::EC_SHARD_COPY_OTHER, + ), + ]; + for (status, want) in cases { + assert_eq!(ec_shard_copy_failure_reason(&status), want, "{status:?}"); + } + } + fn loc(dir: &str, idx_dir: &str, shard_count: usize, has_ecx: bool) -> LocInfo { LocInfo { dir: dir.to_string(), diff --git a/weed/server/volume_grpc_erasure_coding.go b/weed/server/volume_grpc_erasure_coding.go index b80c7dba3e..22963d4a33 100644 --- a/weed/server/volume_grpc_erasure_coding.go +++ b/weed/server/volume_grpc_erasure_coding.go @@ -395,7 +395,7 @@ func (vs *VolumeServer) VolumeEcShardsRebuild(ctx context.Context, req *volume_s } // VolumeEcShardsCopy copy the .ecx and some ec data slices -func (vs *VolumeServer) VolumeEcShardsCopy(ctx context.Context, req *volume_server_pb.VolumeEcShardsCopyRequest) (*volume_server_pb.VolumeEcShardsCopyResponse, error) { +func (vs *VolumeServer) VolumeEcShardsCopy(ctx context.Context, req *volume_server_pb.VolumeEcShardsCopyRequest) (_ *volume_server_pb.VolumeEcShardsCopyResponse, err error) { if err := vs.checkGrpcAdminAuth(ctx); err != nil { return nil, err } @@ -409,6 +409,13 @@ func (vs *VolumeServer) VolumeEcShardsCopy(ctx context.Context, req *volume_serv } glog.V(0).Infof("VolumeEcShardsCopy: %v", req) + defer func() { + if err != nil { + reason := ecShardCopyFailureReason(err) + stats.VolumeServerEcShardCopyFailures.WithLabelValues(req.Collection, reason).Inc() + glog.Warningf("VolumeEcShardsCopy volume %d shards %v from %s failed (%s): %v", req.VolumeId, req.ShardIds, req.SourceDataNode, reason, err) + } + }() // Overlapping copies of one vid would share the staged index, and a failed // one's cleanup would remove shards another already committed. @@ -493,7 +500,7 @@ func (vs *VolumeServer) VolumeEcShardsCopy(ctx context.Context, req *volume_serv // A failed copy removes what it added, or every retry against the same // unusable source strands another unmounted shard on this disk. var created ecCopyCreatedFiles - err := operation.WithVolumeServerClientOptions(true, pb.ServerAddress(req.SourceDataNode), func(client volume_server_pb.VolumeServerClient) error { + err = operation.WithVolumeServerClientOptions(true, pb.ServerAddress(req.SourceDataNode), func(client volume_server_pb.VolumeServerClient) error { // The index is staged first, so a source whose .ecx is unusable fails // the copy before any shard lands here. It is committed after every @@ -613,6 +620,26 @@ func (vs *VolumeServer) VolumeEcShardsCopy(ctx context.Context, req *volume_serv return &volume_server_pb.VolumeEcShardsCopyResponse{}, nil } +// ecShardCopyFailureReason maps a failed EC shard copy to a bounded reason +// label. Errors from the source arrive as gRPC text, so it matches messages. +func ecShardCopyFailureReason(err error) string { + code := status.Code(err) + msg := strings.ToLower(err.Error()) + switch { + case strings.Contains(msg, ".ecx is 0 bytes"): + return stats.EcShardCopyEmptyIndex + case code == codes.ResourceExhausted || strings.Contains(msg, "no space left"): + return stats.EcShardCopyNoSpace + case code == codes.DeadlineExceeded || errors.Is(err, context.DeadlineExceeded) || strings.Contains(msg, "deadline exceeded") || strings.Contains(msg, "deadlineexceeded") || strings.Contains(msg, "deadline expired") || strings.Contains(msg, "deadline has elapsed") || strings.Contains(msg, "timeout") || strings.Contains(msg, "timed out"): + return stats.EcShardCopyTimeout + case code == codes.NotFound || strings.Contains(msg, "not found") || strings.Contains(msg, "notfound"): + return stats.EcShardCopySourceNotFound + case strings.Contains(msg, "input/output error"): + return stats.EcShardCopyIoError + } + return stats.EcShardCopyOther +} + // requireMountedEncodeRun refuses a copied .vif of another encode run than the // one this server mounts for the volume: the mounted volume would keep // reporting its run while serving the copied bytes. diff --git a/weed/server/volume_grpc_erasure_coding_copy_failure_test.go b/weed/server/volume_grpc_erasure_coding_copy_failure_test.go new file mode 100644 index 0000000000..9f97d663e4 --- /dev/null +++ b/weed/server/volume_grpc_erasure_coding_copy_failure_test.go @@ -0,0 +1,42 @@ +package weed_server + +import ( + "context" + "errors" + "fmt" + "syscall" + "testing" + + "github.com/seaweedfs/seaweedfs/weed/stats" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func TestEcShardCopyFailureReason(t *testing.T) { + cases := []struct { + name string + err error + want string + }{ + {"source lost the shard", fmt.Errorf("VolumeEcShardsCopy volume 7: %w", errors.New("failed to copy /d/7.ec01 file: receiving: rpc error: code = Unknown desc = CopyFile not found ec volume id 7")), stats.EcShardCopySourceNotFound}, + {"not found status", status.Error(codes.NotFound, "volume 7"), stats.EcShardCopySourceNotFound}, + {"wrapped not found status", fmt.Errorf("failed to copy /d/7.ec01 file: %v", status.Error(codes.NotFound, "No such file or directory (os error 2)")), stats.EcShardCopySourceNotFound}, + {"wrapped rust not found", errors.New("VolumeEcShardsCopy volume 7 copy .ec01: code: 'Some requested entity was not found', message: \"No such file or directory (os error 2)\""), stats.EcShardCopySourceNotFound}, + {"empty index", fmt.Errorf("VolumeEcShardsCopy volume 7: %w", errors.New("VolumeEcShardsCopy volume 7: source .ecx is 0 bytes")), stats.EcShardCopyEmptyIndex}, + {"no target disk", status.Error(codes.ResourceExhausted, "no space left"), stats.EcShardCopyNoSpace}, + {"disk full", fmt.Errorf("write /d/7.ec01.copying: %w", syscall.ENOSPC), stats.EcShardCopyNoSpace}, + {"deadline", fmt.Errorf("VolumeEcShardsCopy volume 7: %w", context.DeadlineExceeded), stats.EcShardCopyTimeout}, + {"deadline status", status.Error(codes.DeadlineExceeded, "stream"), stats.EcShardCopyTimeout}, + {"wrapped deadline status", fmt.Errorf("failed to copy /d/7.ec01 file: %v", status.Error(codes.DeadlineExceeded, "stream")), stats.EcShardCopyTimeout}, + {"wrapped rust deadline", errors.New("copy .ec01: code: 'Deadline expired before operation could complete', message: \"stream\""), stats.EcShardCopyTimeout}, + {"rust source deadline", errors.New("rpc error: code = Internal desc = copy 7.ec01: deadline has elapsed"), stats.EcShardCopyTimeout}, + {"network timeout", errors.New("read tcp 10.0.0.1:1->10.0.0.2:2: i/o timeout"), stats.EcShardCopyTimeout}, + {"io error", fmt.Errorf("write /d/7.ec01.copying: %w", syscall.EIO), stats.EcShardCopyIoError}, + {"other", errors.New("copied shards are encode run 1 but /d mounts run 2"), stats.EcShardCopyOther}, + } + for _, c := range cases { + if got := ecShardCopyFailureReason(c.err); got != c.want { + t.Errorf("%s: got %q, want %q", c.name, got, c.want) + } + } +} diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index 7db6ed4f78..28cf89939d 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -757,6 +757,14 @@ var ( Help: "Reads of an EC interval served by reconstructing from other shards; success means reconstruction produced data, not that the needle passed validation.", }, []string{"result"}) + VolumeServerEcShardCopyFailures = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: Namespace, + Subsystem: subsystemVolumeServer, + Name: "ec_shard_copy_failures_total", + Help: "Counter of failed EC shard copies into this server by collection and reason.", + }, []string{"collection", "reason"}) + S3RequestCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, @@ -1195,6 +1203,7 @@ func init() { Gather.MustRegister(VolumeServerECRebuildHistogram) Gather.MustRegister(VolumeServerECRebuildCounter) Gather.MustRegister(VolumeServerECReconstructedIntervalCounter) + Gather.MustRegister(VolumeServerEcShardCopyFailures) Gather.MustRegister(MasterUnderReplicatedVolumes) Gather.MustRegister(MasterWritableVolumesPerDisk) Gather.MustRegister(MasterVolumeCreationCounter) diff --git a/weed/stats/metrics_names.go b/weed/stats/metrics_names.go index a6fd629485..7949cb3a63 100644 --- a/weed/stats/metrics_names.go +++ b/weed/stats/metrics_names.go @@ -83,6 +83,14 @@ const ( // FailureServerError is the failure reason label for generic server-side errors. FailureServerError = "server_error" + // EC shard copy failure reasons. + EcShardCopySourceNotFound = "source_not_found" + EcShardCopyEmptyIndex = "empty_index" + EcShardCopyNoSpace = "no_space" + EcShardCopyTimeout = "timeout" + EcShardCopyIoError = "io_error" + EcShardCopyOther = "other" + // remote-mount cache read labels RemoteCacheSourceFiler = "filer" RemoteCacheSourceS3 = "s3"