Files
seaweedfs/weed/server/master_grpc_server_collection.go
T
Chris LuandGitHub ba5b14b457 master, filer, s3api: bound the collection deletes that strand a caller (#11026)
* master: bound each volume server DeleteCollection, and finish the fan-out

A collection delete fanned out to every volume server holding it with
context.Background(), so a server that accepted the connection and then
went quiet held the whole delete open with nothing to end it. Each RPC is
bounded now, on the same budget allocateVolumeTimeout gives the other
master-to-volume-server admin RPC. The volume server runs the delete to
completion regardless of the request context, so giving up costs the
confirmation and not the deletion.

The walk itself is the caller's, not a per-server one:

- It outlives the caller. A cancelled request must not abandon a
  destructive fan-out part-done, with volumes left behind and no request
  still running to come back for them.
- It no longer stops at the first server that refuses, which left the
  collection on every server after it in the list. The first failure is
  still what is reported, and the collection stays in the topology so a
  later delete comes back for the rest.
- It sends one RPC per server rather than one per replica.
  ListVolumeServers reports a node once for every replica it holds, while
  DeleteCollection removes the whole collection from the server it
  reaches, so a collection with thousands of volumes repeated the same
  whole-collection delete thousands of times over.

Both passes run too. Returning after a failed normal pass left the
collection's EC shards in place with nothing left to retry them.

Claude-Session: https://claude.ai/code/session_01EnB1fbryyKc2LetRZxQPTP

* master: delete the EC shards behind /col/delete too

The HTTP handler carried its own copy of the volume-server walk and only
ever ran the normal pass, so a collection deleted through it kept its EC
shards. It shares the gRPC path now, which also gets it the bounded RPCs
and the one-per-server fan-out.

Claude-Session: https://claude.ai/code/session_01EnB1fbryyKc2LetRZxQPTP

* filer: bound the collection delete a bucket delete leaves behind

Deleting a bucket entry deletes its collection afterwards, deliberately
detached from the request so a client that hangs up cannot strand the
bucket's volumes. Detached meant unbounded, though: with the master down
or mid-election the wait for a leader has nothing to end it, so the
handler parks, and the client retrying behind it parks another.

It keeps outliving the request and now carries a deadline of its own. The
budget bounds the wait, not the work: the master keeps deleting on its own
fan-out once asked, so giving up costs the confirmation.

Claude-Session: https://claude.ai/code/session_01EnB1fbryyKc2LetRZxQPTP

* s3api: bound the collection RPCs a bucket creation and deletion issue

Neither carried a deadline, so a transient failure anywhere down the chain
held the S3 request open until the client gave up on it. Both budgets are
taken outside the filer failover walk, so one budget covers the whole walk
rather than granting each filer a fresh one.

The walk itself stops when that budget is spent, and stops without blaming
anyone: the caller's own expiry is not evidence against the filer that was
answering, and the next filer has no time left to answer in either.
Recorded as a filer failure, a slow master upstream would flag every filer
in the walk, and the three failures that open the circuit take unrelated
object reads down with them.

Claude-Session: https://claude.ai/code/session_01EnB1fbryyKc2LetRZxQPTP

* s3api: a failed collection listing no longer fails a bucket creation

PutBucket lists collections to notice a leftover one it is about to reuse.
The result feeds a warning and nothing else -- s3a.exists is what decides
whether the bucket already exists -- yet a transient failure of that
listing returned 500 and refused the creation. It is advisory now, so a
failure is logged and the creation continues, exactly as it does when the
listing returns false.

Claude-Session: https://claude.ai/code/session_01EnB1fbryyKc2LetRZxQPTP
2026-08-28 16:32:30 -07:00

144 lines
4.7 KiB
Go

package weed_server
import (
"context"
"time"
"github.com/seaweedfs/raft"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/operation"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
)
// deleteCollectionTimeout bounds one DeleteCollection RPC to a volume server, so
// a server that accepts the connection and then stops answering cannot hold the
// fan-out open with nothing to end it. Same bound as allocateVolumeTimeout, the
// other master-to-volume-server admin RPC. The volume server runs the delete to
// completion regardless of the request context, so giving up costs the
// confirmation and not the deletion.
const deleteCollectionTimeout = 1 * time.Minute
func (ms *MasterServer) CollectionList(ctx context.Context, req *master_pb.CollectionListRequest) (*master_pb.CollectionListResponse, error) {
if !ms.Topo.IsLeader() {
return nil, raft.NotLeaderError
}
resp := &master_pb.CollectionListResponse{}
collections := ms.Topo.ListCollections(req.IncludeNormalVolumes, req.IncludeEcVolumes)
for _, c := range collections {
resp.Collections = append(resp.Collections, &master_pb.Collection{
Name: c,
})
}
return resp, nil
}
func (ms *MasterServer) CollectionDelete(ctx context.Context, req *master_pb.CollectionDeleteRequest) (*master_pb.CollectionDeleteResponse, error) {
if !ms.Topo.IsLeader() {
return nil, raft.NotLeaderError
}
if err := ms.deleteCollection(ctx, req.Name); err != nil {
return nil, err
}
return &master_pb.CollectionDeleteResponse{}, nil
}
// deleteCollection removes a collection's normal volumes and its EC shards. Both
// passes run: one collection can hold both, and returning after a failed normal
// pass left the shards in place with no request left to come back for them. The
// normal pass keeps precedence in what is reported, as it did before.
func (ms *MasterServer) deleteCollection(ctx context.Context, collectionName string) error {
// Values only, no deadline: a caller that hangs up must not abandon a
// destructive fan-out part-done, with volumes left behind and no request still
// running to come back for them. Each RPC is bounded on its own.
ctx = context.WithoutCancel(ctx)
normalErr := ms.doDeleteNormalCollection(ctx, collectionName)
ecErr := ms.doDeleteEcCollection(ctx, collectionName)
if normalErr != nil {
if ecErr != nil {
glog.ErrorfCtx(ctx, "delete collection %s ec shards: %v", collectionName, ecErr)
}
return normalErr
}
return ecErr
}
func (ms *MasterServer) doDeleteNormalCollection(ctx context.Context, collectionName string) error {
collection, ok := ms.Topo.FindCollection(collectionName)
if !ok {
return nil
}
// One RPC per server, not one per replica: ListVolumeServers reports a node
// once for every replica it holds, while DeleteCollection removes the whole
// collection from the server it reaches. ListEcServersByCollection already
// returns each server once.
var servers []pb.ServerAddress
seen := make(map[pb.ServerAddress]struct{})
for _, node := range collection.ListVolumeServers() {
address := node.ServerAddress()
if _, done := seen[address]; done {
continue
}
seen[address] = struct{}{}
servers = append(servers, address)
}
if err := ms.deleteCollectionFrom(ctx, collectionName, servers); err != nil {
return err
}
ms.Topo.DeleteCollection(collectionName)
return nil
}
func (ms *MasterServer) doDeleteEcCollection(ctx context.Context, collectionName string) error {
if err := ms.deleteCollectionFrom(ctx, collectionName, ms.Topo.ListEcServersByCollection(collectionName)); err != nil {
return err
}
ms.Topo.DeleteEcCollection(collectionName)
return nil
}
// deleteCollectionFrom asks every server to drop the collection and keeps going
// past a failure, so one server that is down does not leave the collection on
// every server after it in the list. The first failure is what is reported, and
// the collection stays in the topology so a later delete comes back for the rest.
func (ms *MasterServer) deleteCollectionFrom(ctx context.Context, collectionName string, servers []pb.ServerAddress) error {
var firstErr error
for _, server := range servers {
err := operation.WithVolumeServerClient(false, server, ms.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
rpcCtx, cancel := context.WithTimeout(ctx, deleteCollectionTimeout)
defer cancel()
_, deleteErr := client.DeleteCollection(rpcCtx, &volume_server_pb.DeleteCollectionRequest{
Collection: collectionName,
})
return deleteErr
})
if err != nil {
glog.ErrorfCtx(ctx, "delete collection %s on %s: %v", collectionName, server, err)
if firstErr == nil {
firstErr = err
}
}
}
return firstErr
}