mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-06-28 07:04:03 +08:00

Some checks are pending
go: build dev binaries / cleanup (push) Waiting to run
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Blocked by required conditions
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Blocked by required conditions
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Blocked by required conditions
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Blocked by required conditions
docker: build dev containers / build-dev-containers (push) Waiting to run
End to End / FUSE Mount (push) Waiting to run
go: build binary / Build (push) Waiting to run
Ceph S3 tests / Ceph S3 tests (push) Waiting to run
* rename * set agent address * refactor * add agent sub * pub messages * grpc new client * can publish records via agent * send init message with session id * fmt * check cancelled request while waiting * use sessionId * handle possible nil stream * subscriber process messages * separate debug port * use atomic int64 * less logs * minor * skip io.EOF * rename * remove unused * use saved offsets * do not reuse session, since always session id is new after restart remove last active ts from SessionEntry * simplify printing * purge unused * just proxy the subscription, skipping the session step * adjust offset types * subscribe offset type and possible value * start after the known tsns * avoid wrongly set startPosition * move * remove * refactor * typo * fix * fix changed path
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package pub_client
|
|
|
|
import (
|
|
"github.com/rdleal/intervalst/interval"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/pub_balancer"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util/buffered_queue"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
"log"
|
|
"sync"
|
|
)
|
|
|
|
type PublisherConfiguration struct {
|
|
Topic topic.Topic
|
|
PartitionCount int32
|
|
Brokers []string
|
|
PublisherName string // for debugging
|
|
RecordType *schema_pb.RecordType
|
|
}
|
|
|
|
type PublishClient struct {
|
|
mq_pb.SeaweedMessaging_PublishMessageClient
|
|
Broker string
|
|
Err error
|
|
}
|
|
type TopicPublisher struct {
|
|
partition2Buffer *interval.SearchTree[*buffered_queue.BufferedQueue[*mq_pb.DataMessage], int32]
|
|
grpcDialOption grpc.DialOption
|
|
sync.Mutex // protects grpc
|
|
config *PublisherConfiguration
|
|
jobs []*EachPartitionPublishJob
|
|
}
|
|
|
|
func NewTopicPublisher(config *PublisherConfiguration) (tp *TopicPublisher, err error) {
|
|
tp = &TopicPublisher{
|
|
partition2Buffer: interval.NewSearchTree[*buffered_queue.BufferedQueue[*mq_pb.DataMessage]](func(a, b int32) int {
|
|
return int(a - b)
|
|
}),
|
|
grpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
config: config,
|
|
}
|
|
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(1)
|
|
go func() {
|
|
if err = tp.startSchedulerThread(&wg); err != nil {
|
|
log.Println(err)
|
|
return
|
|
}
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
return
|
|
}
|
|
|
|
func (p *TopicPublisher) Shutdown() error {
|
|
|
|
if inputBuffers, found := p.partition2Buffer.AllIntersections(0, pub_balancer.MaxPartitionCount); found {
|
|
for _, inputBuffer := range inputBuffers {
|
|
inputBuffer.CloseInput()
|
|
}
|
|
}
|
|
|
|
for _, job := range p.jobs {
|
|
job.wg.Wait()
|
|
}
|
|
|
|
return nil
|
|
}
|