mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 09:08:43 +08:00
issue: #43897 - Return LastConfirmedMessageID when wal append operation. - Add resource-key-based locker for broadcast-ack operation to protect the coord state when executing ddl. - Resource-key-based locker is held until the broadcast operation is acked. - ResourceKey support shared and exclusive lock. - Add FastAck execute ack right away after the broadcast done to speed up ddl. - Ack callback will support broadcast message result now. - Add tombstone for broadcaster to avoid to repeatedly commit DDL and ABA issue. --------- Signed-off-by: chyezh <chyezh@outlook.com>
72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/milvus-io/milvus/internal/streamingcoord/server/broadcaster/broadcast"
|
|
"github.com/milvus-io/milvus/pkg/v2/proto/streamingpb"
|
|
"github.com/milvus-io/milvus/pkg/v2/streaming/util/message"
|
|
)
|
|
|
|
// BroadcastService is the interface of the broadcast service.
|
|
type BroadcastService interface {
|
|
streamingpb.StreamingCoordBroadcastServiceServer
|
|
}
|
|
|
|
// NewBroadcastService creates a new broadcast service.
|
|
func NewBroadcastService() BroadcastService {
|
|
return &broadcastServceImpl{}
|
|
}
|
|
|
|
// broadcastServiceeeeImpl is the implementation of the broadcast service.
|
|
type broadcastServceImpl struct{}
|
|
|
|
// Broadcast broadcasts the message to all channels.
|
|
func (s *broadcastServceImpl) Broadcast(ctx context.Context, req *streamingpb.BroadcastRequest) (*streamingpb.BroadcastResponse, error) {
|
|
msg := message.NewBroadcastMutableMessageBeforeAppend(req.Message.Payload, req.Message.Properties)
|
|
api, err := broadcast.StartBroadcastWithResourceKeys(ctx, msg.BroadcastHeader().ResourceKeys.Collect()...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
results, err := api.Broadcast(ctx, msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
protoResult := make(map[string]*streamingpb.ProduceMessageResponseResult, len(results.AppendResults))
|
|
for vchannel, result := range results.AppendResults {
|
|
protoResult[vchannel] = &streamingpb.ProduceMessageResponseResult{
|
|
Id: result.MessageID.IntoProto(),
|
|
Timetick: result.TimeTick,
|
|
LastConfirmedId: result.LastConfirmedMessageID.IntoProto(),
|
|
}
|
|
}
|
|
return &streamingpb.BroadcastResponse{
|
|
BroadcastId: results.BroadcastID,
|
|
Results: protoResult,
|
|
}, nil
|
|
}
|
|
|
|
// Ack acknowledges the message at the specified vchannel.
|
|
func (s *broadcastServceImpl) Ack(ctx context.Context, req *streamingpb.BroadcastAckRequest) (*streamingpb.BroadcastAckResponse, error) {
|
|
broadcaster, err := broadcast.GetWithContext(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if req.Message == nil {
|
|
// before 2.6.1, the request don't have the message field, only have the broadcast id and vchannel.
|
|
// so we need to use the legacy ack interface.
|
|
if err := broadcaster.LegacyAck(ctx, req.BroadcastId, req.Vchannel); err != nil {
|
|
return nil, err
|
|
}
|
|
return &streamingpb.BroadcastAckResponse{}, nil
|
|
}
|
|
if err := broadcaster.Ack(ctx, message.NewImmutableMesasge(
|
|
message.MustUnmarshalMessageID(req.Message.Id),
|
|
req.Message.Payload,
|
|
req.Message.Properties,
|
|
)); err != nil {
|
|
return nil, err
|
|
}
|
|
return &streamingpb.BroadcastAckResponse{}, nil
|
|
}
|