Skip to content

Commit

Permalink
fixed linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
psrvere committed Dec 4, 2024
1 parent 0ffb45d commit d54d4bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
17 changes: 10 additions & 7 deletions internal/commandhandler/commandhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions internal/iothread/iothread.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions internal/shard/shard_thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d54d4bb

Please sign in to comment.