dedup local metadata subscribers

fix https://github.com/chrislusf/seaweedfs/discussions/2542
This commit is contained in:
chrislu 2022-01-23 16:14:22 -08:00
parent bb6854b972
commit 4a311c7f5e
2 changed files with 7 additions and 5 deletions

View file

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

View file

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