seaweedfs/weed/mount/meta_cache/meta_cache_subscribe.go

125 lines
3.6 KiB
Go
Raw Normal View History

2022-02-14 17:09:31 +08:00
package meta_cache
import (
"context"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
"strings"
2022-02-14 17:09:31 +08:00
)
2024-10-07 03:55:19 +08:00
type MetadataFollower struct {
PathPrefixToWatch string
ProcessEventFn func(resp *filer_pb.SubscribeMetadataResponse) error
}
avoid nil I1010 03:10:25.220345 mount_std.go:281 This is SeaweedFS version 30GB 3.76 82ed61c6552e5095c682131012c91594ad2643e6 linux amd64 ^[OR^[OR2024/10/10 03:12:56 Unimplemented opcode POLL panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x3983b41] goroutine 112 [running]: github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents.func2.mergeProceesors.1(0xc000513540) /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:30 +0x41 github.com/seaweedfs/seaweedfs/weed/pb.WithFilerClientFollowMetadata.makeSubscribeMetadataFunc.func1({0x514a560, 0xc0009b06d0}) /github/workspace/weed/pb/filer_pb_tail.go:87 +0x293 github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient.func1.1(0xc000d9e008) /github/workspace/weed/mount/wfs_filer_client.go:27 +0x68 github.com/seaweedfs/seaweedfs/weed/pb.WithGrpcClient(0xa9?, 0x9d1f90fb?, 0xc00098fbe0, {0xc000e1c078, 0x15}, 0x0?, {0xc000a76bd0?, 0x1?, 0x1? }) /github/workspace/weed/pb/grpc_client_server.go:155 +0x33a github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient.func1() /github/workspace/weed/mount/wfs_filer_client.go:25 +0x14c github.com/seaweedfs/seaweedfs/weed/util.Retry({0x489a10c, 0xa}, 0xc00098fcf8) /github/workspace/weed/util/retry.go:16 +0xa7 github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient(0x0?, 0x30?, 0xc00056a568?) /github/workspace/weed/mount/wfs_filer_client.go:18 +0x65 github.com/seaweedfs/seaweedfs/weed/pb.WithFilerClientFollowMetadata({0x50f5898, 0xc000e2c180}, 0xc00101e000, 0xc000d22030) /github/workspace/weed/pb/filer_pb_tail.go:51 +0x87 github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents.func2() /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:115 +0xcb github.com/seaweedfs/seaweedfs/weed/util.RetryUntil({0x48b8b35, 0x11}, 0xc00098fef0, 0x4af0048) /github/workspace/weed/util/retry.go:64 +0x4e github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents(0xc000d1d980, 0x9d1f90fb, {0x50f5898, 0xc000e2c180}, {0x7ffdf6f98dca, 0x4}, 0x17fcf8b7c7ecf8cf, {0xc0000ac208, 0x1, 0x1}) /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:113 +0x39b created by github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).StartBackgroundTasks in goroutine 1 /github/workspace/weed/mount/weedfs.go:150 +0x146
2024-10-10 13:45:58 +08:00
func mergeProcessors(mainProcessor func(resp *filer_pb.SubscribeMetadataResponse) error, followers ...*MetadataFollower) func(resp *filer_pb.SubscribeMetadataResponse) error {
2024-10-07 03:55:19 +08:00
return func(resp *filer_pb.SubscribeMetadataResponse) error {
// build the full path
entry := resp.EventNotification.NewEntry
if entry == nil {
entry = resp.EventNotification.OldEntry
}
avoid nil I1010 03:10:25.220345 mount_std.go:281 This is SeaweedFS version 30GB 3.76 82ed61c6552e5095c682131012c91594ad2643e6 linux amd64 ^[OR^[OR2024/10/10 03:12:56 Unimplemented opcode POLL panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x3983b41] goroutine 112 [running]: github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents.func2.mergeProceesors.1(0xc000513540) /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:30 +0x41 github.com/seaweedfs/seaweedfs/weed/pb.WithFilerClientFollowMetadata.makeSubscribeMetadataFunc.func1({0x514a560, 0xc0009b06d0}) /github/workspace/weed/pb/filer_pb_tail.go:87 +0x293 github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient.func1.1(0xc000d9e008) /github/workspace/weed/mount/wfs_filer_client.go:27 +0x68 github.com/seaweedfs/seaweedfs/weed/pb.WithGrpcClient(0xa9?, 0x9d1f90fb?, 0xc00098fbe0, {0xc000e1c078, 0x15}, 0x0?, {0xc000a76bd0?, 0x1?, 0x1? }) /github/workspace/weed/pb/grpc_client_server.go:155 +0x33a github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient.func1() /github/workspace/weed/mount/wfs_filer_client.go:25 +0x14c github.com/seaweedfs/seaweedfs/weed/util.Retry({0x489a10c, 0xa}, 0xc00098fcf8) /github/workspace/weed/util/retry.go:16 +0xa7 github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient(0x0?, 0x30?, 0xc00056a568?) /github/workspace/weed/mount/wfs_filer_client.go:18 +0x65 github.com/seaweedfs/seaweedfs/weed/pb.WithFilerClientFollowMetadata({0x50f5898, 0xc000e2c180}, 0xc00101e000, 0xc000d22030) /github/workspace/weed/pb/filer_pb_tail.go:51 +0x87 github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents.func2() /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:115 +0xcb github.com/seaweedfs/seaweedfs/weed/util.RetryUntil({0x48b8b35, 0x11}, 0xc00098fef0, 0x4af0048) /github/workspace/weed/util/retry.go:64 +0x4e github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents(0xc000d1d980, 0x9d1f90fb, {0x50f5898, 0xc000e2c180}, {0x7ffdf6f98dca, 0x4}, 0x17fcf8b7c7ecf8cf, {0xc0000ac208, 0x1, 0x1}) /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:113 +0x39b created by github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).StartBackgroundTasks in goroutine 1 /github/workspace/weed/mount/weedfs.go:150 +0x146
2024-10-10 13:45:58 +08:00
if entry != nil {
dir := resp.Directory
if resp.EventNotification.NewParentPath != "" {
dir = resp.EventNotification.NewParentPath
}
fp := util.NewFullPath(dir, entry.Name)
2024-10-07 03:55:19 +08:00
avoid nil I1010 03:10:25.220345 mount_std.go:281 This is SeaweedFS version 30GB 3.76 82ed61c6552e5095c682131012c91594ad2643e6 linux amd64 ^[OR^[OR2024/10/10 03:12:56 Unimplemented opcode POLL panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x3983b41] goroutine 112 [running]: github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents.func2.mergeProceesors.1(0xc000513540) /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:30 +0x41 github.com/seaweedfs/seaweedfs/weed/pb.WithFilerClientFollowMetadata.makeSubscribeMetadataFunc.func1({0x514a560, 0xc0009b06d0}) /github/workspace/weed/pb/filer_pb_tail.go:87 +0x293 github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient.func1.1(0xc000d9e008) /github/workspace/weed/mount/wfs_filer_client.go:27 +0x68 github.com/seaweedfs/seaweedfs/weed/pb.WithGrpcClient(0xa9?, 0x9d1f90fb?, 0xc00098fbe0, {0xc000e1c078, 0x15}, 0x0?, {0xc000a76bd0?, 0x1?, 0x1? }) /github/workspace/weed/pb/grpc_client_server.go:155 +0x33a github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient.func1() /github/workspace/weed/mount/wfs_filer_client.go:25 +0x14c github.com/seaweedfs/seaweedfs/weed/util.Retry({0x489a10c, 0xa}, 0xc00098fcf8) /github/workspace/weed/util/retry.go:16 +0xa7 github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient(0x0?, 0x30?, 0xc00056a568?) /github/workspace/weed/mount/wfs_filer_client.go:18 +0x65 github.com/seaweedfs/seaweedfs/weed/pb.WithFilerClientFollowMetadata({0x50f5898, 0xc000e2c180}, 0xc00101e000, 0xc000d22030) /github/workspace/weed/pb/filer_pb_tail.go:51 +0x87 github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents.func2() /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:115 +0xcb github.com/seaweedfs/seaweedfs/weed/util.RetryUntil({0x48b8b35, 0x11}, 0xc00098fef0, 0x4af0048) /github/workspace/weed/util/retry.go:64 +0x4e github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents(0xc000d1d980, 0x9d1f90fb, {0x50f5898, 0xc000e2c180}, {0x7ffdf6f98dca, 0x4}, 0x17fcf8b7c7ecf8cf, {0xc0000ac208, 0x1, 0x1}) /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:113 +0x39b created by github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).StartBackgroundTasks in goroutine 1 /github/workspace/weed/mount/weedfs.go:150 +0x146
2024-10-10 13:45:58 +08:00
for _, follower := range followers {
if strings.HasPrefix(string(fp), follower.PathPrefixToWatch) {
if err := follower.ProcessEventFn(resp); err != nil {
return err
}
2024-10-07 03:55:19 +08:00
}
}
}
return mainProcessor(resp)
}
}
func SubscribeMetaEvents(mc *MetaCache, selfSignature int32, client filer_pb.FilerClient, dir string, lastTsNs int64, followers ...*MetadataFollower) error {
var prefixes []string
for _, follower := range followers {
prefixes = append(prefixes, follower.PathPrefixToWatch)
}
2022-02-14 17:09:31 +08:00
processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {
message := resp.EventNotification
for _, sig := range message.Signatures {
if sig == selfSignature && selfSignature != 0 {
return nil
}
}
dir := resp.Directory
var oldPath util.FullPath
var newEntry *filer.Entry
if message.OldEntry != nil {
oldPath = util.NewFullPath(dir, message.OldEntry.Name)
glog.V(4).Infof("deleting %v", oldPath)
}
if message.NewEntry != nil {
if message.NewParentPath != "" {
dir = message.NewParentPath
}
key := util.NewFullPath(dir, message.NewEntry.Name)
glog.V(4).Infof("creating %v", key)
newEntry = filer.FromPbEntry(dir, message.NewEntry)
}
err := mc.AtomicUpdateEntryFromFiler(context.Background(), oldPath, newEntry)
2022-02-14 17:09:31 +08:00
if err == nil {
if message.OldEntry != nil && message.NewEntry != nil {
oldKey := util.NewFullPath(resp.Directory, message.OldEntry.Name)
mc.invalidateFunc(oldKey, message.OldEntry)
if message.OldEntry.Name != message.NewEntry.Name {
newKey := util.NewFullPath(dir, message.NewEntry.Name)
mc.invalidateFunc(newKey, message.NewEntry)
}
2022-02-25 17:17:26 +08:00
} else if filer_pb.IsCreate(resp) {
// no need to invalidate
2022-02-25 17:17:26 +08:00
} else if filer_pb.IsDelete(resp) {
2022-02-14 17:09:31 +08:00
oldKey := util.NewFullPath(resp.Directory, message.OldEntry.Name)
mc.invalidateFunc(oldKey, message.OldEntry)
}
}
return err
}
prefix := dir
if !strings.HasSuffix(prefix, "/") {
prefix = prefix + "/"
}
2023-03-22 14:01:49 +08:00
metadataFollowOption := &pb.MetadataFollowOption{
ClientName: "mount",
ClientId: selfSignature,
2023-10-14 07:48:14 +08:00
ClientEpoch: 1,
2023-03-22 14:01:49 +08:00
SelfSignature: selfSignature,
PathPrefix: prefix,
2024-10-07 03:55:19 +08:00
AdditionalPathPrefixes: prefixes,
2023-03-22 14:01:49 +08:00
DirectoriesToWatch: nil,
StartTsNs: lastTsNs,
StopTsNs: 0,
EventErrorType: pb.FatalOnError,
}
2023-10-02 02:33:56 +08:00
util.RetryUntil("followMetaUpdates", func() error {
2023-10-14 07:48:14 +08:00
metadataFollowOption.ClientEpoch++
avoid nil I1010 03:10:25.220345 mount_std.go:281 This is SeaweedFS version 30GB 3.76 82ed61c6552e5095c682131012c91594ad2643e6 linux amd64 ^[OR^[OR2024/10/10 03:12:56 Unimplemented opcode POLL panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x3983b41] goroutine 112 [running]: github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents.func2.mergeProceesors.1(0xc000513540) /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:30 +0x41 github.com/seaweedfs/seaweedfs/weed/pb.WithFilerClientFollowMetadata.makeSubscribeMetadataFunc.func1({0x514a560, 0xc0009b06d0}) /github/workspace/weed/pb/filer_pb_tail.go:87 +0x293 github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient.func1.1(0xc000d9e008) /github/workspace/weed/mount/wfs_filer_client.go:27 +0x68 github.com/seaweedfs/seaweedfs/weed/pb.WithGrpcClient(0xa9?, 0x9d1f90fb?, 0xc00098fbe0, {0xc000e1c078, 0x15}, 0x0?, {0xc000a76bd0?, 0x1?, 0x1? }) /github/workspace/weed/pb/grpc_client_server.go:155 +0x33a github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient.func1() /github/workspace/weed/mount/wfs_filer_client.go:25 +0x14c github.com/seaweedfs/seaweedfs/weed/util.Retry({0x489a10c, 0xa}, 0xc00098fcf8) /github/workspace/weed/util/retry.go:16 +0xa7 github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).WithFilerClient(0x0?, 0x30?, 0xc00056a568?) /github/workspace/weed/mount/wfs_filer_client.go:18 +0x65 github.com/seaweedfs/seaweedfs/weed/pb.WithFilerClientFollowMetadata({0x50f5898, 0xc000e2c180}, 0xc00101e000, 0xc000d22030) /github/workspace/weed/pb/filer_pb_tail.go:51 +0x87 github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents.func2() /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:115 +0xcb github.com/seaweedfs/seaweedfs/weed/util.RetryUntil({0x48b8b35, 0x11}, 0xc00098fef0, 0x4af0048) /github/workspace/weed/util/retry.go:64 +0x4e github.com/seaweedfs/seaweedfs/weed/mount/meta_cache.SubscribeMetaEvents(0xc000d1d980, 0x9d1f90fb, {0x50f5898, 0xc000e2c180}, {0x7ffdf6f98dca, 0x4}, 0x17fcf8b7c7ecf8cf, {0xc0000ac208, 0x1, 0x1}) /github/workspace/weed/mount/meta_cache/meta_cache_subscribe.go:113 +0x39b created by github.com/seaweedfs/seaweedfs/weed/mount.(*WFS).StartBackgroundTasks in goroutine 1 /github/workspace/weed/mount/weedfs.go:150 +0x146
2024-10-10 13:45:58 +08:00
return pb.WithFilerClientFollowMetadata(client, metadataFollowOption, mergeProcessors(processEventFn, followers...))
2022-02-14 17:09:31 +08:00
}, func(err error) bool {
glog.Errorf("follow metadata updates: %v", err)
return true
})
return nil
}