Browse Source

dedup local metadata subscribers

fix https://github.com/chrislusf/seaweedfs/discussions/2542
pull/2613/head
chrislu 3 years ago
parent
commit
4a311c7f5e
  1. 3
      weed/filer/meta_aggregator.go
  2. 9
      weed/server/filer_grpc_server_sub_meta.go

3
weed/filer/meta_aggregator.go

@ -165,13 +165,14 @@ func (ma *MetaAggregator) subscribeToOneFiler(f *Filer, self pb.ServerAddress, p
for {
glog.V(4).Infof("subscribing remote %s meta change: %v", peer, time.Unix(0, lastTsNs))
err := pb.WithFilerClient(false, peer, ma.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
err := pb.WithFilerClient(true, peer, ma.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
stream, err := client.SubscribeLocalMetadata(ctx, &filer_pb.SubscribeMetadataRequest{
ClientName: "filer:" + string(self),
PathPrefix: "/",
SinceNs: lastTsNs,
ClientId: int32(ma.filer.UniqueFileId),
})
if err != nil {
return fmt.Errorf("subscribe: %v", err)

9
weed/server/filer_grpc_server_sub_meta.go

@ -27,7 +27,6 @@ func (fs *FilerServer) SubscribeMetadata(req *filer_pb.SubscribeMetadataRequest,
if alreadyKnown {
return fmt.Errorf("duplicated subscription detected for client %s id %d", clientName, req.ClientId)
}
defer fs.deleteClient(clientName, req.ClientId)
lastReadTime := time.Unix(0, req.SinceNs)
@ -84,9 +83,11 @@ func (fs *FilerServer) SubscribeLocalMetadata(req *filer_pb.SubscribeMetadataReq
peerAddress := findClientAddress(stream.Context(), 0)
_, clientName := fs.addClient(req.ClientName, peerAddress, 0)
defer fs.deleteClient(clientName, 0)
alreadyKnown, clientName := fs.addClient(req.ClientName, peerAddress, req.ClientId)
if alreadyKnown {
return fmt.Errorf("duplicated local subscription detected for client %s id %d", clientName, req.ClientId)
}
defer fs.deleteClient(clientName, req.ClientId)
lastReadTime := time.Unix(0, req.SinceNs)
glog.V(0).Infof(" %v local subscribe %s from %+v", clientName, req.PathPrefix, lastReadTime)

Loading…
Cancel
Save