2024-06-06 19:44:19 -07:00
|
|
|
package filer_client
|
2024-05-14 08:50:17 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FilerClientAccessor struct {
|
2024-05-20 11:05:18 -07:00
|
|
|
GetFiler func() pb.ServerAddress
|
|
|
|
GetGrpcDialOption func() grpc.DialOption
|
2024-05-14 08:50:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fca *FilerClientAccessor) WithFilerClient(streamingMode bool, fn func(filer_pb.SeaweedFilerClient) error) error {
|
|
|
|
return pb.WithFilerClient(streamingMode, 0, fca.GetFiler(), fca.GetGrpcDialOption(), fn)
|
|
|
|
}
|
|
|
|
|
2024-11-04 12:08:25 -08:00
|
|
|
func (fca *FilerClientAccessor) SaveTopicConfToFiler(t topic.Topic, conf *mq_pb.ConfigureTopicResponse) error {
|
2024-05-14 08:50:17 -07:00
|
|
|
|
|
|
|
glog.V(0).Infof("save conf for topic %v to filer", t)
|
|
|
|
|
|
|
|
// save the topic configuration on filer
|
2024-11-04 12:08:25 -08:00
|
|
|
return fca.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
return t.WriteConfFile(client, conf)
|
|
|
|
})
|
2024-05-14 08:50:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fca *FilerClientAccessor) ReadTopicConfFromFiler(t topic.Topic) (conf *mq_pb.ConfigureTopicResponse, err error) {
|
|
|
|
|
2024-11-04 12:08:25 -08:00
|
|
|
glog.V(1).Infof("load conf for topic %v from filer", t)
|
2024-05-14 08:50:17 -07:00
|
|
|
|
|
|
|
if err = fca.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
2024-11-04 12:08:25 -08:00
|
|
|
conf, err = t.ReadConfFile(client)
|
|
|
|
return err
|
2024-05-14 08:50:17 -07:00
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf, nil
|
|
|
|
}
|
2025-07-11 10:19:27 -07:00
|
|
|
|
|
|
|
// ReadTopicConfFromFilerWithMetadata reads topic configuration along with file creation and modification times
|
|
|
|
func (fca *FilerClientAccessor) ReadTopicConfFromFilerWithMetadata(t topic.Topic) (conf *mq_pb.ConfigureTopicResponse, createdAtNs, modifiedAtNs int64, err error) {
|
|
|
|
|
|
|
|
glog.V(1).Infof("load conf with metadata for topic %v from filer", t)
|
|
|
|
|
|
|
|
if err = fca.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
conf, createdAtNs, modifiedAtNs, err = t.ReadConfFileWithMetadata(client)
|
|
|
|
return err
|
|
|
|
}); err != nil {
|
|
|
|
return nil, 0, 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf, createdAtNs, modifiedAtNs, nil
|
|
|
|
}
|