Update Storage options to support rolling buffer (#798)

Add new storage options:
- `WithBuffer`:  WithBuffer sets the buffer size. The value must be a factorial of 4KiB.
- `WithMinimumBuffer`: WithMinimumBuffer sets the threshold to enforce when the buffer expands back to its original size.
pull/4095/head
Elim Tsiagbey 3 years ago
parent 5056c93845
commit 366128f079

@ -52,6 +52,8 @@ func getDefaultOptions() Options {
WithCloseSyncMode: Asynchronous,
WithFileAccessMode: ReadOnly,
WithCreateFile: false,
WithBuffer: 0,
WithMinimumBuffer: 0,
}
}
@ -60,6 +62,8 @@ type Options struct {
WithCloseSyncMode SyncMode
WithFileAccessMode AccessMode
WithCreateFile bool
WithBuffer uint64
WithMinimumBuffer uint64
}
// Option is a storage option.
@ -85,3 +89,19 @@ func WithFileAccessMode(m AccessMode) Option {
o.WithFileAccessMode = m
}
}
// WithBuffer sets the buffer size.
// The value must be a factorial of 4KiB.
func WithBuffer(b uint64) Option {
return func(o *Options) {
o.WithBuffer = b
}
}
// WithMinimumBuffer sets the threshold to enforce when the
// buffer expands back to its original size.
func WithMinimumBuffer(m uint64) Option {
return func(o *Options) {
o.WithMinimumBuffer = m
}
}

@ -59,4 +59,24 @@ func Test_getOpts(t *testing.T) {
testOpts.WithCreateFile = true
assert.Equal(opts, testOpts)
})
t.Run("WithBuffer", func(t *testing.T) {
testOpts := getDefaultOptions()
opts := GetOpts(WithBuffer(0))
assert.Equal(testOpts, opts)
testOpts = getDefaultOptions()
opts = GetOpts(WithBuffer(4096))
testOpts.WithBuffer = 4096
assert.Equal(opts, testOpts)
})
t.Run("WithMinimumBuffer", func(t *testing.T) {
testOpts := getDefaultOptions()
opts := GetOpts(WithMinimumBuffer(0))
assert.Equal(testOpts, opts)
testOpts = getDefaultOptions()
opts = GetOpts(WithMinimumBuffer(88))
testOpts.WithMinimumBuffer = 88
assert.Equal(opts, testOpts)
})
}

Loading…
Cancel
Save