[#1539] object: Make search check the service state before request
All checks were successful
DCO action / DCO (pull_request) Successful in 3m22s
Tests and linters / Run gofumpt (pull_request) Successful in 3m24s
Vulncheck / Vulncheck (pull_request) Successful in 4m39s
Pre-commit hooks / Pre-commit (pull_request) Successful in 4m50s
Build / Build Components (pull_request) Successful in 5m21s
Tests and linters / Lint (pull_request) Successful in 5m20s
Tests and linters / gopls check (pull_request) Successful in 5m22s
Tests and linters / Staticcheck (pull_request) Successful in 5m38s
Tests and linters / Tests with -race (pull_request) Successful in 5m57s
Tests and linters / Tests (pull_request) Successful in 6m26s

* Introduce `rpcSearchDialer` and pass it to raw `SearchObjects` call.
  The dialer helps to check a cached gRPC connection. If it's invalidated
  in fact, then the call get failed immediatly and the call doesn't need to
  wait for context cancellation.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2024-12-04 16:57:50 +03:00
parent 279549be94
commit 7eb557f4c8

View file

@ -17,6 +17,10 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/signature" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/signature"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
healthV1 "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/status"
) )
type requestForwarder struct { type requestForwarder struct {
@ -25,6 +29,21 @@ type requestForwarder struct {
Key *ecdsa.PrivateKey Key *ecdsa.PrivateKey
} }
func rpcSearchDialer(ctx context.Context, cc grpc.ClientConnInterface) error {
healthClient := healthV1.NewHealthClient(cc)
resp, err := healthClient.Check(ctx, &healthV1.HealthCheckRequest{})
if err != nil {
if status.Code(err) == codes.Unimplemented {
return nil
}
return fmt.Errorf("health check error: %w", err)
}
if resp.GetStatus() != healthV1.HealthCheckResponse_SERVING {
return errors.New("unavailable grpc server")
}
return nil
}
func (f *requestForwarder) forwardRequest(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) ([]oid.ID, error) { func (f *requestForwarder) forwardRequest(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) ([]oid.ID, error) {
var err error var err error
@ -47,7 +66,7 @@ func (f *requestForwarder) forwardRequest(ctx context.Context, addr network.Addr
var searchStream *rpc.SearchResponseReader var searchStream *rpc.SearchResponseReader
err = c.RawForAddress(ctx, addr, func(cli *rpcclient.Client) error { err = c.RawForAddress(ctx, addr, func(cli *rpcclient.Client) error {
searchStream, err = rpc.SearchObjects(cli, f.Request, rpcclient.WithContext(ctx)) searchStream, err = rpc.SearchObjects(cli, f.Request, rpcclient.WithContext(ctx), rpcclient.WithDialer(rpcSearchDialer))
return err return err
}) })
if err != nil { if err != nil {