mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-08 15:41:15 +02:00
* 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
184 lines
6.3 KiB
Go
184 lines
6.3 KiB
Go
package filer
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
"github.com/seaweedfs/seaweedfs/weed/util/log_buffer"
|
|
"github.com/seaweedfs/seaweedfs/weed/wdclient"
|
|
)
|
|
|
|
// collectionDeleteMaster is just enough of a master for a MasterClient to
|
|
// consider itself connected, and records every CollectionDelete it is asked for.
|
|
type collectionDeleteMaster struct {
|
|
master_pb.UnimplementedSeaweedServer
|
|
calls chan collectionDeleteCall
|
|
}
|
|
|
|
type collectionDeleteCall struct {
|
|
name string
|
|
// budget is the time the RPC arrived with, or 0 when it carried no deadline.
|
|
budget time.Duration
|
|
}
|
|
|
|
// KeepConnected is what MasterClient waits on before it reports a master: one
|
|
// response is enough, then the stream idles until the server is torn down.
|
|
func (m *collectionDeleteMaster) KeepConnected(stream master_pb.Seaweed_KeepConnectedServer) error {
|
|
if _, err := stream.Recv(); err != nil {
|
|
return err
|
|
}
|
|
if err := stream.Send(&master_pb.KeepConnectedResponse{}); err != nil {
|
|
return err
|
|
}
|
|
<-stream.Context().Done()
|
|
return nil
|
|
}
|
|
|
|
func (m *collectionDeleteMaster) CollectionDelete(ctx context.Context, req *master_pb.CollectionDeleteRequest) (*master_pb.CollectionDeleteResponse, error) {
|
|
call := collectionDeleteCall{name: req.Name}
|
|
if deadline, ok := ctx.Deadline(); ok {
|
|
call.budget = time.Until(deadline)
|
|
}
|
|
m.calls <- call
|
|
return &master_pb.CollectionDeleteResponse{}, nil
|
|
}
|
|
|
|
// hookedStore is the stub store with one extra seam: a callback that runs once
|
|
// an entry has actually been removed, so a test can interleave an event -- a
|
|
// client hanging up, say -- between the store write and whatever follows it.
|
|
type hookedStore struct {
|
|
*stubFilerStore
|
|
onDeleteEntry func(util.FullPath)
|
|
}
|
|
|
|
func (s *hookedStore) DeleteEntry(ctx context.Context, p util.FullPath) error {
|
|
if err := s.stubFilerStore.DeleteEntry(ctx, p); err != nil {
|
|
return err
|
|
}
|
|
if s.onDeleteEntry != nil {
|
|
s.onDeleteEntry(p)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// newFilerWithFakeMaster builds a filer backed by the stub store, with its
|
|
// MasterClient connected to a fake master the test can observe.
|
|
func newFilerWithFakeMaster(t *testing.T) (*Filer, *hookedStore, *collectionDeleteMaster) {
|
|
t.Helper()
|
|
|
|
master := &collectionDeleteMaster{calls: make(chan collectionDeleteCall, 4)}
|
|
|
|
lis, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
t.Fatalf("listen: %v", err)
|
|
}
|
|
grpcServer := grpc.NewServer()
|
|
master_pb.RegisterSeaweedServer(grpcServer, master)
|
|
go func() { _ = grpcServer.Serve(lis) }()
|
|
t.Cleanup(grpcServer.Stop)
|
|
|
|
_, port, err := net.SplitHostPort(lis.Addr().String())
|
|
if err != nil {
|
|
t.Fatalf("split listener address: %v", err)
|
|
}
|
|
masterAddress := pb.ServerAddress(fmt.Sprintf("127.0.0.1:0.%s", port))
|
|
|
|
mc := wdclient.NewMasterClient(
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
"test", cluster.FilerType, pb.ServerAddress("localhost:0"), "", "",
|
|
*pb.NewServiceDiscoveryFromMap(map[string]pb.ServerAddress{"m": masterAddress}),
|
|
)
|
|
|
|
connecting, stopConnecting := context.WithCancel(context.Background())
|
|
t.Cleanup(stopConnecting)
|
|
go mc.KeepConnectedToMaster(connecting)
|
|
|
|
waiting, cancelWaiting := context.WithTimeout(context.Background(), 20*time.Second)
|
|
defer cancelWaiting()
|
|
mc.WaitUntilConnected(waiting)
|
|
if waiting.Err() != nil {
|
|
t.Fatal("the master client never connected to the fake master")
|
|
}
|
|
|
|
store := &hookedStore{stubFilerStore: newStubFilerStore()}
|
|
f := &Filer{
|
|
DirBucketsPath: "/buckets",
|
|
RemoteStorage: NewFilerRemoteStorage(),
|
|
Store: NewFilerStoreWrapper(store),
|
|
FilerConf: NewFilerConf(),
|
|
MaxFilenameLength: 255,
|
|
MasterClient: mc,
|
|
FileIdDeletionQueue: util.NewUnboundedQueue(),
|
|
deletionQuit: make(chan struct{}),
|
|
LocalMetaLogBuffer: log_buffer.NewLogBuffer("test", time.Minute,
|
|
func(*log_buffer.LogBuffer, time.Time, time.Time, []byte, int64, int64) {}, nil, func() {}),
|
|
}
|
|
return f, store, master
|
|
}
|
|
|
|
// Deleting a bucket entry deletes its collection, and the request hanging up
|
|
// partway must not stop that: the bucket's metadata is already gone, so skipping
|
|
// it strands the bucket's volumes with nothing left to come back for them. The
|
|
// cleanup still has to carry a deadline of its own, or a master that is down
|
|
// parks this handler and every client retry behind it parks another.
|
|
//
|
|
// The cancellation lands between the store removing the entry and the collection
|
|
// delete, which is where a client disconnect actually bites: FilerStoreWrapper
|
|
// refuses a context that is already dead on entry, so an up-front cancellation
|
|
// fails the delete long before this point instead.
|
|
func TestDeleteEntryMetaAndDataDeletesCollectionWhenTheRequestIsCancelledMidDelete(t *testing.T) {
|
|
f, store, master := newFilerWithFakeMaster(t)
|
|
|
|
const bucket = "bucket-a"
|
|
bucketPath := util.FullPath(f.DirBucketsPath + "/" + bucket)
|
|
if err := store.InsertEntry(context.Background(), &Entry{
|
|
FullPath: bucketPath,
|
|
Attr: Attr{Mode: os.ModeDir | 0755},
|
|
}); err != nil {
|
|
t.Fatalf("seed the bucket entry: %v", err)
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
// The client hangs up just as the bucket entry comes out of the store.
|
|
store.onDeleteEntry = func(util.FullPath) { cancel() }
|
|
|
|
if err := f.DeleteEntryMetaAndData(ctx, bucketPath, true, false, true, false, nil, 0); err != nil {
|
|
t.Fatalf("DeleteEntryMetaAndData: %v", err)
|
|
}
|
|
if ctx.Err() == nil {
|
|
t.Fatal("test setup: the request was never cancelled, so nothing was exercised")
|
|
}
|
|
|
|
var call collectionDeleteCall
|
|
select {
|
|
case call = <-master.calls:
|
|
case <-time.After(20 * time.Second):
|
|
t.Fatal("CollectionDelete never reached the master")
|
|
}
|
|
if call.name != bucket {
|
|
t.Errorf("master was asked to delete collection %q, want %q", call.name, bucket)
|
|
}
|
|
if call.budget <= 0 {
|
|
t.Error("CollectionDelete arrived with no deadline; a master that stops answering would hold this handler open")
|
|
}
|
|
if call.budget > collectionDeleteTimeout {
|
|
t.Errorf("CollectionDelete budget = %v, want at most collectionDeleteTimeout %v", call.budget, collectionDeleteTimeout)
|
|
}
|
|
|
|
if store.getEntry(string(bucketPath)) != nil {
|
|
t.Error("the bucket entry survived the delete")
|
|
}
|
|
}
|