Skip to content

Commit

Permalink
Server initialization hook
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitbbhayani committed Jan 22, 2025
1 parent 168c9ce commit ec0b852
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var rootCmd = &cobra.Command{
Short: "an in-memory database;",
Run: func(cmd *cobra.Command, args []string) {
config.Init(cmd.Flags())
server.Init()
server.Start()
},
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type DiceDBConfig struct {
MaxClients int `mapstructure:"max-clients" default:"20000" description:"the maximum number of clients to accept"`
NumShards int `mapstructure:"num-shards" default:"-1" description:"number of shards to create. defaults to number of cores"`

EnableWAL bool `mapstructure:"enable-wal" default:"true" description:"enable write-ahead logging"`
EnableWAL bool `mapstructure:"enable-wal" default:"false" description:"enable write-ahead logging"`
WALEngine string `mapstructure:"wal-engine" default:"aof" description:"wal engine to use, values: sqlite, aof"`
WALDir string `mapstructure:"wal-dir" default:"/var/log/dicedb" description:"the directory to store WAL segments"`
WALMode string `mapstructure:"wal-mode" default:"buffered" description:"wal mode to use, values: buffered, unbuffered"`
Expand Down
2 changes: 1 addition & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func New() *slog.Logger {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
zerologLogger := zerolog.New(zerolog.ConsoleWriter{
Out: os.Stderr,
NoColor: true,
NoColor: false,
TimeFormat: time.RFC3339,
}).Level(toZerologLevel(getSLogLevel())).With().Timestamp().Logger()
return slog.New(newZerologHandler(&zerologLogger))
Expand Down
12 changes: 7 additions & 5 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"time"

"github.com/dicedb/dice/internal/auth"
"github.com/dicedb/dice/internal/logger"
"github.com/dicedb/dice/internal/server/httpws"

"github.com/dicedb/dice/internal/commandhandler"
"github.com/dicedb/dice/internal/logger"
"github.com/dicedb/dice/internal/server/abstractserver"
"github.com/dicedb/dice/internal/wal"
"github.com/dicedb/dice/internal/watchmanager"
Expand Down Expand Up @@ -60,6 +60,10 @@ func printBanner() {
`)
}

func Init() {
slog.SetDefault(logger.New())
}

func Start() {
printBanner()
printConfiguration()
Expand All @@ -71,8 +75,6 @@ func Start() {
_, _ = auth.UserStore.Add(config.Config.Username)
}

slog.SetDefault(logger.New())

ctx, cancel := context.WithCancel(context.Background())

// Handle SIGTERM and SIGINT
Expand Down Expand Up @@ -113,9 +115,9 @@ func Start() {
slog.Debug("WAL initialization complete")

if config.Config.EnableWAL {
slog.Info("restoring database from WAL")
slog.Info("initializing wal restoration. this may take a while...")
wal.ReplayWAL(wl)
slog.Info("database restored from WAL")
slog.Info("in-memory state restored. process complete")
}
}

Expand Down

0 comments on commit ec0b852

Please sign in to comment.