Skip to content

Commit

Permalink
patch release to enhance conf and redundant WAL validation
Browse files Browse the repository at this point in the history
  • Loading branch information
vinitparekh17 committed Dec 18, 2024
1 parent bc15fe8 commit 0e08349
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 39 deletions.
16 changes: 8 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ const (
# Version
version = "0.1.0"
# Async Server Configuration
async_server.addr = "0.0.0.0"
async_server.port = 7379
async_server.keepalive = 300
async_server.timeout = 300
async_server.max_conn = 0
# RESP Server Configuration
resp_server.addr = "0.0.0.0"
resp_server.port = 7379
resp_server.keepalive = 300
resp_server.timeout = 300
resp_server.max_conn = 0
# HTTP Configuration
http.enabled = false
Expand Down Expand Up @@ -127,7 +127,7 @@ type Config struct {
Version string `config:"version" default:"0.1.0"`
InstanceID string `config:"instance_id"`
Auth auth `config:"auth"`
RespServer respServer `config:"async_server"`
RespServer respServer `config:"resp_server"`
HTTP http `config:"http"`
WebSocket websocket `config:"websocket"`
Performance performance `config:"performance"`
Expand Down Expand Up @@ -193,7 +193,7 @@ type persistence struct {

type WALConfig struct {
// Directory where WAL log files will be stored
LogDir string `config:"log_dir" default:"tmp/dicedb-wal"`
LogDir string `config:"log_dir" default:"tmp/dicedb-wal" validate:"dirpath,required"`
// Whether WAL is enabled
Enabled bool `config:"enabled" default:"true"`
// WAL buffering mode: 'buffered' (writes buffered in memory) or 'unbuffered' (immediate disk writes)
Expand Down
23 changes: 1 addition & 22 deletions config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func validateConfig(config *Config) error {
func validateShardCount(sl validator.StructLevel) {
config := sl.Current().Interface().(Config)
if config.Performance.NumShards <= 0 && config.Performance.NumShards != -1 {
sl.ReportError(config.Performance.NumShards, "NumShards", "NumShards", "invalidValue", "must be -1 or greater than 0")
sl.ReportError(config.Performance.NumShards, "NumShards", "NumShards", "invalidValue", "use -1 for auto-sharding as per the number of CPUs or a positive integer")
}
}

Expand Down Expand Up @@ -115,27 +115,6 @@ func applyDefaultValuesFromTags(config *Config, fieldName string) error {

func validateWALConfig(sl validator.StructLevel) {
config := sl.Current().Interface().(Config)

// LogDir validation
if config.WAL.LogDir == "" {
sl.ReportError(config.WAL.LogDir, "LogDir", "LogDir", "required", "cannot be empty")
}

// MaxSegmentSize validation
if config.WAL.MaxSegmentSizeMB <= 0 {
sl.ReportError(config.WAL.MaxSegmentSizeMB, "MaxSegmentSize", "MaxSegmentSize", "gt", "must be greater than 0")
}

// MaxSegmentCount validation
if config.WAL.MaxSegmentCount <= 0 {
sl.ReportError(config.WAL.MaxSegmentCount, "MaxSegmentCount", "MaxSegmentCount", "gt", "must be greater than 0")
}

// BufferSize validation
if config.WAL.BufferSizeMB <= 0 {
sl.ReportError(config.WAL.BufferSizeMB, "BufferSize", "BufferSize", "gt", "must be greater than 0")
}

// WALMode and WriteMode compatibility checks
if config.WAL.WalMode == "buffered" && config.WAL.WriteMode == "fsync" {
sl.ReportError(config.WAL.WalMode, "WALMode", "WALMode", "incompatible", "walMode 'buffered' cannot be used with writeMode 'fsync'")
Expand Down
12 changes: 6 additions & 6 deletions dicedb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Version
version = "0.1.0"

# Async Server Configuration
async_server.addr = "0.0.0.0"
async_server.port = 7379
async_server.keepalive = 300
async_server.timeout = 300
async_server.max_conn = 0
# RESP Server Configuration
resp_server.addr = "0.0.0.0"
resp_server.port = 7379
resp_server.keepalive = 300
resp_server.timeout = 300
resp_server.max_conn = 0

# HTTP Configuration
http.enabled = false
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ require (
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.9.0
github.com/twmb/murmur3 v1.1.8
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
golang.org/x/crypto v0.29.0
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
google.golang.org/protobuf v1.35.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/twmb/murmur3 v1.1.8 h1:8Yt9taO/WN3l08xErzjeschgZU2QSrwm1kclYq+0aRg=
github.com/twmb/murmur3 v1.1.8/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY=
golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
Expand Down

0 comments on commit 0e08349

Please sign in to comment.