2020-11-14 22:26:08 +00:00
|
|
|
package filer
|
|
|
|
|
|
|
|
import (
|
2020-11-15 05:21:20 +00:00
|
|
|
"bytes"
|
|
|
|
"math"
|
|
|
|
|
2020-11-14 22:26:08 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2020-11-15 22:06:03 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2020-11-14 22:26:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// onMetadataChangeEvent is triggered after filer processed change events from local or remote filers
|
|
|
|
func (f *Filer) onMetadataChangeEvent(event *filer_pb.SubscribeMetadataResponse) {
|
2020-12-10 19:11:02 +00:00
|
|
|
if DirectoryEtcSeaweedFS != event.Directory {
|
|
|
|
if DirectoryEtcSeaweedFS != event.EventNotification.NewParentPath {
|
2020-11-15 05:21:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entry := event.EventNotification.NewEntry
|
|
|
|
if entry == nil {
|
2020-11-14 22:26:08 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
glog.V(0).Infof("procesing %v", event)
|
2020-11-15 22:06:03 +00:00
|
|
|
if entry.Name == FilerConfName {
|
2020-11-15 05:21:20 +00:00
|
|
|
f.reloadFilerConfiguration(entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-15 22:06:03 +00:00
|
|
|
func (f *Filer) readEntry(chunks []*filer_pb.FileChunk) ([]byte, error) {
|
2020-11-15 05:21:20 +00:00
|
|
|
var buf bytes.Buffer
|
2020-11-15 22:06:03 +00:00
|
|
|
err := StreamContent(f.MasterClient, &buf, chunks, 0, math.MaxInt64)
|
2020-11-15 05:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Filer) reloadFilerConfiguration(entry *filer_pb.Entry) {
|
2020-11-15 22:06:03 +00:00
|
|
|
fc := NewFilerConf()
|
2021-02-19 01:07:02 +00:00
|
|
|
err := fc.loadFromChunks(f, entry.Content, entry.Chunks)
|
2020-11-15 05:21:20 +00:00
|
|
|
if err != nil {
|
2020-11-15 22:06:03 +00:00
|
|
|
glog.Errorf("read filer conf chunks: %v", err)
|
2020-11-15 05:21:20 +00:00
|
|
|
return
|
|
|
|
}
|
2020-11-15 22:06:03 +00:00
|
|
|
f.FilerConf = fc
|
|
|
|
}
|
2020-11-14 22:26:08 +00:00
|
|
|
|
2020-11-15 22:06:03 +00: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-14 22:26:08 +00:00
|
|
|
}
|