mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +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>
32 lines
771 B
Go
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
|
|
}
|