mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
issue: #33285 - add two grpc resolver (by session and by streaming coord assignment service) - add one grpc balancer (by serverID and roundrobin) - add lazy conn to avoid block by first service discovery - add some utility function for streaming service Signed-off-by: chyezh <chyezh@outlook.com>
34 lines
748 B
Go
34 lines
748 B
Go
package contextutil
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type (
|
|
pickResultKeyType int
|
|
)
|
|
|
|
var pickResultServerIDKey pickResultKeyType = 0
|
|
|
|
// WithPickServerID returns a new context with the pick result.
|
|
func WithPickServerID(ctx context.Context, serverID int64) context.Context {
|
|
return context.WithValue(ctx, pickResultServerIDKey, &serverIDPickResult{
|
|
serverID: serverID,
|
|
})
|
|
}
|
|
|
|
// GetPickServerID must get the pick result from context.
|
|
// panic otherwise.
|
|
func GetPickServerID(ctx context.Context) (int64, bool) {
|
|
pr := ctx.Value(pickResultServerIDKey)
|
|
if pr == nil {
|
|
return -1, false
|
|
}
|
|
return pr.(*serverIDPickResult).serverID, true
|
|
}
|
|
|
|
// serverIDPickResult is used to store the result of picker.
|
|
type serverIDPickResult struct {
|
|
serverID int64
|
|
}
|