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
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/client/pub_client"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_agent_pb"
|
|
"log/slog"
|
|
"math/rand/v2"
|
|
)
|
|
|
|
func (a *MessageQueueAgent) StartPublishSession(ctx context.Context, req *mq_agent_pb.StartPublishSessionRequest) (*mq_agent_pb.StartPublishSessionResponse, error) {
|
|
sessionId := rand.Int64()
|
|
|
|
topicPublisher, err := pub_client.NewTopicPublisher(
|
|
&pub_client.PublisherConfiguration{
|
|
Topic: topic.NewTopic(req.Topic.Namespace, req.Topic.Name),
|
|
PartitionCount: req.PartitionCount,
|
|
Brokers: a.brokersList(),
|
|
PublisherName: req.PublisherName,
|
|
RecordType: req.RecordType,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
a.publishersLock.Lock()
|
|
a.publishers[SessionId(sessionId)] = &SessionEntry[*pub_client.TopicPublisher]{
|
|
entry: topicPublisher,
|
|
}
|
|
a.publishersLock.Unlock()
|
|
|
|
return &mq_agent_pb.StartPublishSessionResponse{
|
|
SessionId: sessionId,
|
|
}, nil
|
|
}
|
|
|
|
func (a *MessageQueueAgent) ClosePublishSession(ctx context.Context, req *mq_agent_pb.ClosePublishSessionRequest) (*mq_agent_pb.ClosePublishSessionResponse, error) {
|
|
var finishErr string
|
|
a.publishersLock.Lock()
|
|
publisherEntry, found := a.publishers[SessionId(req.SessionId)]
|
|
if found {
|
|
if err := publisherEntry.entry.FinishPublish(); err != nil {
|
|
finishErr = err.Error()
|
|
slog.Warn("failed to finish publish", "error", err)
|
|
}
|
|
delete(a.publishers, SessionId(req.SessionId))
|
|
}
|
|
a.publishersLock.Unlock()
|
|
return &mq_agent_pb.ClosePublishSessionResponse{
|
|
Error: finishErr,
|
|
}, nil
|
|
}
|