|
@ -6,6 +6,7 @@ import ( |
|
|
"github.com/seaweedfs/seaweedfs/weed/glog" |
|
|
"github.com/seaweedfs/seaweedfs/weed/glog" |
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/pub_balancer" |
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/pub_balancer" |
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic" |
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic" |
|
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb" |
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb" |
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb" |
|
|
"google.golang.org/grpc/codes" |
|
|
"google.golang.org/grpc/codes" |
|
|
"google.golang.org/grpc/status" |
|
|
"google.golang.org/grpc/status" |
|
@ -15,11 +16,12 @@ import ( |
|
|
// It generates an assignments based on existing allocations,
|
|
|
// It generates an assignments based on existing allocations,
|
|
|
// and then assign the partitions to the brokers.
|
|
|
// and then assign the partitions to the brokers.
|
|
|
func (b *MessageQueueBroker) ConfigureTopic(ctx context.Context, request *mq_pb.ConfigureTopicRequest) (resp *mq_pb.ConfigureTopicResponse, err error) { |
|
|
func (b *MessageQueueBroker) ConfigureTopic(ctx context.Context, request *mq_pb.ConfigureTopicRequest) (resp *mq_pb.ConfigureTopicResponse, err error) { |
|
|
if b.currentBalancer == "" { |
|
|
|
|
|
|
|
|
if !b.lockAsBalancer.IsLocked() { |
|
|
|
|
|
glog.V(0).Infof("broker %s found balancer:%s, %s isLocked:%v", b.option.BrokerAddress(), pb.ServerAddress(b.lockAsBalancer.LockOwner()), b.lockAsBalancer.LockOwner(), b.lockAsBalancer.IsLocked()) |
|
|
return nil, status.Errorf(codes.Unavailable, "no balancer") |
|
|
return nil, status.Errorf(codes.Unavailable, "no balancer") |
|
|
} |
|
|
} |
|
|
if !b.lockAsBalancer.IsLocked() { |
|
|
|
|
|
proxyErr := b.withBrokerClient(false, b.currentBalancer, func(client mq_pb.SeaweedMessagingClient) error { |
|
|
|
|
|
|
|
|
if !b.isLockOwner() { |
|
|
|
|
|
proxyErr := b.withBrokerClient(false, pb.ServerAddress(b.lockAsBalancer.LockOwner()), func(client mq_pb.SeaweedMessagingClient) error { |
|
|
resp, err = client.ConfigureTopic(ctx, request) |
|
|
resp, err = client.ConfigureTopic(ctx, request) |
|
|
return nil |
|
|
return nil |
|
|
}) |
|
|
}) |
|
@ -30,19 +32,24 @@ func (b *MessageQueueBroker) ConfigureTopic(ctx context.Context, request *mq_pb. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
t := topic.FromPbTopic(request.Topic) |
|
|
t := topic.FromPbTopic(request.Topic) |
|
|
var readErr error |
|
|
|
|
|
|
|
|
var readErr, assignErr error |
|
|
resp, readErr = b.readTopicConfFromFiler(t) |
|
|
resp, readErr = b.readTopicConfFromFiler(t) |
|
|
if readErr != nil { |
|
|
if readErr != nil { |
|
|
glog.V(0).Infof("read topic %s conf: %v", request.Topic, err) |
|
|
|
|
|
} else { |
|
|
|
|
|
readErr = b.ensureTopicActiveAssignments(t, resp) |
|
|
|
|
|
|
|
|
glog.V(0).Infof("read topic %s conf: %v", request.Topic, readErr) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if resp != nil { |
|
|
|
|
|
assignErr = b.ensureTopicActiveAssignments(t, resp) |
|
|
// no need to assign directly.
|
|
|
// no need to assign directly.
|
|
|
// The added or updated assignees will read from filer directly.
|
|
|
// The added or updated assignees will read from filer directly.
|
|
|
// The gone assignees will die by themselves.
|
|
|
// The gone assignees will die by themselves.
|
|
|
} |
|
|
} |
|
|
if readErr == nil && len(resp.BrokerPartitionAssignments) == int(request.PartitionCount) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if readErr == nil && assignErr == nil && len(resp.BrokerPartitionAssignments) == int(request.PartitionCount) { |
|
|
glog.V(0).Infof("existing topic partitions %d: %+v", len(resp.BrokerPartitionAssignments), resp.BrokerPartitionAssignments) |
|
|
glog.V(0).Infof("existing topic partitions %d: %+v", len(resp.BrokerPartitionAssignments), resp.BrokerPartitionAssignments) |
|
|
} else { |
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if resp != nil && len(resp.BrokerPartitionAssignments) > 0 { |
|
|
if resp != nil && len(resp.BrokerPartitionAssignments) > 0 { |
|
|
if cancelErr := b.assignTopicPartitionsToBrokers(ctx, request.Topic, resp.BrokerPartitionAssignments, false); cancelErr != nil { |
|
|
if cancelErr := b.assignTopicPartitionsToBrokers(ctx, request.Topic, resp.BrokerPartitionAssignments, false); cancelErr != nil { |
|
|
glog.V(1).Infof("cancel old topic %s partitions assignments %v : %v", request.Topic, resp.BrokerPartitionAssignments, cancelErr) |
|
|
glog.V(1).Infof("cancel old topic %s partitions assignments %v : %v", request.Topic, resp.BrokerPartitionAssignments, cancelErr) |
|
@ -60,7 +67,6 @@ func (b *MessageQueueBroker) ConfigureTopic(ctx context.Context, request *mq_pb. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
b.Balancer.OnPartitionChange(request.Topic, resp.BrokerPartitionAssignments) |
|
|
b.Balancer.OnPartitionChange(request.Topic, resp.BrokerPartitionAssignments) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
glog.V(0).Infof("ConfigureTopic: topic %s partition assignments: %v", request.Topic, resp.BrokerPartitionAssignments) |
|
|
glog.V(0).Infof("ConfigureTopic: topic %s partition assignments: %v", request.Topic, resp.BrokerPartitionAssignments) |
|
|
|
|
|
|
|
|