yihao.dai 51f69f32d0
feat: Add CDC support (#44124)
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>
2025-09-16 16:32:01 +08:00

32 lines
771 B
Go

package contextutil
import (
"context"
"github.com/cockroachdb/errors"
"google.golang.org/grpc/metadata"
)
const clusterIDKey = "cluster-id"
// WithClusterID attaches cluster id to context.
func WithClusterID(ctx context.Context, clusterID string) context.Context {
return metadata.AppendToOutgoingContext(ctx, clusterIDKey, clusterID)
}
// GetClusterID gets cluster id from context.
func GetClusterID(ctx context.Context) (string, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return "", errors.New("cluster id not found from context")
}
msg := md.Get(clusterIDKey)
if len(msg) == 0 {
return "", errors.New("cluster id not found in context")
}
if msg[0] == "" {
return "", errors.New("cluster id is empty")
}
return msg[0], nil
}