backend: Hooks interface & implementation.

This commit is contained in:
Piotr Tabor
2021-04-09 14:18:18 +02:00
parent c46e96d519
commit 9f11b16b2d
3 changed files with 51 additions and 0 deletions

View File

@ -104,6 +104,8 @@ type backend struct {
stopc chan struct{}
donec chan struct{}
hooks Hooks
lg *zap.Logger
}
@ -124,6 +126,9 @@ type BackendConfig struct {
UnsafeNoFsync bool `json:"unsafe-no-fsync"`
// Mlock prevents backend database file to be swapped
Mlock bool
// Hooks are getting executed during lifecycle of Backend's transactions.
Hooks Hooks
}
func DefaultBackendConfig() BackendConfig {
@ -189,6 +194,9 @@ func newBackend(bcfg BackendConfig) *backend {
lg: bcfg.Logger,
}
b.batchTx = newBatchTxBuffered(b)
// We set it after newBatchTxBuffered to skip the 'empty' commit.
b.hooks = bcfg.Hooks
go b.run()
return b
}