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: mysql2, postgres2 trigger actions on bucket creation and deletion
Chris Lu6d3a96eb562f
diff --git a/weed/filer/abstract_sql/abstract_sql_store.go b/weed/filer/abstract_sql/abstract_sql_store.goindex 07ce561457..6f37a118b7 100644--- a/weed/filer/abstract_sql/abstract_sql_store.go+++ b/weed/filer/abstract_sql/abstract_sql_store.go@@ -32,6 +32,25 @@ type AbstractSqlStore struct {dbsLock sync.Mutex}+func (store *AbstractSqlStore) OnBucketCreation(bucket string) {+ store.dbsLock.Lock()+ defer store.dbsLock.Unlock()++ if store.dbs == nil {+ return+ }+ store.dbs[bucket] = true+}+func (store *AbstractSqlStore) OnBucketDeletion(bucket string) {+ store.dbsLock.Lock()+ defer store.dbsLock.Unlock()++ if store.dbs == nil {+ return+ }+ delete(store.dbs, bucket)+}+const (DEFAULT_TABLE = "filemeta")diff --git a/weed/filer/filer_on_meta_event.go b/weed/filer/filer_on_meta_event.goindex b29324b61f..c9f75a5caf 100644--- a/weed/filer/filer_on_meta_event.go+++ b/weed/filer/filer_on_meta_event.go@@ -12,6 +12,24 @@ import (// onMetadataChangeEvent is triggered after filer processed change events from local or remote filersfunc (f *Filer) onMetadataChangeEvent(event *filer_pb.SubscribeMetadataResponse) {f.maybeReloadFilerConfiguration(event)+ f.onBucketEvents(event)+}++func (f *Filer) onBucketEvents(event *filer_pb.SubscribeMetadataResponse) {+ message := event.EventNotification+ for _, sig := range message.Signatures {+ if sig == f.Signature {+ return+ }+ }+ if f.DirBucketsPath == event.Directory {+ if message.OldEntry == nil && message.NewEntry != nil {+ f.Store.OnBucketCreation(message.NewEntry.Name)+ }+ if message.OldEntry != nil && message.NewEntry == nil {+ f.Store.OnBucketDeletion(message.OldEntry.Name)+ }+ }}func (f *Filer) maybeReloadFilerConfiguration(event *filer_pb.SubscribeMetadataResponse) {diff --git a/weed/filer/filerstore.go b/weed/filer/filerstore.goindex 8955a25c78..069920f2db 100644--- a/weed/filer/filerstore.go+++ b/weed/filer/filerstore.go@@ -39,3 +39,9 @@ type FilerStore interface {Shutdown()}++type BucketAware interface {+ OnBucketCreation(bucket string)+ OnBucketDeletion(bucket string)+}+diff --git a/weed/filer/filerstore_wrapper.go b/weed/filer/filerstore_wrapper.goindex 64baac3714..95848e61b7 100644--- a/weed/filer/filerstore_wrapper.go+++ b/weed/filer/filerstore_wrapper.go@@ -21,6 +21,8 @@ type VirtualFilerStore interface {DeleteHardLink(ctx context.Context, hardLinkId HardLinkId) errorDeleteOneEntry(ctx context.Context, entry *Entry) errorAddPathSpecificStore(path string, storeId string, store FilerStore)+ OnBucketCreation(bucket string)+ OnBucketDeletion(bucket string)}type FilerStoreWrapper struct {@@ -40,6 +42,27 @@ func NewFilerStoreWrapper(store FilerStore) *FilerStoreWrapper {}}+func (fsw *FilerStoreWrapper) OnBucketCreation(bucket string) {+ for _, store := range fsw.storeIdToStore {+ if ba, ok := store.(BucketAware); ok {+ ba.OnBucketCreation(bucket)+ }+ }+ if ba, ok := fsw.defaultStore.(BucketAware); ok {+ ba.OnBucketCreation(bucket)+ }+}+func (fsw *FilerStoreWrapper) OnBucketDeletion(bucket string) {+ for _, store := range fsw.storeIdToStore {+ if ba, ok := store.(BucketAware); ok {+ ba.OnBucketDeletion(bucket)+ }+ }+ if ba, ok := fsw.defaultStore.(BucketAware); ok {+ ba.OnBucketDeletion(bucket)+ }+}+func (fsw *FilerStoreWrapper) AddPathSpecificStore(path string, storeId string, store FilerStore) {fsw.storeIdToStore[storeId] = NewFilerStorePathTranlator(path, store)err := fsw.pathToStore.Put([]byte(path), storeId)