|
@ -1,9 +1,12 @@ |
|
|
package weed_server |
|
|
package weed_server |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"fmt" |
|
|
"strings" |
|
|
"strings" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto" |
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2" |
|
|
"github.com/chrislusf/seaweedfs/weed/filer2" |
|
|
"github.com/chrislusf/seaweedfs/weed/glog" |
|
|
"github.com/chrislusf/seaweedfs/weed/glog" |
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" |
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" |
|
@ -23,10 +26,7 @@ func (fs *FilerServer) SubscribeMetadata(req *filer_pb.SubscribeMetadataRequest, |
|
|
lastReadTime = time.Unix(0, req.SinceNs) |
|
|
lastReadTime = time.Unix(0, req.SinceNs) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var readErr error |
|
|
|
|
|
for { |
|
|
|
|
|
|
|
|
|
|
|
lastReadTime, readErr = fs.filer.ReadLogBuffer(lastReadTime, func(dirPath string, eventNotification *filer_pb.EventNotification) error { |
|
|
|
|
|
|
|
|
eachEventNotificationFn := func(dirPath string, eventNotification *filer_pb.EventNotification) error { |
|
|
|
|
|
|
|
|
// get complete path to the file or directory
|
|
|
// get complete path to the file or directory
|
|
|
var entryName string |
|
|
var entryName string |
|
@ -52,20 +52,33 @@ func (fs *FilerServer) SubscribeMetadata(req *filer_pb.SubscribeMetadataRequest, |
|
|
EventNotification: eventNotification, |
|
|
EventNotification: eventNotification, |
|
|
} |
|
|
} |
|
|
if err := stream.Send(message); err != nil { |
|
|
if err := stream.Send(message); err != nil { |
|
|
|
|
|
glog.V(0).Infof("=> client %v: %+v", clientName, err) |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
}) |
|
|
|
|
|
if readErr != nil { |
|
|
|
|
|
glog.V(0).Infof("=> client %v: %+v", clientName, readErr) |
|
|
|
|
|
return readErr |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_, err := fs.filer.MetaLogBuffer.LoopProcessLogData(lastReadTime, func() bool { |
|
|
fs.listenersLock.Lock() |
|
|
fs.listenersLock.Lock() |
|
|
fs.listenersCond.Wait() |
|
|
fs.listenersCond.Wait() |
|
|
fs.listenersLock.Unlock() |
|
|
fs.listenersLock.Unlock() |
|
|
|
|
|
return true |
|
|
|
|
|
}, func(logEntry *filer_pb.LogEntry) error { |
|
|
|
|
|
event := &filer_pb.SubscribeMetadataResponse{} |
|
|
|
|
|
if err := proto.Unmarshal(logEntry.Data, event); err != nil { |
|
|
|
|
|
glog.Errorf("unexpected unmarshal filer_pb.SubscribeMetadataResponse: %v", err) |
|
|
|
|
|
return fmt.Errorf("unexpected unmarshal filer_pb.SubscribeMetadataResponse: %v", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := eachEventNotificationFn(event.Directory, event.EventNotification); err != nil { |
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (fs *FilerServer) addClient(clientType string, clientAddress string) (clientName string) { |
|
|
func (fs *FilerServer) addClient(clientType string, clientAddress string) (clientName string) { |
|
|