grpcutil

package
v0.0.0-...-debceaf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// ForwardMetadataKey is used to record the forwarded host of PD.
	ForwardMetadataKey = "pd-forwarded-host"
	// FollowerHandleMetadataKey is used to mark the permit of follower handle.
	FollowerHandleMetadataKey = "pd-allow-follower-handle"
)

Variables

This section is empty.

Functions

func BuildFollowerHandleContext

func BuildFollowerHandleContext(ctx context.Context) context.Context

BuildFollowerHandleContext creates a context with follower handle metadata information. It is used in client side.

func BuildForwardContext

func BuildForwardContext(ctx context.Context, url string) context.Context

BuildForwardContext creates a context with receiver metadata information. It is used in client side.

func GetClientConn

func GetClientConn(ctx context.Context, addr string, tlsCfg *tls.Config, do ...grpc.DialOption) (*grpc.ClientConn, error)

GetClientConn returns a gRPC client connection. creates a client connection to the given target. By default, it's a non-blocking dial (the function won't wait for connections to be established, and connecting happens in the background). To make it a blocking dial, use WithBlock() dial option.

In the non-blocking case, the ctx does not act against the connection. It only controls the setup steps.

In the blocking case, ctx can be used to cancel or expire the pending connection. Once this function returns, the cancellation and expiration of ctx will be noop. Users should call ClientConn.Close to terminate all the pending operations after this function returns.

func GetForwardedHost

func GetForwardedHost(ctx context.Context, f func(context.Context) (metadata.MD, bool)) string

GetForwardedHost returns the forwarded host in metadata. Only used for test.

func GetOrCreateGRPCConn

func GetOrCreateGRPCConn(ctx context.Context, clientConns *sync.Map, url string, tlsCfg *tls.Config, opt ...grpc.DialOption) (*grpc.ClientConn, error)

GetOrCreateGRPCConn returns the corresponding grpc client connection of the given addr. Returns the old one if's already existed in the clientConns; otherwise creates a new one and returns it.

func IsFollowerHandleEnabled

func IsFollowerHandleEnabled(ctx context.Context, f func(context.Context) (metadata.MD, bool)) bool

IsFollowerHandleEnabled returns the forwarded host in metadata. Only used for test.

func UnaryBackofferInterceptor

func UnaryBackofferInterceptor() grpc.UnaryClientInterceptor

UnaryBackofferInterceptor is a gRPC interceptor that adds a backoffer to the call.

func UnaryCircuitBreakerInterceptor

func UnaryCircuitBreakerInterceptor() grpc.UnaryClientInterceptor

UnaryCircuitBreakerInterceptor is a gRPC interceptor that adds a circuit breaker to the call.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL