Skip to content

Commit

Permalink
Renaming all appropriate variables from Redis to DiceDB (DiceDB#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinKul28 authored Oct 3, 2024
1 parent b903a2a commit 03c4b66
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 130 deletions.
2 changes: 1 addition & 1 deletion internal/clientio/requestparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import (
)

type Parser interface {
Parse(data []byte) ([]*cmd.RedisCmd, error)
Parse(data []byte) ([]*cmd.DiceDBCmd, error)
}
10 changes: 5 additions & 5 deletions internal/clientio/requestparser/resp/respparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func (p *Parser) SetData(data []byte) {
p.pos = 0
}

// Parse parses the entire input and returns a slice of RedisCmd
func (p *Parser) Parse(data []byte) ([]*cmd.RedisCmd, error) {
// Parse parses the entire input and returns a slice of DiceDBCmd
func (p *Parser) Parse(data []byte) ([]*cmd.DiceDBCmd, error) {
p.SetData(data)
var commands []*cmd.RedisCmd
var commands []*cmd.DiceDBCmd
for p.pos < len(p.data) {
c, err := p.parseCommand()
if err != nil {
Expand All @@ -68,7 +68,7 @@ func (p *Parser) Parse(data []byte) ([]*cmd.RedisCmd, error) {
return commands, nil
}

func (p *Parser) parseCommand() (*cmd.RedisCmd, error) {
func (p *Parser) parseCommand() (*cmd.DiceDBCmd, error) {
if p.pos >= len(p.data) {
return nil, ErrUnexpectedEOF
}
Expand All @@ -84,7 +84,7 @@ func (p *Parser) parseCommand() (*cmd.RedisCmd, error) {
return nil, fmt.Errorf("error while parsing command, empty command")
}

return &cmd.RedisCmd{
return &cmd.DiceDBCmd{
Cmd: strings.ToUpper(elements[0]),
Args: elements[1:],
}, nil
Expand Down
25 changes: 13 additions & 12 deletions internal/clientio/requestparser/resp/respparser_test.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
package respparser

import (
"github.com/dicedb/dice/mocks"
"log/slog"
"reflect"
"testing"

"github.com/dicedb/dice/mocks"

"github.com/dicedb/dice/internal/cmd"
)

func TestParser_Parse(t *testing.T) {
tests := []struct {
name string
input string
want []*cmd.RedisCmd
want []*cmd.DiceDBCmd
wantErr bool
}{
{
name: "Simple SET command",
input: "*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "SET", Args: []string{"key", "value"}},
},
},
{
name: "GET command",
input: "*2\r\n$3\r\nGET\r\n$3\r\nkey\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "GET", Args: []string{"key"}},
},
},
{
name: "Multiple commands",
input: "*2\r\n$4\r\nPING\r\n$4\r\nPONG\r\n*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "PING", Args: []string{"PONG"}},
{Cmd: "SET", Args: []string{"key", "value"}},
},
},
{
name: "Command with integer argument",
input: "*3\r\n$6\r\nEXPIRE\r\n$3\r\nkey\r\n:60\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "EXPIRE", Args: []string{"key", "60"}},
},
},
Expand All @@ -58,28 +59,28 @@ func TestParser_Parse(t *testing.T) {
{
name: "Command with null bulk string argument",
input: "*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$-1\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "SET", Args: []string{"key", "(nil)"}},
},
},
{
name: "Command with Simple String argument",
input: "*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n+OK\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "SET", Args: []string{"key", "OK"}},
},
},
{
name: "Command with Error argument",
input: "*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n-ERR Invalid argument\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "SET", Args: []string{"key", "ERR Invalid argument"}},
},
},
{
name: "Command with mixed argument types",
input: "*5\r\n$4\r\nMSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n:1000\r\n+OK\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "MSET", Args: []string{"key", "value", "1000", "OK"}},
},
},
Expand All @@ -96,7 +97,7 @@ func TestParser_Parse(t *testing.T) {
{
name: "Command with empty bulk string",
input: "*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$0\r\n\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "SET", Args: []string{"key", ""}},
},
},
Expand All @@ -113,7 +114,7 @@ func TestParser_Parse(t *testing.T) {
{
name: "Large bulk string",
input: "*2\r\n$4\r\nECHO\r\n$1000\r\n" + string(make([]byte, 1000)) + "\r\n",
want: []*cmd.RedisCmd{
want: []*cmd.DiceDBCmd{
{Cmd: "ECHO", Args: []string{string(make([]byte, 1000))}},
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/cmds.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cmd

type RedisCmd struct {
type DiceDBCmd struct {
RequestID uint32
Cmd string
Args []string
}

type RedisCmds struct {
Cmds []*RedisCmd
Cmds []*DiceDBCmd
RequestID uint32
}
10 changes: 5 additions & 5 deletions internal/comm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ func (c *Client) TxnBegin() {
}

func (c *Client) TxnDiscard() {
c.Cqueue.Cmds = make([]*cmd.RedisCmd, 0)
c.Cqueue.Cmds = make([]*cmd.DiceDBCmd, 0)
c.IsTxn = false
}

func (c *Client) TxnQueue(redisCmd *cmd.RedisCmd) {
c.Cqueue.Cmds = append(c.Cqueue.Cmds, redisCmd)
func (c *Client) TxnQueue(diceDBCmd *cmd.DiceDBCmd) {
c.Cqueue.Cmds = append(c.Cqueue.Cmds, diceDBCmd)
}

func NewClient(fd int) *Client {
cmds := make([]*cmd.RedisCmd, 0)
cmds := make([]*cmd.DiceDBCmd, 0)
return &Client{
Fd: fd,
Cqueue: cmd.RedisCmds{
Expand All @@ -57,7 +57,7 @@ func NewClient(fd int) *Client {
}

func NewHTTPQwatchClient(qwatchResponseChan chan QwatchResponse, clientIdentifierID uint32) *Client {
cmds := make([]*cmd.RedisCmd, 0)
cmds := make([]*cmd.DiceDBCmd, 0)
return &Client{
Cqueue: cmd.RedisCmds{Cmds: cmds},
Session: auth.NewSession(),
Expand Down
8 changes: 4 additions & 4 deletions internal/errors/migrated_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
)

// Package errors provides error definitions and utility functions for handling
// common Redis error scenarios within the application. This package centralizes
// error messages to ensure consistency and clarity when interacting with Redis
// common DiceDB error scenarios within the application. This package centralizes
// error messages to ensure consistency and clarity when interacting with DiceDB
// commands and responses.

// Standard error variables for various Redis-related error conditions.
// Standard error variables for various DiceDB-related error conditions.
var (
ErrAuthFailed = errors.New("AUTH failed") // Indicates authentication failure.
ErrIntegerOutOfRange = errors.New("ERR value is not an integer or out of range") // Represents a value that is either not an integer or is out of allowed range.
ErrInvalidNumberFormat = errors.New("ERR value is not an integer or a float") // Signals that a value provided is not in a valid integer or float format.
ErrValueOutOfRange = errors.New("ERR value is out of range") // Indicates that a value is beyond the permissible range.
ErrOverflow = errors.New("ERR increment or decrement would overflow") // Signifies that an increment or decrement operation would exceed the limits.
ErrSyntax = errors.New("ERR syntax error") // Represents a syntax error in a Redis command.
ErrSyntax = errors.New("ERR syntax error") // Represents a syntax error in a DiceDB command.
ErrKeyNotFound = errors.New("ERR no such key") // Indicates that the specified key does not exist.
ErrWrongTypeOperation = errors.New("WRONGTYPE Operation against a key holding the wrong kind of value") // Signals an operation attempted on a key with an incompatible type.
ErrInvalidHyperLogLogKey = errors.New("WRONGTYPE Key is not a valid HyperLogLog string value") // Indicates that a key is not a valid HyperLogLog value.
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
dstore "github.com/dicedb/dice/internal/store"
)

func ExecuteCommand(c *cmd.RedisCmd, client *comm.Client, store *dstore.Store, httpOp, websocketOp bool) *EvalResponse {
func ExecuteCommand(c *cmd.DiceDBCmd, client *comm.Client, store *dstore.Store, httpOp, websocketOp bool) *EvalResponse {
diceCmd, ok := DiceCmds[c.Cmd]
if !ok {
return &EvalResponse{Result: diceerrors.NewErrWithFormattedMessage("unknown command '%s', with args beginning with: %s", c.Cmd, strings.Join(c.Args, " ")), Error: nil}
Expand Down
7 changes: 3 additions & 4 deletions internal/eval/worker_eval.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package eval

// This file contains functions required by worker nodes to
// evaluate specific Redis-like commands (e.g., INFO, PING).
// These evaluation functions are exposed to the worker,
// allowing them to process commands and return appropriate responses.
// These evaluation functions are exposed to the worker, without
// making any contact with shards allowing them to process
// commands and return appropriate responses.

import (
"github.com/dicedb/dice/internal/clientio"
Expand Down
2 changes: 1 addition & 1 deletion internal/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package object

type Obj struct {
TypeEncoding uint8
// Redis allots 24 bits to these bits, but we will use 32 bits because
// Redis allocates 24 bits to these bits, but we will use 32 bits because
// golang does not support bitfields, and we need not make this super-complicated
// by merging TypeEncoding + LastAccessedAt in one 32-bit integer.
// But nonetheless, we can benchmark and see how that fares.
Expand Down
16 changes: 8 additions & 8 deletions internal/ops/store_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
)

type StoreOp struct {
SeqID uint8 // SeqID is the sequence id of the operation within a single request (optional, may be used for ordering)
RequestID uint32 // RequestID identifies the request that this StoreOp belongs to
Cmd *cmd.RedisCmd // Cmd is the atomic Store command (e.g., GET, SET)
ShardID uint8 // ShardID of the shard on which the Store command will be executed
WorkerID string // WorkerID is the ID of the worker that sent this Store operation
Client *comm.Client // Client that sent this Store operation. TODO: This can potentially replace the WorkerID in the future
HTTPOp bool // HTTPOp is true if this Store operation is an HTTP operation
WebsocketOp bool // WebsocketOp is true if this Store operation is a Websocket operation
SeqID uint8 // SeqID is the sequence id of the operation within a single request (optional, may be used for ordering)
RequestID uint32 // RequestID identifies the request that this StoreOp belongs to
Cmd *cmd.DiceDBCmd // Cmd is the atomic Store command (e.g., GET, SET)
ShardID uint8 // ShardID of the shard on which the Store command will be executed
WorkerID string // WorkerID is the ID of the worker that sent this Store operation
Client *comm.Client // Client that sent this Store operation. TODO: This can potentially replace the WorkerID in the future
HTTPOp bool // HTTPOp is true if this Store operation is an HTTP operation
WebsocketOp bool // WebsocketOp is true if this Store operation is a Websocket operation
}

// StoreResponse represents the response of a Store operation.
Expand Down
18 changes: 9 additions & 9 deletions internal/querymanager/query_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

type (
cacheStore common.ITable[string, *object.Obj]
CacheStore common.ITable[string, *object.Obj]

// QuerySubscription represents a subscription to watch a query.
QuerySubscription struct {
Expand Down Expand Up @@ -54,7 +54,7 @@ type (
// Manager watches for changes in keys and notifies clients.
Manager struct {
WatchList sync.Map // WatchList is a map of query string to their respective clients, type: map[string]*sync.Map[int]struct{}
QueryCache common.ITable[string, cacheStore] // QueryCache is a map of fingerprints to their respective data caches
QueryCache common.ITable[string, CacheStore] // QueryCache is a map of fingerprints to their respective data caches
QueryCacheMu sync.RWMutex
logger *slog.Logger
}
Expand Down Expand Up @@ -86,23 +86,23 @@ func NewClientIdentifier(clientIdentifierID int, isHTTPClient bool) ClientIdenti
}
}

func NewQueryCacheStoreRegMap() common.ITable[string, cacheStore] {
return &common.RegMap[string, cacheStore]{
M: make(map[string]cacheStore),
func NewQueryCacheStoreRegMap() common.ITable[string, CacheStore] {
return &common.RegMap[string, CacheStore]{
M: make(map[string]CacheStore),
}
}

func NewQueryCacheStore() common.ITable[string, cacheStore] {
func NewQueryCacheStore() common.ITable[string, CacheStore] {
return NewQueryCacheStoreRegMap()
}

func NewCacheStoreRegMap() cacheStore {
func NewCacheStoreRegMap() CacheStore {
return &common.RegMap[string, *object.Obj]{
M: make(map[string]*object.Obj),
}
}

func NewCacheStore() cacheStore {
func NewCacheStore() CacheStore {
return NewCacheStoreRegMap()
}

Expand Down Expand Up @@ -221,7 +221,7 @@ func (m *Manager) updateQueryCache(queryFingerprint string, event dstore.QueryWa

store, ok := m.QueryCache.Get(queryFingerprint)
if !ok {
m.logger.Warn("Fingerprint not found in cacheStore", slog.String("fingerprint", queryFingerprint))
m.logger.Warn("Fingerprint not found in CacheStore", slog.String("fingerprint", queryFingerprint))
return
}

Expand Down
14 changes: 7 additions & 7 deletions internal/server/cmd_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/dicedb/dice/internal/shard"
)

// CmdType defines the type of Redis command based on how it interacts with shards.
// CmdType defines the type of DiceDB command based on how it interacts with shards.
// It uses an integer value to represent different command types.
type CmdType int

Expand All @@ -21,15 +21,15 @@ const (
Custom // Custom commands involve direct client communication.
)

// CmdsMeta stores metadata about Redis commands, including how they are processed across shards.
// CmdsMeta stores metadata about DiceDB commands, including how they are processed across shards.
// CmdType indicates how the command should be handled, while Breakup and Gather provide logic
// for breaking up multishard commands and gathering their responses.
type CmdsMeta struct {
Cmd string // Command name.
Breakup func(mgr *shard.ShardManager, redisCmd *cmd.RedisCmd, c *comm.Client) []cmd.RedisCmd // Function to break up multishard commands.
Gather func(responses ...eval.EvalResponse) []byte // Function to gather responses from shards.
RespNoShards func(args []string) []byte // Function for commands that don't interact with shards.
CmdType // Enum indicating the command type.
Cmd string // Command name.
Breakup func(mgr *shard.ShardManager, DiceDBCmd *cmd.DiceDBCmd, c *comm.Client) []cmd.DiceDBCmd // Function to break up multishard commands.
Gather func(responses ...eval.EvalResponse) []byte // Function to gather responses from shards.
RespNoShards func(args []string) []byte // Function for commands that don't interact with shards.
CmdType // Enum indicating the command type.
}

// WorkerCmdsMeta is a map that associates command names with their corresponding metadata.
Expand Down
Loading

0 comments on commit 03c4b66

Please sign in to comment.