Skip to content

Commit

Permalink
filer: mysql2, postgres2 trigger actions on bucket creation and deletion
Browse files Browse the repository at this point in the history
fix #1877
  • Loading branch information
chrislusf committed Mar 14, 2021
1 parent cb42331 commit 6d3a96e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
19 changes: 19 additions & 0 deletions weed/filer/abstract_sql/abstract_sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
18 changes: 18 additions & 0 deletions weed/filer/filer_on_meta_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ import (
// onMetadataChangeEvent is triggered after filer processed change events from local or remote filers
func (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) {
Expand Down
6 changes: 6 additions & 0 deletions weed/filer/filerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ type FilerStore interface {

Shutdown()
}

type BucketAware interface {
OnBucketCreation(bucket string)
OnBucketDeletion(bucket string)
}

23 changes: 23 additions & 0 deletions weed/filer/filerstore_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type VirtualFilerStore interface {
DeleteHardLink(ctx context.Context, hardLinkId HardLinkId) error
DeleteOneEntry(ctx context.Context, entry *Entry) error
AddPathSpecificStore(path string, storeId string, store FilerStore)
OnBucketCreation(bucket string)
OnBucketDeletion(bucket string)
}

type FilerStoreWrapper struct {
Expand All @@ -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)
Expand Down

2 comments on commit 6d3a96e

@LazyDBA247-Anyvision
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrislusf that requires multiple filers to have "-peers" configured?

@chrislusf
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

Please sign in to comment.