SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
filer: add a placement overlay seam for the write path (#10437)
Chris Lu0f718f8509c5
diff --git a/weed/filer/filer.go b/weed/filer/filer.goindex 4595c55f4e..bd349af670 100644--- a/weed/filer/filer.go+++ b/weed/filer/filer.go@@ -56,6 +56,7 @@ type Filer struct {MetaAggregator *MetaAggregatorSignature int32FilerConf *FilerConf+ placementOverlay PlacementOverlayRemoteStorage *FilerRemoteStoragelazyFetchGroup singleflight.GrouplazyListGroup singleflight.Group@@ -96,6 +97,10 @@ func NewFiler(masters pb.ServerDiscovery, grpcDialOption grpc.DialOption, filerHf.metaLogCollection = collectionf.metaLogReplication = replication+ if newPlacementOverlay != nil {+ f.placementOverlay = newPlacementOverlay(f)+ }+go f.loopProcessingDeletion()return fdiff --git a/weed/filer/placement_overlay.go b/weed/filer/placement_overlay.gonew file mode 100644index 0000000000..9c9f80873c--- /dev/null+++ b/weed/filer/placement_overlay.go@@ -0,0 +1,36 @@+package filer++// PlacementOverlay resolves a write-time placement override for a collection —+// the disk type, replication, and data center new volumes of that collection+// should land on — or ok=false when the collection has none.+//+// It exists so a feature can steer where a bound collection's data lands without+// every operator setting an fs.configure rule by hand. The type is deliberately+// generic: it names no placement-policy concepts, so a downstream build+// registers whatever overlay it wants without coupling this seam to it.+type PlacementOverlay func(collection string) (diskType, replication, dataCenter string, ok bool)++// newPlacementOverlay builds the overlay for a filer. Enterprise sets it in an+// init() pulled in by a side-effect import, the way plugin-worker handlers+// register — the setter cannot live here because this package is overwritten by+// the sync.+var newPlacementOverlay func(*Filer) PlacementOverlay++// RegisterPlacementOverlay installs the factory. It is meant to be called from a+// package init() — before any Filer is constructed and before serving starts —+// so the unsynchronized read in NewFiler never races the write. The last+// registration wins; there is only ever one overlay.+func RegisterPlacementOverlay(factory func(*Filer) PlacementOverlay) {+ newPlacementOverlay = factory+}++// ResolvePlacement returns the overlay's placement for a collection, or+// ok=false when there is no overlay or the collection is not steered. The write+// path applies these between the explicit request value and the filer.conf+// rule, so an overlay overrides the rule but yields to an explicit request.+func (f *Filer) ResolvePlacement(collection string) (diskType, replication, dataCenter string, ok bool) {+ if f == nil || f.placementOverlay == nil || collection == "" {+ return "", "", "", false+ }+ return f.placementOverlay(collection)+}diff --git a/weed/server/filer_server_handlers_write.go b/weed/server/filer_server_handlers_write.goindex f44f530045..1344c67f5c 100644--- a/weed/server/filer_server_handlers_write.go+++ b/weed/server/filer_server_handlers_write.go@@ -295,14 +295,29 @@ func (fs *FilerServer) detectStorageOption(ctx context.Context, requestURI, qColttlSeconds = int32(ttl.Minutes()) * 60}+ collection := util.Nvl(qCollection, rule.Collection, bucketDefaultCollection, fs.option.Collection)++ // A placement overlay steers a bound collection's new volumes onto a tier.+ // It sits between the explicit request and the filer.conf rule: it overrides+ // the rule but yields to a value the caller asked for outright. Only a+ // steered collection contributes values; an unsteered one clears them so it+ // falls straight through to the rule.+ overlayDisk, overlayReplication, overlayDataCenter, overlaySteered := fs.filer.ResolvePlacement(collection)+ if !overlaySteered {+ overlayDisk, overlayReplication, overlayDataCenter = "", "", ""+ } else {+ glog.V(4).InfofCtx(ctx, "placement overlay steers collection %s: disk=%q replication=%q dataCenter=%q",+ collection, overlayDisk, overlayReplication, overlayDataCenter)+ }+return &operation.StorageOption{- Replication: util.Nvl(qReplication, rule.Replication, fs.option.DefaultReplication),- Collection: util.Nvl(qCollection, rule.Collection, bucketDefaultCollection, fs.option.Collection),- DataCenter: util.Nvl(dataCenter, rule.DataCenter, fs.option.DataCenter),+ Replication: util.Nvl(qReplication, overlayReplication, rule.Replication, fs.option.DefaultReplication),+ Collection: collection,+ DataCenter: util.Nvl(dataCenter, overlayDataCenter, rule.DataCenter, fs.option.DataCenter),Rack: util.Nvl(rack, rule.Rack, fs.option.Rack),DataNode: util.Nvl(dataNode, rule.DataNode, fs.option.DataNode),TtlSeconds: ttlSeconds,- DiskType: util.Nvl(diskType, rule.DiskType),+ DiskType: util.Nvl(diskType, overlayDisk, rule.DiskType),Fsync: rule.Fsync,VolumeGrowthCount: rule.VolumeGrowthCount,MaxFileNameLength: maxFileNameLength,