Skip to content

Commit

Permalink
server: Implement WithMmapSize option for backend config
Browse files Browse the repository at this point in the history
Accept a third argument for NewDefaultBackend for overrides to the
BackendConfig.
Add a new function, WithMmapSize, which modifies the backend config to
provide a custom InitiamMmapSize.

Signed-off-by: Ivan Valdes <ivan@vald.es>
  • Loading branch information
ivanvc committed Feb 13, 2024
1 parent 42f0cb9 commit d69adf4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/storage/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ type BackendConfig struct {
Hooks Hooks
}

type BackendConfigOption func(*BackendConfig)

func DefaultBackendConfig(lg *zap.Logger) BackendConfig {
return BackendConfig{
BatchInterval: defaultBatchInterval,
Expand All @@ -164,9 +166,19 @@ func New(bcfg BackendConfig) Backend {
return newBackend(bcfg)
}

func NewDefaultBackend(lg *zap.Logger, path string) Backend {
func WithMmapSize(size uint64) BackendConfigOption {
return func(bcfg *BackendConfig) {
bcfg.MmapSize = size
}
}

func NewDefaultBackend(lg *zap.Logger, path string, opts ...BackendConfigOption) Backend {
bcfg := DefaultBackendConfig(lg)
bcfg.Path = path
for _, opt := range opts {
opt(&bcfg)
}

return newBackend(bcfg)
}

Expand Down

0 comments on commit d69adf4

Please sign in to comment.