add CreateTopic API

This commit is contained in:
chrislu
2023-09-24 14:22:11 -07:00
parent 0f8168c0c9
commit 0361c321b4
9 changed files with 714 additions and 400 deletions

View File

@@ -7,6 +7,26 @@ import (
"google.golang.org/grpc/status"
)
func (broker *MessageQueueBroker) CreateTopic(ctx context.Context, request *mq_pb.CreateTopicRequest) (resp *mq_pb.CreateTopicResponse, err error) {
if broker.currentBalancer == "" {
return nil, status.Errorf(codes.Unavailable, "no balancer")
}
if !broker.lockAsBalancer.IsLocked() {
proxyErr := broker.withBrokerClient(false, broker.currentBalancer, func(client mq_pb.SeaweedMessagingClient) error {
resp, err = client.CreateTopic(ctx, request)
return nil
})
if proxyErr != nil {
return nil, proxyErr
}
return resp, err
}
ret := &mq_pb.CreateTopicResponse{}
ret.BrokerPartitionAssignments, err = broker.Balancer.LookupOrAllocateTopicPartitions(request.Topic, true)
return ret, err
}
// FindTopicBrokers returns the brokers that are serving the topic
//
// 1. lock the topic