snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
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
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
This commit is contained in:
260
weed/server/filer_grpc_server_stream_mutate.go
Normal file
260
weed/server/filer_grpc_server_stream_mutate.go
Normal file
@@ -0,0 +1,260 @@
|
||||
package weed_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
// streamMutateConcurrency bounds the number of in-flight mutations processed
|
||||
// concurrently per client stream. Set to the typical filer-store sweet spot
|
||||
// so one noisy mount cannot exhaust filer resources.
|
||||
const streamMutateConcurrency = 64
|
||||
|
||||
// streamMutatePendingLimit caps total outstanding requests per stream
|
||||
// (admitted + waiting-for-admission). Prevents goroutine explosion when a
|
||||
// client floods requests against a conflicted path while leaving enough
|
||||
// headroom that cross-path requests never block Recv in practice.
|
||||
const streamMutatePendingLimit = 1024
|
||||
|
||||
// syncStream wraps a bidi stream so that concurrent goroutines can Send
|
||||
// without interleaving frames. gRPC requires that Send not be called
|
||||
// concurrently; this mutex is the serialization point.
|
||||
type syncStream struct {
|
||||
stream grpc.BidiStreamingServer[filer_pb.StreamMutateEntryRequest, filer_pb.StreamMutateEntryResponse]
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func (s *syncStream) Send(r *filer_pb.StreamMutateEntryResponse) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.stream.Send(r)
|
||||
}
|
||||
|
||||
func (fs *FilerServer) StreamMutateEntry(stream grpc.BidiStreamingServer[filer_pb.StreamMutateEntryRequest, filer_pb.StreamMutateEntryResponse]) error {
|
||||
ss := &syncStream{stream: stream}
|
||||
// Path-keyed admission + subtree barriers, adapted from filer.sync's
|
||||
// MetadataProcessor (weed/command/filer_sync_jobs.go). Admit blocks when
|
||||
// a new request conflicts with an in-flight one on the same path or with
|
||||
// a barrier directory at the same path / an ancestor.
|
||||
sched := newMutateScheduler(streamMutateConcurrency)
|
||||
// pendingSem caps goroutines-per-stream. The receive loop only blocks on
|
||||
// this sem (not on Admit), so one conflicted path cannot head-of-line
|
||||
// block receipt of unrelated paths — later distinct-path requests can be
|
||||
// spawned, admitted, and processed while the conflicted request waits.
|
||||
pendingSem := make(chan struct{}, streamMutatePendingLimit)
|
||||
var wg sync.WaitGroup
|
||||
// Track the first fatal send error across worker goroutines.
|
||||
var sendErrMu sync.Mutex
|
||||
var sendErr error
|
||||
setSendErr := func(e error) {
|
||||
sendErrMu.Lock()
|
||||
if sendErr == nil {
|
||||
sendErr = e
|
||||
}
|
||||
sendErrMu.Unlock()
|
||||
}
|
||||
getSendErr := func() error {
|
||||
sendErrMu.Lock()
|
||||
defer sendErrMu.Unlock()
|
||||
return sendErr
|
||||
}
|
||||
|
||||
for {
|
||||
if e := getSendErr(); e != nil {
|
||||
wg.Wait()
|
||||
return e
|
||||
}
|
||||
req, err := stream.Recv()
|
||||
if err == io.EOF {
|
||||
wg.Wait()
|
||||
return getSendErr()
|
||||
}
|
||||
if err != nil {
|
||||
wg.Wait()
|
||||
return err
|
||||
}
|
||||
|
||||
primary, secondary, kind := classifyMutation(req)
|
||||
pendingSem <- struct{}{}
|
||||
wg.Add(1)
|
||||
go func(req *filer_pb.StreamMutateEntryRequest, p, s util.FullPath, k mutateJobKind) {
|
||||
defer wg.Done()
|
||||
defer func() { <-pendingSem }()
|
||||
// Admission happens off the Recv loop so a conflicted path never
|
||||
// blocks receipt of unrelated requests.
|
||||
sched.Admit(p, s, k)
|
||||
defer sched.Done(p, s, k)
|
||||
if e := fs.handleStreamMutateRequest(ss, req); e != nil {
|
||||
setSendErr(e)
|
||||
}
|
||||
}(req, primary, secondary, kind)
|
||||
}
|
||||
}
|
||||
|
||||
// handleStreamMutateRequest processes one request and sends exactly one
|
||||
// (possibly multi-message) response via the shared sync stream. It returns
|
||||
// a non-nil error only if Send fails — in which case the caller should
|
||||
// tear down the stream.
|
||||
func (fs *FilerServer) handleStreamMutateRequest(ss *syncStream, req *filer_pb.StreamMutateEntryRequest) error {
|
||||
switch r := req.Request.(type) {
|
||||
|
||||
case *filer_pb.StreamMutateEntryRequest_CreateRequest:
|
||||
resp, createErr := fs.CreateEntry(ss.stream.Context(), r.CreateRequest)
|
||||
if createErr != nil {
|
||||
resp = &filer_pb.CreateEntryResponse{Error: createErr.Error()}
|
||||
}
|
||||
out := &filer_pb.StreamMutateEntryResponse{
|
||||
RequestId: req.RequestId,
|
||||
IsLast: true,
|
||||
Response: &filer_pb.StreamMutateEntryResponse_CreateResponse{CreateResponse: resp},
|
||||
}
|
||||
if resp.Error != "" {
|
||||
out.Error = resp.Error
|
||||
out.Errno = int32(syscall.EIO)
|
||||
}
|
||||
return ss.Send(out)
|
||||
|
||||
case *filer_pb.StreamMutateEntryRequest_UpdateRequest:
|
||||
resp, updateErr := fs.UpdateEntry(ss.stream.Context(), r.UpdateRequest)
|
||||
if updateErr != nil {
|
||||
resp = &filer_pb.UpdateEntryResponse{}
|
||||
}
|
||||
out := &filer_pb.StreamMutateEntryResponse{
|
||||
RequestId: req.RequestId,
|
||||
IsLast: true,
|
||||
Response: &filer_pb.StreamMutateEntryResponse_UpdateResponse{UpdateResponse: resp},
|
||||
}
|
||||
if updateErr != nil {
|
||||
out.Error = updateErr.Error()
|
||||
out.Errno = int32(syscall.EIO)
|
||||
}
|
||||
return ss.Send(out)
|
||||
|
||||
case *filer_pb.StreamMutateEntryRequest_DeleteRequest:
|
||||
resp, deleteErr := fs.DeleteEntry(ss.stream.Context(), r.DeleteRequest)
|
||||
if deleteErr != nil {
|
||||
resp = &filer_pb.DeleteEntryResponse{Error: deleteErr.Error()}
|
||||
}
|
||||
out := &filer_pb.StreamMutateEntryResponse{
|
||||
RequestId: req.RequestId,
|
||||
IsLast: true,
|
||||
Response: &filer_pb.StreamMutateEntryResponse_DeleteResponse{DeleteResponse: resp},
|
||||
}
|
||||
if resp.Error != "" {
|
||||
out.Error = resp.Error
|
||||
out.Errno = int32(syscall.EIO)
|
||||
}
|
||||
return ss.Send(out)
|
||||
|
||||
case *filer_pb.StreamMutateEntryRequest_RenameRequest:
|
||||
return fs.handleStreamMutateRename(ss, req.RequestId, r.RenameRequest)
|
||||
|
||||
default:
|
||||
// Send a terminal error response so the client's per-RequestId waiter
|
||||
// is released; returning nil here would leak the client-side waiter
|
||||
// forever when a future oneof variant or a malformed request arrives.
|
||||
glog.Warningf("StreamMutateEntry: unknown request type %T", req.Request)
|
||||
return ss.Send(&filer_pb.StreamMutateEntryResponse{
|
||||
RequestId: req.RequestId,
|
||||
IsLast: true,
|
||||
Error: "unknown request type",
|
||||
Errno: int32(syscall.EINVAL),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// handleStreamMutateRename delegates to the existing StreamRenameEntry logic
|
||||
// using a proxy stream that converts StreamRenameEntryResponse events into
|
||||
// StreamMutateEntryResponse messages on the parent bidi stream.
|
||||
func (fs *FilerServer) handleStreamMutateRename(
|
||||
parent *syncStream,
|
||||
requestId uint64,
|
||||
req *filer_pb.StreamRenameEntryRequest,
|
||||
) error {
|
||||
proxy := &renameStreamProxy{parent: parent, requestId: requestId}
|
||||
renameErr := fs.StreamRenameEntry(req, proxy)
|
||||
// Always send a final is_last=true to signal rename completion.
|
||||
finalResp := &filer_pb.StreamMutateEntryResponse{
|
||||
RequestId: requestId,
|
||||
IsLast: true,
|
||||
Response: &filer_pb.StreamMutateEntryResponse_RenameResponse{
|
||||
RenameResponse: &filer_pb.StreamRenameEntryResponse{},
|
||||
},
|
||||
}
|
||||
if renameErr != nil {
|
||||
finalResp.Error = renameErr.Error()
|
||||
finalResp.Errno = renameErrno(renameErr)
|
||||
glog.V(0).Infof("StreamMutateEntry rename: %v", renameErr)
|
||||
}
|
||||
return parent.Send(finalResp)
|
||||
}
|
||||
|
||||
// renameStreamProxy adapts the bidi StreamMutateEntry stream to look like a
|
||||
// SeaweedFiler_StreamRenameEntryServer, which is what StreamRenameEntry and
|
||||
// moveEntry expect. Each Send() call forwards the response as a non-final
|
||||
// StreamMutateEntryResponse.
|
||||
type renameStreamProxy struct {
|
||||
parent *syncStream
|
||||
requestId uint64
|
||||
}
|
||||
|
||||
func (p *renameStreamProxy) Send(resp *filer_pb.StreamRenameEntryResponse) error {
|
||||
return p.parent.Send(&filer_pb.StreamMutateEntryResponse{
|
||||
RequestId: p.requestId,
|
||||
IsLast: false,
|
||||
Response: &filer_pb.StreamMutateEntryResponse_RenameResponse{RenameResponse: resp},
|
||||
})
|
||||
}
|
||||
|
||||
func (p *renameStreamProxy) Context() context.Context {
|
||||
return p.parent.stream.Context()
|
||||
}
|
||||
|
||||
// SendMsg routes through Send so the payload is wrapped into a
|
||||
// StreamMutateEntryResponse and goes through the syncStream mutex. Calling
|
||||
// SendMsg with anything other than *filer_pb.StreamRenameEntryResponse would
|
||||
// emit the wrong protobuf type on this RPC, so reject other shapes.
|
||||
func (p *renameStreamProxy) SendMsg(m any) error {
|
||||
resp, ok := m.(*filer_pb.StreamRenameEntryResponse)
|
||||
if !ok {
|
||||
return fmt.Errorf("renameStreamProxy.SendMsg: unexpected type %T", m)
|
||||
}
|
||||
return p.Send(resp)
|
||||
}
|
||||
|
||||
// RecvMsg on the proxy would race with the outer StreamMutateEntry recv
|
||||
// loop and could steal unrelated mutation requests. The rename logic never
|
||||
// calls RecvMsg (it is strictly a server-push stream), so fail loudly if it
|
||||
// ever does.
|
||||
func (p *renameStreamProxy) RecvMsg(m any) error {
|
||||
return fmt.Errorf("renameStreamProxy.RecvMsg is not supported")
|
||||
}
|
||||
|
||||
func (p *renameStreamProxy) SetHeader(md metadata.MD) error { return p.parent.stream.SetHeader(md) }
|
||||
func (p *renameStreamProxy) SendHeader(md metadata.MD) error { return p.parent.stream.SendHeader(md) }
|
||||
func (p *renameStreamProxy) SetTrailer(md metadata.MD) { p.parent.stream.SetTrailer(md) }
|
||||
|
||||
// renameErrno maps a rename error to a POSIX errno for the client.
|
||||
func renameErrno(err error) int32 {
|
||||
msg := err.Error()
|
||||
switch {
|
||||
case strings.Contains(msg, "not found"):
|
||||
return int32(syscall.ENOENT)
|
||||
case strings.Contains(msg, "not empty"):
|
||||
return int32(syscall.ENOTEMPTY)
|
||||
case strings.Contains(msg, "not directory"):
|
||||
return int32(syscall.ENOTDIR)
|
||||
default:
|
||||
return int32(syscall.EIO)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user