From d54d4bb1ab3ef58c27fb72424339484721d3dd08 Mon Sep 17 00:00:00 2001 From: Prateek Singh Rathore Date: Wed, 4 Dec 2024 21:00:00 +0530 Subject: [PATCH] fixed linter warnings --- internal/commandhandler/commandhandler.go | 17 ++++++++++------- internal/iothread/iothread.go | 3 --- internal/shard/shard_thread.go | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/internal/commandhandler/commandhandler.go b/internal/commandhandler/commandhandler.go index 623d9c848..71813565f 100644 --- a/internal/commandhandler/commandhandler.go +++ b/internal/commandhandler/commandhandler.go @@ -84,16 +84,16 @@ func (h *BaseCommandHandler) Start(ctx context.Context) error { case <-ctx.Done(): return ctx.Err() case cmdReq := <-h.adhocReqChan: - h.handleCmdRequestWithTimeout(ctx, errChan, []*cmd.DiceDBCmd{cmdReq}, true, defaultRequestTimeout) + resp, err := h.handleCmdRequestWithTimeout(ctx, errChan, []*cmd.DiceDBCmd{cmdReq}, true, defaultRequestTimeout) + h.sendResponseToIOThread(resp, err) case err := <-errChan: return h.handleError(err) case data := <-h.ioThreadReadChan: resp, err := h.processCommand(ctx, &data, h.globalErrorChan) + h.sendResponseToIOThread(resp, err) if err != nil { - h.sendResponseToIOThread(err) return err } - h.sendResponseToIOThread(resp) } } } @@ -189,9 +189,8 @@ func (h *BaseCommandHandler) executeCommand(ctx context.Context, diceDBCmd *cmd. var customErr *diceerrors.PreProcessError if errors.As(err, &customErr) { return nil, fmt.Errorf("%v", customErr.Result) - } else { - return nil, err } + return nil, err } case Custom: @@ -488,8 +487,12 @@ func (h *BaseCommandHandler) handleError(err error) error { return fmt.Errorf("error writing response: %v", err) } -func (h *BaseCommandHandler) sendResponseToIOThread(response interface{}) { - h.ioThreadWriteChan <- response +func (h *BaseCommandHandler) sendResponseToIOThread(resp interface{}, err error) { + if err != nil { + h.ioThreadWriteChan <- err + return + } + h.ioThreadWriteChan <- resp } func (h *BaseCommandHandler) isAuthenticated(diceDBCmd *cmd.DiceDBCmd) error { diff --git a/internal/iothread/iothread.go b/internal/iothread/iothread.go index f95707d10..f01023523 100644 --- a/internal/iothread/iothread.go +++ b/internal/iothread/iothread.go @@ -3,14 +3,11 @@ package iothread import ( "context" "log/slog" - "time" "github.com/dicedb/dice/internal/auth" "github.com/dicedb/dice/internal/clientio/iohandler" ) -const defaultRequestTimeout = 6 * time.Second - // IOThread interface type IOThread interface { ID() string diff --git a/internal/shard/shard_thread.go b/internal/shard/shard_thread.go index 4fc40bf5f..587573615 100644 --- a/internal/shard/shard_thread.go +++ b/internal/shard/shard_thread.go @@ -29,15 +29,16 @@ type CmdHandlerChannels struct { } type ShardThread struct { - id ShardID // id is the unique identifier for the shard. - store *dstore.Store // store that the shard is responsible for. - ReqChan chan *ops.StoreOp // ReqChan is this shard's channel for receiving requests. - cmdHandlerMap map[string]CmdHandlerChannels // cmdHandlerMap maps each command handler id to its corresponding CommandHandlerChannels, containing both the common and preprocessing response channels. - mu sync.RWMutex // mu is the cmdHandlerMap's mutex for thread safety. - globalErrorChan chan error // globalErrorChan is the channel for sending system-level errors. - shardErrorChan chan *ShardError // ShardErrorChan is the channel for sending shard-level errors. - lastCronExecTime time.Time // lastCronExecTime is the last time the shard executed cron tasks. - cronFrequency time.Duration // cronFrequency is the frequency at which the shard executes cron tasks. + id ShardID // id is the unique identifier for the shard. + store *dstore.Store // store that the shard is responsible for. + ReqChan chan *ops.StoreOp // ReqChan is this shard's channel for receiving requests. + // cmdHandlerMap maps each command handler id to its corresponding CommandHandlerChannels, containing both the common and preprocessing response channels. + cmdHandlerMap map[string]CmdHandlerChannels + mu sync.RWMutex // mu is the cmdHandlerMap's mutex for thread safety. + globalErrorChan chan error // globalErrorChan is the channel for sending system-level errors. + shardErrorChan chan *ShardError // ShardErrorChan is the channel for sending shard-level errors. + lastCronExecTime time.Time // lastCronExecTime is the last time the shard executed cron tasks. + cronFrequency time.Duration // cronFrequency is the frequency at which the shard executes cron tasks. } // NewShardThread creates a new ShardThread instance with the given shard id and error channel.