2020-11-15 06:26:08 +08:00
|
|
|
package filer
|
|
|
|
|
|
|
|
import (
|
2020-11-15 13:21:20 +08:00
|
|
|
"bytes"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2020-11-15 06:26:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// onMetadataChangeEvent is triggered after filer processed change events from local or remote filers
|
|
|
|
func (f *Filer) onMetadataChangeEvent(event *filer_pb.SubscribeMetadataResponse) {
|
2021-03-10 05:21:26 +08:00
|
|
|
f.maybeReloadFilerConfiguration(event)
|
2021-07-29 13:43:12 +08:00
|
|
|
f.maybeReloadRemoteStorageConfigurationAndMapping(event)
|
2021-03-14 14:07:39 +08:00
|
|
|
f.onBucketEvents(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Filer) onBucketEvents(event *filer_pb.SubscribeMetadataResponse) {
|
|
|
|
message := event.EventNotification
|
2022-07-28 12:04:37 +08:00
|
|
|
|
2021-03-14 14:07:39 +08:00
|
|
|
if f.DirBucketsPath == event.Directory {
|
2022-02-25 17:17:26 +08:00
|
|
|
if filer_pb.IsCreate(event) {
|
2021-08-02 03:28:08 +08:00
|
|
|
if message.NewEntry.IsDirectory {
|
|
|
|
f.Store.OnBucketCreation(message.NewEntry.Name)
|
|
|
|
}
|
2021-03-14 14:07:39 +08:00
|
|
|
}
|
2022-02-25 17:17:26 +08:00
|
|
|
if filer_pb.IsDelete(event) {
|
2021-08-02 03:28:08 +08:00
|
|
|
if message.OldEntry.IsDirectory {
|
|
|
|
f.Store.OnBucketDeletion(message.OldEntry.Name)
|
|
|
|
}
|
2021-03-14 14:07:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-10 05:21:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Filer) maybeReloadFilerConfiguration(event *filer_pb.SubscribeMetadataResponse) {
|
2020-12-11 03:11:02 +08:00
|
|
|
if DirectoryEtcSeaweedFS != event.Directory {
|
|
|
|
if DirectoryEtcSeaweedFS != event.EventNotification.NewParentPath {
|
2020-11-15 13:21:20 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entry := event.EventNotification.NewEntry
|
|
|
|
if entry == nil {
|
2020-11-15 06:26:08 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
glog.V(0).Infof("procesing %v", event)
|
2020-11-16 06:06:03 +08:00
|
|
|
if entry.Name == FilerConfName {
|
2020-11-15 13:21:20 +08:00
|
|
|
f.reloadFilerConfiguration(entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 15:08:54 +08:00
|
|
|
func (f *Filer) readEntry(chunks []*filer_pb.FileChunk, size uint64) ([]byte, error) {
|
2020-11-15 13:21:20 +08:00
|
|
|
var buf bytes.Buffer
|
2022-02-08 15:08:54 +08:00
|
|
|
err := StreamContent(f.MasterClient, &buf, chunks, 0, int64(size))
|
2020-11-15 13:21:20 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Filer) reloadFilerConfiguration(entry *filer_pb.Entry) {
|
2020-11-16 06:06:03 +08:00
|
|
|
fc := NewFilerConf()
|
2022-11-15 22:33:36 +08:00
|
|
|
err := fc.loadFromChunks(f, entry.Content, entry.GetChunks(), FileSize(entry))
|
2020-11-15 13:21:20 +08:00
|
|
|
if err != nil {
|
2020-11-16 06:06:03 +08:00
|
|
|
glog.Errorf("read filer conf chunks: %v", err)
|
2020-11-15 13:21:20 +08:00
|
|
|
return
|
|
|
|
}
|
2020-11-16 06:06:03 +08:00
|
|
|
f.FilerConf = fc
|
|
|
|
}
|
2020-11-15 06:26:08 +08:00
|
|
|
|
2020-11-16 06:06:03 +08:00
|
|
|
func (f *Filer) LoadFilerConf() {
|
|
|
|
fc := NewFilerConf()
|
|
|
|
err := util.Retry("loadFilerConf", func() error {
|
|
|
|
return fc.loadFromFiler(f)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("read filer conf: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f.FilerConf = fc
|
2020-11-15 06:26:08 +08:00
|
|
|
}
|
2021-07-29 13:43:12 +08:00
|
|
|
|
2022-09-15 14:06:44 +08:00
|
|
|
// //////////////////////////////////
|
2021-07-29 13:43:12 +08:00
|
|
|
// load and maintain remote storages
|
2022-09-15 14:06:44 +08:00
|
|
|
// //////////////////////////////////
|
2021-07-29 13:43:12 +08:00
|
|
|
func (f *Filer) LoadRemoteStorageConfAndMapping() {
|
|
|
|
if err := f.RemoteStorage.LoadRemoteStorageConfigurationsAndMapping(f); err != nil {
|
|
|
|
glog.Errorf("read remote conf and mapping: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (f *Filer) maybeReloadRemoteStorageConfigurationAndMapping(event *filer_pb.SubscribeMetadataResponse) {
|
|
|
|
// FIXME add reloading
|
|
|
|
}
|