chyezh fda720b880
enhance: streaming service grpc utilities (#34436)
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>
2024-07-15 20:49:38 +08:00

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
}