From d53e69ecde00b603f852ca3a58829d7ed1da37fd Mon Sep 17 00:00:00 2001 From: hlts2 Date: Wed, 24 Jan 2024 11:00:47 +0900 Subject: [PATCH] fix: error handling for option and update comment Signed-off-by: hlts2 --- internal/db/kvs/pogreb/options.go | 4 +++- internal/db/kvs/pogreb/pogreb.go | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/db/kvs/pogreb/options.go b/internal/db/kvs/pogreb/options.go index 33cd243de0..f65008c6b0 100644 --- a/internal/db/kvs/pogreb/options.go +++ b/internal/db/kvs/pogreb/options.go @@ -39,7 +39,7 @@ func WithPath(path string) Option { // WithBackgroundSyncInterval returns the option to sets the amount of time between background Sync() calls. // Setting the value to 0 disables the automatic background synchronization. -// Setting the value to -1 makes the DB call Sync() after every write operation. +// Setting the value to -1 or less makes the DB call Sync() after every write operation. func WithBackgroundSyncInterval(s string) Option { return func(d *db) error { if s == "" { @@ -61,6 +61,7 @@ func WithBackgroundSyncInterval(s string) Option { } // WithBackgroundCompactionInterval returns the option to sets the amount of time between background Compact() calls. +// Setting the value to 0 or less disables the automatic background compaction. func WithBackgroundCompactionInterval(s string) Option { return func(d *db) error { if s == "" { @@ -73,6 +74,7 @@ func WithBackgroundCompactionInterval(s string) Option { if d.opts == nil { d.opts = new(pogreb.Options) } + if dur < 0 { dur = -1 } diff --git a/internal/db/kvs/pogreb/pogreb.go b/internal/db/kvs/pogreb/pogreb.go index 03225f0f5b..d2dc8854bd 100644 --- a/internal/db/kvs/pogreb/pogreb.go +++ b/internal/db/kvs/pogreb/pogreb.go @@ -22,6 +22,7 @@ import ( "github.com/vdaas/vald/internal/conv" "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/log" ) // Pogreb represents an interface for operating the pogreb database. @@ -47,7 +48,13 @@ func New(opts ...Option) (_ Pogreb, err error) { db := new(db) for _, opt := range append(deafultOpts, opts...) { if err := opt(db); err != nil { - return nil, errors.ErrOptionFailed(err, reflect.ValueOf(opt)) + oerr := errors.ErrOptionFailed(err, reflect.ValueOf(opt)) + e := &errors.ErrCriticalOption{} + if errors.As(oerr, &e) { + log.Error(err) + return nil, oerr + } + log.Warn(oerr) } }