Files
seaweedfs/weed/server/master_grpc_server_collection.go
T
Chris LuandClaude Opus 5.5 f2e9e49842 master: stop volume growth from leaking volumes into a just-deleted collection (#13035)
* topology: stop a grow once a delete fences its collection

A grow request creates its volumes one after another and resolves the
collection by name for each, so once the collection was deleted the rest of
the request recreated it. The request now keeps the collection it started
in and holds a per-collection fence shared while it creates each volume. A
delete can raise the fence exclusively, which waits out the volume in
flight, and the request stops at its next volume. A collection dropped only
because its last layout emptied is followed to the one published under its
name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* master: fence volume growth before deleting a collection

The delete listed the collection's servers, fanned out DeleteCollection, and
only then dropped the collection from the topology. A grow still running
created its next volumes during or after the fan-out, on servers that had
already been cleaned or were not in the list, and those volumes registered a
new layout for the deleted collection that nothing removed. A bucket deleted
right after its first write leaked most of its initial volumes this way.

The delete now raises the collection's growth fence first, so the volume in
flight registers and is deleted with the rest, and the grow stops. A failed
fan-out lifts the fence, since the collection stays in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: refuse assigns from a collection being deleted

The delete waits for the volume a grow is creating before it lists the
collection's servers, and the collection's writable volumes stayed
assignable meanwhile, so a write could land in a volume about to be
deleted. The delete now raises the fence before it waits, and assigns
check it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: list only collections that hold a volume layout

A grow request publishes its collection before its first volume
registers, so one that created nothing left a collection with no
volume in the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: queue no grow for a collection being deleted

PickForWrite returned the layout's shouldGrow before it checked the
fence, so an assign on an empty layout of a collection being deleted
still queued a grow. That grow could run after the delete finished and
recreate the collection. Check the fence right after the pick, before
any early return.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: keep an emptied collection published while growth holds it

DeleteLayout unpublished a collection as soon as its last layout
emptied, even while a grow held it or a delete had fenced it. The
volume in flight then registered by name into a new collection that
the delete never listed servers for, and the delete's final
DeleteCollection dropped it from the topology while it stayed on disk.
Unpublish an empty collection only when no grow or delete holds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: fence the collection still published under the name

An emptied-layout cleanup that passed its fence check could unpublish the
collection while the delete waited to fence it. The delete then fenced and
listed an orphaned object, while growth published a new collection under
the name that no fence held. Topology.FenceGrowth re-checks publication
once the fence is up and moves to the collection published since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: run one delete of a collection at a time

Two deletes of one collection both fenced it and fanned out by name. Once
the first removed it, a write could recreate the collection, and the
second delete removed the new one's volumes and topology entry.
FenceGrowth now waits for a delete already running on the collection and
finds nothing once that delete removed it; a delete that failed hands
the collection to the one waiting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: stop a delete another delete beat to the collection

A delete that fenced the collection but had not yet checked that it was
still published retried when it was not, for the collection an emptied
layout drops. A delete that removed it in between also left it
unpublished, so the retry fenced and returned the collection a write had
recreated under the name since. finish(true) now marks the collection
deleted before it unpublishes it, and the retry stops at that mark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* master: keep the name fenced through the EC pass of a delete

The normal pass unpublished the collection and let growth back in before
the EC pass ran. The EC pass deletes by name on every server holding the
collection's shards, and DeleteCollection on a server also drops its
normal volumes, so a write recreating the bucket in between could land a
volume that the EC pass then deleted. A second delete of the name, finding
no collection, also ran its own EC pass by name.

deleteCollection now fences the name once, before either pass, and lifts
or ends the fence after both. finish(true) unpublishes the collection then.
A name with EC shards only gets an empty collection to fence, so an assign
under it is refused too, and a delete that finds nothing skips both passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: wait for the second delete's lock instead of sleeping

The overlapping-delete tests slept before acting on the first delete. A
second delete scheduled late started after the collection was replaced, or
after the first delete was already over, so the tests could fail or pass
without the overlap they check. They now wait until the second delete is
blocked on the delete lock, read from the goroutine stacks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* topology: empty the layout through UnRegisterVolumeLayout in the test

The test called DeleteLayout, whose signature differs in builds that key
layouts by more than replication, TTL and disk type. UnRegisterVolumeLayout
reaches the same cleanup from a VolumeInfo and has one signature everywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 22:46:28 -08:00

146 lines
5.0 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"
"github.com/seaweedfs/seaweedfs/weed/topology"
)
// 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 err := ms.checkGrpcAdminAuth(ctx); err != nil {
return nil, err
}
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)
// Before listing the servers, and held through both passes: a grow still
// running, or an assign or grow under the name, would otherwise place a
// volume on a server one pass misses, or one that a pass then deletes by name.
collection, finish, ok := ms.Topo.FenceGrowth(collectionName)
if !ok {
return nil
}
normalErr := ms.doDeleteNormalCollection(ctx, collection)
ecErr := ms.doDeleteEcCollection(ctx, collectionName)
finish(normalErr == nil)
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, collection *topology.Collection) error {
// 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)
}
return ms.deleteCollectionFrom(ctx, collection.Name, servers)
}
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
}