forked from TrueCloudLab/frostfs-node
[#2165] services/tree: Allow to set custom synchronization interval
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
6a4e5e6f0a
commit
d3054e577a
6 changed files with 37 additions and 7 deletions
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
treeconfig "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/tree"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/core/container"
|
||||
|
@ -63,12 +64,29 @@ func initTreeService(c *cfg) {
|
|||
c.treeService.Start(ctx)
|
||||
}))
|
||||
|
||||
addNewEpochNotificationHandler(c, func(_ event.Event) {
|
||||
err := c.treeService.SynchronizeAll()
|
||||
if err != nil {
|
||||
c.log.Error("could not synchronize Tree Service", zap.Error(err))
|
||||
}
|
||||
})
|
||||
if d := treeConfig.SyncInterval(); d == 0 {
|
||||
addNewEpochNotificationHandler(c, func(_ event.Event) {
|
||||
err := c.treeService.SynchronizeAll()
|
||||
if err != nil {
|
||||
c.log.Error("could not synchronize Tree Service", zap.Error(err))
|
||||
}
|
||||
})
|
||||
} else {
|
||||
go func() {
|
||||
tick := time.NewTicker(d)
|
||||
defer tick.Stop()
|
||||
|
||||
for range tick.C {
|
||||
err := c.treeService.SynchronizeAll()
|
||||
if err != nil {
|
||||
c.log.Error("could not synchronize Tree Service", zap.Error(err))
|
||||
if errors.Is(err, tree.ErrShuttingDown) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
subscribeToContainerRemoval(c, func(e event.Event) {
|
||||
ev := e.(containerEvent.DeleteSuccess)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue