From 207aa69a9dc96a72fb22db8e83a2220dfd1651f0 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 29 Nov 2026 10:01:16 -0800 Subject: [PATCH] filer: keep the metadata log in its own collection, with room reserved for it (#13102) * filer: grow the metadata log collection on its own, fall back when it is full metaLog.volumeGrowthCount (default 2) is sent with assigns into the metadata log collection, so it grows by a few volumes instead of the master's default growth. When that collection cannot take the piece, the assign falls back to the collection the log uses without the override, so a full cluster does not stall the log. Co-Authored-By: Claude Opus 5.5 * filer: keep the metadata log in its own collection by default metaLog.collection now defaults to filer-meta, so purging old log days empties whole volumes instead of leaving log chunks scattered across the default collection's volumes. Setting it to "" keeps the log in the filer's -collection as before. Co-Authored-By: Claude Opus 5.5 * volume: default -max to 10 to leave room for the metadata log collection The default collection still grows by 7 volumes; the extra slots keep the filer's metadata log collection (2 volumes by default) from taking them. Go and Rust volume servers share the new default. Co-Authored-By: Claude Opus 5.5 * filer: bound the meta log collection's share of the assign budget A meta log collection that cannot grow (for example a replication the cluster cannot place) keeps answering with retryable errors, so the first assign used the whole shared budget and the fallback was never tried. Give it 10s, then fall back, and skip it for a minute after a failure instead of waiting on it at every flush. Co-Authored-By: Claude Opus 5.5 * filer: name the default meta log collection so no bucket maps to it A bucket named filer-meta mapped to the same collection, and deleting it from the admin page or weed shell drops the collection directly at the master, taking the metadata log with it. Bucket names cannot contain "_", and filer group buckets map to "_". Co-Authored-By: Claude Opus 5.5 * filer: clear the meta log overrides after the viper test Setting the collection back to its default value kept an explicit override, so the defaults test passed even without the SetDefault. Co-Authored-By: Claude Opus 5.5 * filer: retry the meta log collection once its fallback also fails The pause after a failed meta collection assign kept pieces on the shared collection for a full minute even when that assign failed too, so meta volumes that finished growing stayed unused while every flush failed. Co-Authored-By: Claude Opus 5.5 * filer: pick a default meta log collection no grouped bucket maps to Filer group "_filer" with bucket "meta" maps to "_filer_meta". The default now keeps its only "_" in front, and the test checks every group and bucket split of it. Co-Authored-By: Claude Opus 5.5 * filer: default the meta log collection to _meta Co-Authored-By: Claude Opus 5.5 * filer: keep the default meta log collection on bucket delete A filer that logs elsewhere did not treat _meta as reserved, so deleting a bucket a storage rule maps to _meta dropped the collection other filers write their logs to. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- seaweed-volume/src/config.rs | 2 +- weed/command/scaffold/filer.toml | 12 +- weed/command/scaffold/master.toml | 2 + weed/command/server.go | 2 +- weed/command/volume.go | 2 +- weed/filer/filer.go | 20 ++- weed/filer/filer_delete_collection_test.go | 21 +++ weed/filer/filer_delete_entry.go | 8 +- weed/filer/filer_notify_append.go | 71 +++++++-- .../filer_notify_append_compress_test.go | 140 ++++++++++++++++++ weed/filer/meta_log_collection_test.go | 32 +++- 11 files changed, 276 insertions(+), 36 deletions(-) diff --git a/seaweed-volume/src/config.rs b/seaweed-volume/src/config.rs index 7cb2ee7ede..f091ee11de 100644 --- a/seaweed-volume/src/config.rs +++ b/seaweed-volume/src/config.rs @@ -175,7 +175,7 @@ pub struct Cli { /// Maximum numbers of volumes, count[,count]... /// If set to zero, the limit will be auto configured as free disk space divided by volume size. - #[arg(long = "max", default_value = "8")] + #[arg(long = "max", default_value = "10")] pub max: String, /// Comma separated IP addresses having write permission. No limit if empty. diff --git a/weed/command/scaffold/filer.toml b/weed/command/scaffold/filer.toml index 6f65e0d30f..3800e1dc89 100644 --- a/weed/command/scaffold/filer.toml +++ b/weed/command/scaffold/filer.toml @@ -17,12 +17,18 @@ recursive_delete = false # increase this if using tools like Spark that create temporary directories. #s3.empty_folder_cleanup_delay = "2m" # where the filer's internal system metadata log chunks are stored. -# By default the log follows the filer's -collection flag; set this to keep -# the internal log in its own collection, out of the default one. +# By default the log has its own collection, so purging old log days frees +# whole volumes. Set it to "" to keep the log in the filer's -collection. +# Avoid a name a bucket maps to: deleting that bucket drops the collection. # Keep the target stable: log chunks written under an older value are not # moved, and old log entries keep referencing that collection's volumes. -#metaLog.collection = "filer-meta" +#metaLog.collection = "_meta" #metaLog.replication = "" +# volumes added each time the metadata log collection needs to grow. +# Keep this many free volume slots for it beside the master's volume_growth +# count; 0 uses the master's count. When the collection cannot grow, log +# chunks go to the filer's -collection until it can. +#metaLog.volumeGrowthCount = 2 #################################################### # The following are filer store options diff --git a/weed/command/scaffold/master.toml b/weed/command/scaffold/master.toml index fd16616b1b..cfca8826fc 100644 --- a/weed/command/scaffold/master.toml +++ b/weed/command/scaffold/master.toml @@ -55,6 +55,8 @@ storage_class = "STANDARD_IA" # 000 has only one copy, copy_1 # 010 and 001 has two copies, copy_2 # 011 has only 3 copies, copy_3 +# The filer's metadata log collection grows by metaLog.volumeGrowthCount in +# filer.toml instead; volume servers keep room for both by default (-max=10). [master.volume_growth] copy_1 = 7 # create 1 x 7 = 7 actual volumes copy_2 = 6 # create 2 x 6 = 12 actual volumes diff --git a/weed/command/server.go b/weed/command/server.go index cd2219bb08..0240e03469 100644 --- a/weed/command/server.go +++ b/weed/command/server.go @@ -69,7 +69,7 @@ var ( serverDisableHttp = cmdServer.Flag.Bool("disableHttp", false, "disable http requests, only gRPC operations are allowed.") serverIamConfig = cmdServer.Flag.String("iam.config", "", "path to the advanced IAM config file for S3. An alias for -s3.iam.config, but with lower priority.") volumeDataFolders = cmdServer.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...") - volumeMaxDataVolumeCounts = cmdServer.Flag.String("volume.max", "8", "maximum numbers of volumes, count[,count]... If set to zero, the limit will be auto configured as free disk space divided by volume size.") + volumeMaxDataVolumeCounts = cmdServer.Flag.String("volume.max", "10", "maximum numbers of volumes, count[,count]... If set to zero, the limit will be auto configured as free disk space divided by volume size.") volumeMinFreeSpacePercent = cmdServer.Flag.String("volume.minFreeSpacePercent", "1", "minimum free disk space (default to 1%). Low disk space will mark all volumes as ReadOnly (deprecated, use minFreeSpace instead).") volumeMinFreeSpace = cmdServer.Flag.String("volume.minFreeSpace", "", "min free disk space (value<=100 as percentage like 1, other as human readable bytes, like 10GiB). Low disk space will mark all volumes as ReadOnly.") serverMetricsHttpPort = cmdServer.Flag.Int("metricsPort", 0, "Prometheus metrics listen port") diff --git a/weed/command/volume.go b/weed/command/volume.go index 3471d93e88..d6a224fbd0 100644 --- a/weed/command/volume.go +++ b/weed/command/volume.go @@ -268,7 +268,7 @@ var cmdVolume = &Command{ var ( volumeFolders = cmdVolume.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...") - maxVolumeCounts = cmdVolume.Flag.String("max", "8", "maximum numbers of volumes, count[,count]... If set to zero, the limit will be auto configured as free disk space divided by volume size.") + maxVolumeCounts = cmdVolume.Flag.String("max", "10", "maximum numbers of volumes, count[,count]... If set to zero, the limit will be auto configured as free disk space divided by volume size.") volumeWhiteListOption = cmdVolume.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.") minFreeSpacePercent = cmdVolume.Flag.String("minFreeSpacePercent", "1", "minimum free disk space (default to 1%). Low disk space will mark all volumes as ReadOnly (deprecated, use minFreeSpace instead).") minFreeSpace = cmdVolume.Flag.String("minFreeSpace", "", "min free disk space (value<=100 as percentage like 1, other as human readable bytes, like 10GiB). Low disk space will mark all volumes as ReadOnly.") diff --git a/weed/filer/filer.go b/weed/filer/filer.go index fabdacf670..98969ab5bc 100644 --- a/weed/filer/filer.go +++ b/weed/filer/filer.go @@ -54,6 +54,10 @@ type DialOptions struct { Volume grpc.DialOption } +// No bucket maps to this collection: bucket names cannot contain "_", and a +// filer group's buckets map to "_", with a "_" after the group. +const defaultMetaLogCollection = "_meta" + type Filer struct { UniqueFilerId int32 UniqueFilerEpoch int32 @@ -73,11 +77,13 @@ type Filer struct { LocalMetaLogBuffer *log_buffer.LogBuffer metaLogCollection string metaLogReplication string - // Override where system metadata-log chunks are assigned, keeping the - // internal log out of the default collection; empty keeps today's - // behaviour. Set via viper: filer.options.metaLog.collection / .replication. + // Where system metadata-log chunks are assigned, keeping the internal log + // out of the default collection; empty follows the filer's collection. + // Set via viper: filer.options.metaLog.collection / .replication. metaLogTargetCollection string metaLogTargetReplication string + metaLogVolumeGrowthCount uint32 + metaLogOwnAssignPausedUntil atomic.Int64 DefaultDiskType string MetaAggregator *MetaAggregator Signature int32 @@ -181,15 +187,13 @@ func NewFiler(masters pb.ServerDiscovery, dialOptions *DialOptions, filerHost pb f.metaLogCollection = collection f.metaLogReplication = replication - // Optional override for where the system metadata-log chunks land, so - // operators can keep internal log volumes out of the default collection. - // Unset (""), this changes nothing: meta logs keep following the filer - // default exactly as before. v := util.GetViper() - v.SetDefault("filer.options.metaLog.collection", "") + v.SetDefault("filer.options.metaLog.collection", defaultMetaLogCollection) v.SetDefault("filer.options.metaLog.replication", "") + v.SetDefault("filer.options.metaLog.volumeGrowthCount", 2) f.metaLogTargetCollection = v.GetString("filer.options.metaLog.collection") f.metaLogTargetReplication = v.GetString("filer.options.metaLog.replication") + f.metaLogVolumeGrowthCount = v.GetUint32("filer.options.metaLog.volumeGrowthCount") if f.metaLogTargetCollection != "" { glog.V(0).Infof("system metadata logs will be stored in collection %q", f.metaLogTargetCollection) } diff --git a/weed/filer/filer_delete_collection_test.go b/weed/filer/filer_delete_collection_test.go index eae9ea6e3d..fecc1a8358 100644 --- a/weed/filer/filer_delete_collection_test.go +++ b/weed/filer/filer_delete_collection_test.go @@ -252,6 +252,27 @@ func TestDeleteBucketNamedAfterSharedCollection(t *testing.T) { } } +// A filer logging elsewhere still keeps the default meta log collection: +// other filers may write their logs there. +func TestDeleteBucketKeepsDefaultMetaLogCollection(t *testing.T) { + f, store, master := newFilerWithFakeMaster(t) + f.FilerConf.SetLocationConf(&filer_pb.FilerConf_PathConf{ + LocationPrefix: "/buckets/a", + Collection: defaultMetaLogCollection, + }) + seedBucket(t, store, util.FullPath("/buckets/a")) + + if err := f.DeleteEntryMetaAndData(context.Background(), "/buckets/a", true, false, true, false, nil, time.Time{}); err != nil { + t.Fatalf("DeleteEntryMetaAndData: %v", err) + } + + select { + case call := <-master.calls: + t.Fatalf("default meta log collection was deleted: %q", call.name) + default: + } +} + // A rule pointing a non-bucket path at the same collection keeps it: the // collection serves files the bucket delete must not orphan. func TestDeleteBucketKeepsCollectionUsedByNonBucketPath(t *testing.T) { diff --git a/weed/filer/filer_delete_entry.go b/weed/filer/filer_delete_entry.go index 88d0d91252..81318bc002 100644 --- a/weed/filer/filer_delete_entry.go +++ b/weed/filer/filer_delete_entry.go @@ -338,11 +338,9 @@ func (f *Filer) bucketCollection(ctx context.Context, bucket string) (collection // Rule-less writes outside buckets fall back to the filer's default // collection, so a bucket resolving there shares it with them. The - // system metadata-log collection (when explicitly redirected via - // filer.options.metaLog.collection) is in the same boat: it backs internal - // log volumes, so a bucket that resolves there must never drop it - // either. - if collection == f.metaLogCollection { + // metadata-log collections back internal log volumes, and the default one + // can serve other filers even when this one logs elsewhere. + if collection == f.metaLogCollection || collection == defaultMetaLogCollection { return "" } if f.metaLogTargetCollection != "" && collection == f.metaLogTargetCollection { diff --git a/weed/filer/filer_notify_append.go b/weed/filer/filer_notify_append.go index a769329ef4..4174905e28 100644 --- a/weed/filer/filer_notify_append.go +++ b/weed/filer/filer_notify_append.go @@ -95,6 +95,64 @@ func (f *Filer) metaLogReplicationFor(ruleReplication string) string { return util.Nvl(f.metaLogTargetReplication, f.metaLogReplication, ruleReplication) } +// metaLogAssignRequests lists the assigns to try, in order, for a metadata log +// piece: the meta log collection, then the collection the log uses without +// it, so a meta log collection that cannot grow does not stall the log. +func (f *Filer) metaLogAssignRequests(targetFile string, size int) []*operation.VolumeAssignRequest { + diskType, rule := f.resolveMetadataLogAssignDiskType(targetFile) + request := &operation.VolumeAssignRequest{ + Count: 1, + Collection: f.metaLogCollectionFor(rule.Collection), + Replication: f.metaLogReplicationFor(rule.Replication), + DiskType: diskType, + WritableVolumeCount: rule.VolumeGrowthCount, + ExpectedDataSize: uint64(size), + } + if f.metaLogTargetCollection == "" { + return []*operation.VolumeAssignRequest{request} + } + request.WritableVolumeCount = f.metaLogVolumeGrowthCount + shared := *request + shared.Collection = util.Nvl(f.metaLogCollection, rule.Collection) + shared.Replication = util.Nvl(f.metaLogReplication, rule.Replication) + shared.WritableVolumeCount = rule.VolumeGrowthCount + if shared.Collection == request.Collection { + return []*operation.VolumeAssignRequest{request} + } + return []*operation.VolumeAssignRequest{request, &shared} +} + +var ( + metaLogOwnAssignBudget = 10 * time.Second + metaLogOwnAssignPause = time.Minute +) + +// assignMetaLogPiece gives the meta log collection a bounded share of the +// assign budget, since a collection that cannot grow can keep answering with +// retryable errors. After it fails, pieces go straight to the fallback for a +// while instead of waiting on it again at every flush, until the fallback +// fails too. +func (f *Filer) assignMetaLogPiece(ctx context.Context, requests []*operation.VolumeAssignRequest) (*operation.AssignResult, error) { + if len(requests) == 1 { + return operation.Assign(ctx, f.GetMaster, f.masterGrpcDialOption(), requests[0]) + } + if time.Now().UnixNano() >= f.metaLogOwnAssignPausedUntil.Load() { + ownCtx, cancel := context.WithTimeout(ctx, metaLogOwnAssignBudget) + assignResult, err := operation.Assign(ownCtx, f.GetMaster, f.masterGrpcDialOption(), requests[0]) + cancel() + if err == nil || ctx.Err() != nil { + return assignResult, err + } + glog.V(1).Infof("assign metadata log piece in collection %q: %v; using %q for %v", requests[0].Collection, err, requests[1].Collection, metaLogOwnAssignPause) + f.metaLogOwnAssignPausedUntil.Store(time.Now().Add(metaLogOwnAssignPause).UnixNano()) + } + assignResult, err := operation.Assign(ctx, f.GetMaster, f.masterGrpcDialOption(), requests[1]) + if err != nil { + f.metaLogOwnAssignPausedUntil.Store(0) + } + return assignResult, err +} + func (f *Filer) assignAndUpload(ctx context.Context, targetFile string, data []byte) (*operation.AssignResult, *operation.UploadResult, error) { // Consecutive events repeat whole chunk lists, but the uploader only // samples the first bytes before deciding to compress. @@ -103,18 +161,7 @@ func (f *Filer) assignAndUpload(ctx context.Context, targetFile string, data []b data, isCompressed = compressed, true } - // assign a volume location - diskType, rule := f.resolveMetadataLogAssignDiskType(targetFile) - assignRequest := &operation.VolumeAssignRequest{ - Count: 1, - Collection: f.metaLogCollectionFor(rule.Collection), - Replication: f.metaLogReplicationFor(rule.Replication), - DiskType: diskType, - WritableVolumeCount: rule.VolumeGrowthCount, - ExpectedDataSize: uint64(len(data)), - } - - assignResult, err := operation.Assign(ctx, f.GetMaster, f.masterGrpcDialOption(), assignRequest) + assignResult, err := f.assignMetaLogPiece(ctx, f.metaLogAssignRequests(targetFile, len(data))) if err != nil { return nil, nil, fmt.Errorf("AssignVolume: %w", err) } diff --git a/weed/filer/filer_notify_append_compress_test.go b/weed/filer/filer_notify_append_compress_test.go index 0fd4bfb1a4..159dd12697 100644 --- a/weed/filer/filer_notify_append_compress_test.go +++ b/weed/filer/filer_notify_append_compress_test.go @@ -11,12 +11,16 @@ import ( "net/http" "net/http/httptest" "strings" + "sync/atomic" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" "github.com/seaweedfs/seaweedfs/weed/operation" @@ -133,3 +137,139 @@ func TestMetaLogPieceUploadsIncompressibleAsIs(t *testing.T) { assert.Zero(t, uploadResult.Gzip) assert.Equal(t, uint32(len(data)), uploadResult.Size) } + +type fullCollectionMaster struct { + assignMaster + full string + fullErr error + attempts atomic.Int32 +} + +func (m *fullCollectionMaster) Assign(ctx context.Context, req *master_pb.AssignRequest) (*master_pb.AssignResponse, error) { + if req.Collection == m.full { + if m.attempts.Add(1) == 1 { + m.requests <- req + } + if m.fullErr != nil { + return nil, m.fullErr + } + return nil, fmt.Errorf("no free volumes left for collection %s", m.full) + } + return m.assignMaster.Assign(ctx, req) +} + +func TestMetaLogPieceFallsBackWhenMetaCollectionIsFull(t *testing.T) { + volume := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusCreated) + _ = json.NewEncoder(w).Encode(operation.UploadResult{Size: 1}) + })) + t.Cleanup(volume.Close) + + master := &fullCollectionMaster{ + assignMaster: assignMaster{ + collectionDeleteMaster: collectionDeleteMaster{calls: make(chan collectionDeleteCall, 1)}, + volumeUrl: strings.TrimPrefix(volume.URL, "http://"), + requests: make(chan *master_pb.AssignRequest, 2), + }, + full: "filer-meta", + } + f, _ := newFilerWithMaster(t, master) + f.GrpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials()) + f.metaLogTargetCollection = "filer-meta" + f.metaLogTargetReplication = "001" + f.metaLogVolumeGrowthCount = 2 + f.metaLogCollection = "mydata" + + _, _, err := f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x")) + require.NoError(t, err) + + own, shared := <-master.requests, <-master.requests + assert.Equal(t, "filer-meta", own.GetCollection()) + assert.Equal(t, "001", own.GetReplication()) + assert.Equal(t, uint32(2), own.GetWritableVolumeCount()) + assert.Equal(t, "mydata", shared.GetCollection()) + assert.Empty(t, shared.GetReplication()) + assert.Zero(t, shared.GetWritableVolumeCount(), "the shared collection keeps its own growth count") +} + +func TestMetaLogPieceFallsBackWhileMetaCollectionKeepsGrowing(t *testing.T) { + budget := metaLogOwnAssignBudget + metaLogOwnAssignBudget = time.Second + t.Cleanup(func() { metaLogOwnAssignBudget = budget }) + + volume := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusCreated) + _ = json.NewEncoder(w).Encode(operation.UploadResult{Size: 1}) + })) + t.Cleanup(volume.Close) + + master := &fullCollectionMaster{ + assignMaster: assignMaster{ + collectionDeleteMaster: collectionDeleteMaster{calls: make(chan collectionDeleteCall, 1)}, + volumeUrl: strings.TrimPrefix(volume.URL, "http://"), + requests: make(chan *master_pb.AssignRequest, 3), + }, + full: "meta", + fullErr: status.Error(codes.ResourceExhausted, "no writable volumes for meta, volume growth in progress"), + } + f, _ := newFilerWithMaster(t, master) + f.GrpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials()) + f.metaLogTargetCollection = "meta" + f.metaLogCollection = "mydata" + + start := time.Now() + _, _, err := f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x")) + require.NoError(t, err) + assert.Less(t, time.Since(start), 5*time.Second, "the fallback must not wait for the whole assign budget") + assert.Equal(t, "meta", (<-master.requests).GetCollection()) + assert.Equal(t, "mydata", (<-master.requests).GetCollection()) + + attempts := master.attempts.Load() + _, _, err = f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x")) + require.NoError(t, err) + assert.Equal(t, "mydata", (<-master.requests).GetCollection()) + assert.Equal(t, attempts, master.attempts.Load(), "the next piece skips the collection that just failed") +} + +func TestMetaLogPieceRetriesMetaCollectionWhenFallbackFails(t *testing.T) { + volume := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusCreated) + _ = json.NewEncoder(w).Encode(operation.UploadResult{Size: 1}) + })) + t.Cleanup(volume.Close) + + master := &fullCollectionMaster{ + assignMaster: assignMaster{ + collectionDeleteMaster: collectionDeleteMaster{calls: make(chan collectionDeleteCall, 1)}, + volumeUrl: strings.TrimPrefix(volume.URL, "http://"), + requests: make(chan *master_pb.AssignRequest, 2), + }, + full: "mydata", + } + f, _ := newFilerWithMaster(t, master) + f.GrpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials()) + f.metaLogTargetCollection = "meta" + f.metaLogCollection = "mydata" + f.metaLogOwnAssignPausedUntil.Store(time.Now().Add(time.Hour).UnixNano()) + + _, _, err := f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x")) + require.Error(t, err) + assert.Equal(t, "mydata", (<-master.requests).GetCollection()) + + _, _, err = f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x")) + require.NoError(t, err, "a failed fallback ends the pause on the meta collection") + assert.Equal(t, "meta", (<-master.requests).GetCollection()) +} + +func TestMetaLogAssignWithoutOwnCollection(t *testing.T) { + f := &Filer{metaLogCollection: "mydata", metaLogVolumeGrowthCount: 2} + requests := f.metaLogAssignRequests(string(appendTestLog), 1) + require.Len(t, requests, 1) + assert.Equal(t, "mydata", requests[0].Collection) + assert.Zero(t, requests[0].WritableVolumeCount, "the growth count is only for the meta log collection") + + f.metaLogTargetCollection = "mydata" + requests = f.metaLogAssignRequests(string(appendTestLog), 1) + require.Len(t, requests, 1) + assert.Equal(t, uint32(2), requests[0].WritableVolumeCount) +} diff --git a/weed/filer/meta_log_collection_test.go b/weed/filer/meta_log_collection_test.go index b631a13ece..16eb71af56 100644 --- a/weed/filer/meta_log_collection_test.go +++ b/weed/filer/meta_log_collection_test.go @@ -7,6 +7,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" + "github.com/seaweedfs/seaweedfs/weed/s3api/s3bucket" "github.com/seaweedfs/seaweedfs/weed/util" ) @@ -94,12 +95,12 @@ func TestMetaLogReplicationResolution(t *testing.T) { // are read into the fields a running filer uses. func TestViperReadsMetaLogOverrides(t *testing.T) { v := util.GetViper() - v.Set("filer.options.metaLog.collection", "filer-meta") + v.Set("filer.options.metaLog.collection", "meta-elsewhere") v.Set("filer.options.metaLog.replication", "100") defer func() { - // Reset so other tests see the unset default. - v.Set("filer.options.metaLog.collection", "") - v.Set("filer.options.metaLog.replication", "") + // nil drops the override, so later reads see the defaults again. + v.Set("filer.options.metaLog.collection", nil) + v.Set("filer.options.metaLog.replication", nil) }() f := NewFiler(pb.ServerDiscovery{}, nil, "", "", "", "", "", 255, nil) @@ -109,7 +110,7 @@ func TestViperReadsMetaLogOverrides(t *testing.T) { f.LocalMetaLogBuffer.ShutdownLogBuffer() f.LocalMetaLogBuffer.WaitForShutdown() }() - if got := f.metaLogTargetCollection; got != "filer-meta" { + if got := f.metaLogTargetCollection; got != "meta-elsewhere" { t.Fatalf("NewFiler did not read the collection override: %q", got) } if got := f.metaLogTargetReplication; got != "100" { @@ -142,3 +143,24 @@ func TestBucketCollectionKeepsMetaLogTargetCollection(t *testing.T) { default: } } + +func TestMetaLogDefaultsToOwnCollection(t *testing.T) { + f := NewFiler(pb.ServerDiscovery{}, nil, "", "", "", "", "", 255, nil) + defer func() { + close(f.deletionQuit) + f.flushCancel() + f.LocalMetaLogBuffer.ShutdownLogBuffer() + f.LocalMetaLogBuffer.WaitForShutdown() + }() + if f.metaLogTargetCollection != "_meta" || f.metaLogVolumeGrowthCount != 2 { + t.Fatalf("defaults: collection %q growth %d", f.metaLogTargetCollection, f.metaLogVolumeGrowthCount) + } + if s3bucket.VerifyS3BucketName(defaultMetaLogCollection) == nil { + t.Fatalf("a bucket can be named %q, so deleting it would drop the metadata log", defaultMetaLogCollection) + } + for i, c := range defaultMetaLogCollection { + if c == '_' && i > 0 && s3bucket.VerifyS3BucketName(defaultMetaLogCollection[i+1:]) == nil { + t.Fatalf("filer group %q with bucket %q maps to %q", defaultMetaLogCollection[:i], defaultMetaLogCollection[i+1:], defaultMetaLogCollection) + } + } +}