Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamskp11 committed Sep 23, 2024
2 parents 946439c + 1d20c2e commit 640e19a
Show file tree
Hide file tree
Showing 87 changed files with 3,143 additions and 581 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tmp_dir = "tmp"
exclude_regex = []
exclude_unchanged = false
follow_symlink = false
full_bin = "GO_ENV=development ./dicedb"
full_bin = "GO_ENV=development ./dicedb --enable-multithreading=false"
include_dir = []
include_ext = ["go", "tpl", "tmpl", "yaml", "env"]
kill_delay = "1s"
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ unittest-one:
go test -v -race -count=1 --run $(TEST_FUNC) ./internal/...

build-docker:
docker build --tag dicedb/dicedb:latest --tag dicedb/dicedb:0.0.2 .
docker build --tag dicedb/dicedb:latest --tag dicedb/dicedb:0.0.4 .

push-docker:
docker push dicedb/dicedb:0.0.4

GOLANGCI_LINT_VERSION := 1.60.1

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ To run the live DiceDB server for local development:
```sh
$ git clone https://github.com/dicedb/dice
$ cd dice
$ air
$ DICE_ENV=dev air
```

> The `DICE_ENV` environment variable is used set the environment, by default it is treated as production. `dev` is used to get pretty printed logs and lower log level.
### Local Setup with Custom Config

By default, DiceDB will look for the configuration file at `/etc/dice/config.toml`. (Linux, Darwin, and WSL)
Expand Down
57 changes: 42 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package config

import (
"log/slog"
"os"
"path/filepath"
"runtime"
"strings"
"time"

"github.com/charmbracelet/log"
"github.com/dicedb/dice/internal/server/utils"
"github.com/pelletier/go-toml/v2"
"github.com/spf13/viper"
Expand All @@ -29,8 +29,9 @@ var (
Host = DefaultHost
Port = DefaultPort

EnableHTTP = true
HTTPPort = 8082
EnableMultiThreading = false
EnableHTTP = true
HTTPPort = 8082
// if RequirePass is set to an empty string, no authentication is required
RequirePass = utils.EmptyStr

Expand Down Expand Up @@ -58,6 +59,9 @@ type Config struct {
PersistenceEnabled bool `mapstructure:"persistenceenabled"`
WriteAOFOnCleanup bool `mapstructure:"writeaofoncleanup"`
LFULogFactor int `mapstructure:"lfulogfactor"`
LogLevel string `mapstructure:"loglevel"`
PrettyPrintLogs bool `mapstructure:"prettyprintlogs"`
EnableMultiThreading bool `mapstructure:"enablemultithreading"`
} `mapstructure:"server"`
Auth struct {
UserName string `mapstructure:"username"`
Expand All @@ -70,7 +74,7 @@ type Config struct {
}

// Default configurations for internal use
var defaultConfig = Config{
var baseConfig = Config{
Server: struct {
Addr string `mapstructure:"addr"`
Port int `mapstructure:"port"`
Expand All @@ -88,6 +92,9 @@ var defaultConfig = Config{
PersistenceEnabled bool `mapstructure:"persistenceenabled"`
WriteAOFOnCleanup bool `mapstructure:"writeaofoncleanup"`
LFULogFactor int `mapstructure:"lfulogfactor"`
LogLevel string `mapstructure:"loglevel"`
PrettyPrintLogs bool `mapstructure:"prettyprintlogs"`
EnableMultiThreading bool `mapstructure:"enablemultithreading"`
}{
Addr: DefaultHost,
Port: DefaultPort,
Expand All @@ -105,6 +112,9 @@ var defaultConfig = Config{
PersistenceEnabled: true,
WriteAOFOnCleanup: true,
LFULogFactor: 10,
LogLevel: "info",
PrettyPrintLogs: false,
EnableMultiThreading: false,
},
Auth: struct {
UserName string `mapstructure:"username"`
Expand All @@ -122,6 +132,24 @@ var defaultConfig = Config{
},
}

var defaultConfig Config

func init() {
config := baseConfig
env := os.Getenv("DICE_ENV")
switch env {
case "dev":
config.Server.LogLevel = "debug"
config.Server.PrettyPrintLogs = true
default:
}
logLevel := os.Getenv("DICE_LOG_LEVEL")
if logLevel != "" {
config.Server.LogLevel = logLevel
}
defaultConfig = config
}

// DiceConfig is the global configuration object for dice
var DiceConfig *Config = &defaultConfig

Expand All @@ -134,7 +162,7 @@ func SetupConfig() {

// Check if both -o and -c flags are set
if areBothFlagsSet() {
log.Error("Both -o and -c flags are set. Please use only one flag.")
slog.Error("Both -o and -c flags are set. Please use only one flag.")
return
}

Expand All @@ -156,19 +184,18 @@ func SetupConfig() {

func createConfigFile(configFilePath string) {
if _, err := os.Stat(configFilePath); err == nil {
log.Warnf("config file already exists at %s", configFilePath)
slog.Warn("config file already exists", slog.String("path", configFilePath))
setUpViperConfig(configFilePath)
return
}

if err := writeConfigFile(configFilePath); err != nil {
log.Error(err)
log.Warn("starting DiceDB with default configurations.")
slog.Warn("starting DiceDB with default configurations.", slog.Any("error", err))
return
}

setUpViperConfig(configFilePath)
log.Infof("config file created at %s with default configurations", configFilePath)
slog.Info("config file created at %s with default configurations", slog.Any("path", configFilePath))
}

func writeConfigFile(configFilePath string) error {
Expand All @@ -177,7 +204,7 @@ func writeConfigFile(configFilePath string) error {
return err
}

log.Infof("creating default config file at %s", configFilePath)
slog.Info("creating default config file at %s", slog.Any("path", configFilePath))
file, err := os.Create(configFilePath)
if err != nil {
return err
Expand Down Expand Up @@ -227,22 +254,22 @@ func setUpViperConfig(configFilePath string) {
viper.SetConfigType("toml")
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
log.Warn("config file not found. Using default configurations.")
slog.Warn("config file not found. Using default configurations.")
return
}
log.Errorf("Error reading config file: %v", err.Error())
slog.Error("Error reading config file", slog.Any("error", err))
}

if err := viper.Unmarshal(&DiceConfig); err != nil {
log.Errorf("Error unmarshalling config file: %v", err.Error())
log.Warn("starting DiceDB with default configurations.")
slog.Error("Error unmarshalling config file", slog.Any("error", err))
slog.Warn("starting DiceDB with default configurations.")
return
}

// override default configurations with command line flags
mergeFlagsWithConfig()

log.Info("configurations loaded successfully.")
slog.Info("configurations loaded successfully.")
}

func mergeFlagsWithConfig() {
Expand Down
Binary file added dice
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/leaderboard-go/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
dicedb:
image: dicedb/dicedb:0.0.2
image: dicedb/dicedb:latest
ports:
- "7379:7379"

Expand Down
13 changes: 3 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,22 @@ go 1.23.0
require gotest.tools/v3 v3.5.1

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -39,7 +32,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand All @@ -49,13 +42,13 @@ require (
require (
github.com/axiomhq/hyperloglog v0.2.0
github.com/bytedance/sonic v1.12.1
github.com/charmbracelet/log v0.4.0
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831
github.com/ohler55/ojg v1.24.0
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rs/xid v1.6.0
github.com/rs/zerolog v1.30.0
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/twmb/murmur3 v1.1.8
Expand Down
18 changes: 16 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964 h1:Ew0znI2JatzKy52N1iS5muUsHkf2UJuhocH7uFW7jjs=
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964/go.mod h1:yBRu/cnL4ks9bgy4vAASdjIW+/xMlFwuHKqtmh3GZQg=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand All @@ -43,6 +44,7 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand All @@ -58,6 +60,11 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
Expand All @@ -73,6 +80,7 @@ github.com/ohler55/ojg v1.24.0 h1:y2AVez6fPTszK/jPhaAYMCAzAoSleConMqSDD5wJKJg=
github.com/ohler55/ojg v1.24.0/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -82,8 +90,11 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
Expand Down Expand Up @@ -124,8 +135,11 @@ golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VA
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package async

import (
"testing"
Expand Down
Loading

0 comments on commit 640e19a

Please sign in to comment.