mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-03 17:31:58 +08:00
This PR implements a new CDC service for Milvus 2.6, providing log-based cross-cluster replication. issue: https://github.com/milvus-io/milvus/issues/44123 --------- Signed-off-by: bigsheeper <yihao.dai@zilliz.com> Signed-off-by: chyezh <chyezh@outlook.com> Co-authored-by: chyezh <chyezh@outlook.com>
67 lines
2.1 KiB
Go
67 lines
2.1 KiB
Go
package broadcast
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/streamingutil/service/lazygrpc"
|
|
"github.com/milvus-io/milvus/pkg/v2/proto/streamingpb"
|
|
"github.com/milvus-io/milvus/pkg/v2/streaming/util/message"
|
|
"github.com/milvus-io/milvus/pkg/v2/streaming/util/types"
|
|
)
|
|
|
|
// NewGRPCBroadcastService creates a new broadcast service with grpc.
|
|
func NewGRPCBroadcastService(service lazygrpc.Service[streamingpb.StreamingCoordBroadcastServiceClient]) *GRPCBroadcastServiceImpl {
|
|
return &GRPCBroadcastServiceImpl{
|
|
service: service,
|
|
}
|
|
}
|
|
|
|
// GRPCBroadcastServiceImpl is the implementation of BroadcastService based on grpc service.
|
|
// If the streaming coord is not deployed at current node, these implementation will be used.
|
|
type GRPCBroadcastServiceImpl struct {
|
|
service lazygrpc.Service[streamingpb.StreamingCoordBroadcastServiceClient]
|
|
}
|
|
|
|
func (c *GRPCBroadcastServiceImpl) Broadcast(ctx context.Context, msg message.BroadcastMutableMessage) (*types.BroadcastAppendResult, error) {
|
|
client, err := c.service.GetService(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp, err := client.Broadcast(ctx, &streamingpb.BroadcastRequest{
|
|
Message: msg.IntoMessageProto(),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
results := make(map[string]*types.AppendResult, len(resp.Results))
|
|
for channel, result := range resp.Results {
|
|
msgID, err := message.UnmarshalMessageID(result.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
results[channel] = &types.AppendResult{
|
|
MessageID: msgID,
|
|
TimeTick: result.GetTimetick(),
|
|
TxnCtx: message.NewTxnContextFromProto(result.GetTxnContext()),
|
|
Extra: result.GetExtra(),
|
|
}
|
|
}
|
|
return &types.BroadcastAppendResult{
|
|
BroadcastID: resp.BroadcastId,
|
|
AppendResults: results,
|
|
}, nil
|
|
}
|
|
|
|
func (c *GRPCBroadcastServiceImpl) Ack(ctx context.Context, msg message.ImmutableMessage) error {
|
|
client, err := c.service.GetService(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = client.Ack(ctx, &streamingpb.BroadcastAckRequest{
|
|
BroadcastId: msg.BroadcastHeader().BroadcastID,
|
|
Vchannel: msg.VChannel(),
|
|
Message: msg.IntoImmutableMessageProto(),
|
|
})
|
|
return err
|
|
}
|