From f7ffd6a125eea956a20a4401072290f54c567ee5 Mon Sep 17 00:00:00 2001 From: ykadowak Date: Tue, 26 Sep 2023 04:06:33 +0000 Subject: [PATCH] Fix DeepSource errors --- internal/config/corrector.go | 2 +- internal/net/grpc/context.go | 3 ++- internal/servers/server/server.go | 10 +++++++--- pkg/index/job/correction/service/corrector.go | 7 +++---- pkg/index/job/correction/service/corrector_test.go | 4 ++-- pkg/index/job/correction/usecase/corrector.go | 3 ++- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/internal/config/corrector.go b/internal/config/corrector.go index 806f5babeb..c29f508472 100644 --- a/internal/config/corrector.go +++ b/internal/config/corrector.go @@ -72,7 +72,7 @@ func (c *Corrector) GetStreamListConcurrency() int { return 200 //nolint:gomnd } -// Returns 2048 when not specified since not setting this could use up all the available momory +// GetBboltAsyncWriteConcurrency returns 2048 when not specified since not setting this could use up all the available momory func (c *Corrector) GetBboltAsyncWriteConcurrency() int { if c != nil { return c.BboltAsyncWriteConcurrency diff --git a/internal/net/grpc/context.go b/internal/net/grpc/context.go index e3077fb67c..2e06fb7897 100644 --- a/internal/net/grpc/context.go +++ b/internal/net/grpc/context.go @@ -20,7 +20,8 @@ import ( type contextKey string -// exported only for testing +// GrpcMethodContextKey represents a context key for grpc method. +// This is exported only for testing. const GrpcMethodContextKey contextKey = "grpc_method" // WrapGRPCMethod returns a copy of parent in which the method associated with key (grpcMethodContextKey). diff --git a/internal/servers/server/server.go b/internal/servers/server/server.go index 9e70fb9512..709f5c973e 100644 --- a/internal/servers/server/server.go +++ b/internal/servers/server/server.go @@ -22,6 +22,7 @@ import ( "crypto/tls" "net/http" "os" + "path/filepath" "reflect" "strconv" "syscall" @@ -128,6 +129,7 @@ type grpcKeepalive struct { permitWithoutStream bool } +// skipcq: GO-R1005 func New(opts ...Option) (Server, error) { srv := new(server) @@ -253,6 +255,7 @@ func (s *server) Name() string { return s.name } +// skipcq: GO-R1005 func (s *server) ListenAndServe(ctx context.Context, ech chan<- error) (err error) { if !s.IsRunning() { s.mu.Lock() @@ -274,8 +277,8 @@ func (s *server) ListenAndServe(ctx context.Context, ech chan<- error) (err erro return s.network.String() }(), func() string { if s.network == net.UNIX { - if len(s.socketPath) == 0 { - s.socketPath = os.TempDir() + string(os.PathSeparator) + s.name + "." + strconv.Itoa(os.Getpid()) + ".sock" + if s.socketPath == "" { + s.socketPath = filepath.Join(os.TempDir(), string(os.PathSeparator), s.name, ".", strconv.Itoa(os.Getpid()), ".sock") } return s.socketPath } @@ -339,6 +342,7 @@ func (s *server) ListenAndServe(ctx context.Context, ech chan<- error) (err erro return nil } +// skipcq: GO-R1005 func (s *server) Shutdown(ctx context.Context) (rerr error) { if !s.IsRunning() { return nil @@ -385,7 +389,7 @@ func (s *server) Shutdown(ctx context.Context) (rerr error) { } } - if len(s.socketPath) != 0 { + if s.socketPath != "" { defer func() { err := os.RemoveAll(s.socketPath) if err != nil { diff --git a/pkg/index/job/correction/service/corrector.go b/pkg/index/job/correction/service/corrector.go index faa5b19d3a..912c52deca 100644 --- a/pkg/index/job/correction/service/corrector.go +++ b/pkg/index/job/correction/service/corrector.go @@ -125,12 +125,10 @@ func (c *correct) Start(ctx context.Context) (<-chan error, error) { func (c *correct) PreStop(_ context.Context) error { log.Info("removing persistent cache files...") - if err := c.checkedID.Close(true); err != nil { - return err - } - return nil + return c.checkedID.Close(true) } +// skipcq: GO-R1005 func (c *correct) correct(ctx context.Context) (err error) { // leftAgentAddrs is the agents' addr that hasn't been corrected yet. // This is used to know which agents possibly have the same index as the target replica. @@ -381,6 +379,7 @@ func (c *correct) correctTimestamp(ctx context.Context, targetReplica *vectorRep return nil } + // skipcq: CRT-D0001 allReplicas := append(foundReplicas, targetReplica) // sort by timestamp diff --git a/pkg/index/job/correction/service/corrector_test.go b/pkg/index/job/correction/service/corrector_test.go index 5083eadf10..533a8c2fd1 100644 --- a/pkg/index/job/correction/service/corrector_test.go +++ b/pkg/index/job/correction/service/corrector_test.go @@ -31,11 +31,11 @@ type mockDiscovererClient struct { client mock.ClientInternal } -func (*mockDiscovererClient) Start(ctx context.Context) (<-chan error, error) { +func (*mockDiscovererClient) Start(context.Context) (<-chan error, error) { return nil, nil } -func (*mockDiscovererClient) GetAddrs(ctx context.Context) []string { +func (*mockDiscovererClient) GetAddrs(context.Context) []string { return nil } diff --git a/pkg/index/job/correction/usecase/corrector.go b/pkg/index/job/correction/usecase/corrector.go index 5567016f7a..5f4bc4c2ea 100644 --- a/pkg/index/job/correction/usecase/corrector.go +++ b/pkg/index/job/correction/usecase/corrector.go @@ -177,6 +177,7 @@ func (r *run) Start(ctx context.Context) (<-chan error, error) { p, err := os.FindProcess(os.Getpid()) if err != nil { // using Fatal to avoid this process to be zombie + // skipcq: RVV-A0003 log.Fatalf("failed to find my pid to kill %v", err) return } @@ -216,6 +217,6 @@ func (r *run) Stop(ctx context.Context) error { return nil } -func (*run) PostStop(ctx context.Context) error { +func (*run) PostStop(_ context.Context) error { return nil }