server: Implement WithMmapSize option for backend config

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.

Backports commit: d69adf45f9e95661966204460f019b8164aaef12 / PR: #17277

Signed-off-by: Ivan Valdes <ivan@vald.es>
This commit is contained in:
Ivan Valdes 2024-05-09 21:33:55 -04:00
parent 0f0af63eaa
commit 6abc349dc9
No known key found for this signature in database
GPG Key ID: 4037D37741ED0CC5

View File

@ -151,6 +151,8 @@ type BackendConfig struct {
Hooks Hooks
}
type BackendConfigOption func(*BackendConfig)
func DefaultBackendConfig() BackendConfig {
return BackendConfig{
BatchInterval: defaultBatchInterval,
@ -163,9 +165,19 @@ func New(bcfg BackendConfig) Backend {
return newBackend(bcfg)
}
func NewDefaultBackend(path string) Backend {
func WithMmapSize(size uint64) BackendConfigOption {
return func(bcfg *BackendConfig) {
bcfg.MmapSize = size
}
}
func NewDefaultBackend(path string, opts ...BackendConfigOption) Backend {
bcfg := DefaultBackendConfig()
bcfg.Path = path
for _, opt := range opts {
opt(&bcfg)
}
return newBackend(bcfg)
}