Skip to content

Commit

Permalink
Adding default config file to be used when dice server starts (DiceDB…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucifercr07 authored and sashpawar11 committed Oct 13, 2024
1 parent 1df50d2 commit 55748da
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 10 deletions.
15 changes: 11 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ type Config struct {
EvictionRatio float64 `mapstructure:"evictionratio"`
KeysLimit int `mapstructure:"keyslimit"`
AOFFile string `mapstructure:"aoffile"`
PersistenceEnabled bool `mapstructure:"persistenceenabled"`
WriteAOFOnCleanup bool `mapstructure:"writeaofoncleanup"`
LFULogFactor int `mapstructure:"lfulogfactor"`
LogLevel string `mapstructure:"loglevel"`
PrettyPrintLogs bool `mapstructure:"prettyprintlogs"`
EnableMultiThreading bool `mapstructure:"enablemultithreading"`
StoreMapInitSize int `mapstructure:"storemapinitsize"`
WatchChanBufSize int `mapstructure:"watchchanbufsize"`
} `mapstructure:"server"`
Auth struct {
UserName string `mapstructure:"username"`
Expand Down Expand Up @@ -99,34 +99,34 @@ var baseConfig = Config{
EvictionRatio float64 `mapstructure:"evictionratio"`
KeysLimit int `mapstructure:"keyslimit"`
AOFFile string `mapstructure:"aoffile"`
PersistenceEnabled bool `mapstructure:"persistenceenabled"`
WriteAOFOnCleanup bool `mapstructure:"writeaofoncleanup"`
LFULogFactor int `mapstructure:"lfulogfactor"`
LogLevel string `mapstructure:"loglevel"`
PrettyPrintLogs bool `mapstructure:"prettyprintlogs"`
EnableMultiThreading bool `mapstructure:"enablemultithreading"`
StoreMapInitSize int `mapstructure:"storemapinitsize"`
WatchChanBufSize int `mapstructure:"watchchanbufsize"`
}{
Addr: DefaultHost,
Port: DefaultPort,
KeepAlive: int32(300),
Timeout: int32(300),
MaxConn: int32(0),
ShardCronFrequency: 1 * time.Second,
ShardCronFrequency: 30 * time.Second,
MultiplexerPollTimeout: 100 * time.Millisecond,
MaxClients: int32(20000),
MaxMemory: 0,
EvictionPolicy: EvictAllKeysLFU,
EvictionRatio: 0.9,
KeysLimit: DefaultKeysLimit,
AOFFile: "./dice-master.aof",
PersistenceEnabled: true,
WriteAOFOnCleanup: false,
LFULogFactor: 10,
LogLevel: "info",
PrettyPrintLogs: false,
EnableMultiThreading: false,
StoreMapInitSize: 1024000,
WatchChanBufSize: 20000,
},
Auth: struct {
UserName string `mapstructure:"username"`
Expand Down Expand Up @@ -305,7 +305,14 @@ func mergeFlagsWithConfig() {

// This function checks if the config file is present or not at ConfigFileLocation
func isConfigFilePresent() bool {
// If config file present in current directory use it
if _, err := os.Stat(filepath.Join(".", DefaultConfigName)); err == nil {
FileLocation = filepath.Join(".", DefaultConfigName)
return true
}

_, err := os.Stat(FileLocation)

return err == nil
}

Expand Down
31 changes: 31 additions & 0 deletions dice.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[Server]
Addr = '0.0.0.0'
Port = 7379
KeepAlive = 300
Timeout = 300
MaxConn = 0
# Value in nanoseconds (30 seconds)
ShardCronFrequency = 30000000000
# Value in nanoseconds (100 ms/0.1 seconds)
MultiplexerPollTimeout = 100000000
MaxClients = 20000
MaxMemory = 0
EvictionPolicy = 'allkeys-lfu'
EvictionRatio = 0.4
KeysLimit = 100000
AOFFile = './dice-master.aof'
WriteAOFOnCleanup = false
LFULogFactor = 10
LogLevel = 'info'
PrettyPrintLogs = false
EnableMultiThreading = false
StoreMapInitSize = 10240
WatchChanBufSize = 20000

[Auth]
UserName = 'dice'
Password = ''

[Network]
IOBufferLength = 512
IOBufferLengthMAX = 51200
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down Expand Up @@ -44,6 +43,7 @@ require (
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831
github.com/gobwas/glob v0.2.3
github.com/google/btree v1.1.3
github.com/google/go-cmp v0.6.0
github.com/gorilla/websocket v1.5.3
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/async/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func RunTestServer(ctx context.Context, wg *sync.WaitGroup, opt TestServerOption

const totalRetries = 100
var err error
watchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Server.KeysLimit)
watchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Server.WatchChanBufSize)
gec := make(chan error)
shardManager := shard.NewShardManager(1, watchChan, gec, opt.Logger)
// Initialize the AsyncServer
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/http/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func RunHTTPServer(ctx context.Context, wg *sync.WaitGroup, opt TestServerOption
config.DiceConfig.Server.WriteAOFOnCleanup = false

globalErrChannel := make(chan error)
watchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Server.KeysLimit)
watchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Server.WatchChanBufSize)
shardManager := shard.NewShardManager(1, watchChan, globalErrChannel, opt.Logger)
queryWatcherLocal := querymanager.NewQueryManager(opt.Logger)
config.HTTPPort = opt.Port
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/websocket/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func RunWebsocketServer(ctx context.Context, wg *sync.WaitGroup, opt TestServerO

// Initialize the WebsocketServer
globalErrChannel := make(chan error)
watchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Server.KeysLimit)
watchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Server.WatchChanBufSize)
shardManager := shard.NewShardManager(1, watchChan, globalErrChannel, opt.Logger)
config.WebsocketPort = opt.Port
testServer := server.NewWebSocketServer(shardManager, watchChan, opt.Logger)
Expand Down
5 changes: 4 additions & 1 deletion internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ func evalDBSIZE(args []string, store *dstore.Store) []byte {
return diceerrors.NewErrArity("DBSIZE")
}

// Expired keys must be explicitly deleted since the cronFrequency for cleanup is configurable.
// A longer delay may prevent timely cleanup, leading to incorrect DBSIZE results.
dstore.DeleteExpiredKeys(store)
// return the RESP encoded value
return clientio.Encode(store.GetKeyCount(), false)
return clientio.Encode(store.GetDBSize(), false)
}

// evalGETDEL returns the value for the queried key in args
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)

watchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Server.KeysLimit)
watchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Server.WatchChanBufSize)
var serverErrCh chan error

// Get the number of available CPU cores on the machine using runtime.NumCPU().
Expand Down

0 comments on commit 55748da

Please sign in to comment.