2022-04-22 13:30:20 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-09-07 09:11:06 +00:00
|
|
|
"errors"
|
2022-12-10 10:59:18 +00:00
|
|
|
"time"
|
2022-04-22 13:30:20 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
treeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/tree"
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
|
|
containerClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
|
|
|
containerEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2022-09-07 09:11:06 +00:00
|
|
|
"go.uber.org/zap"
|
2022-04-22 13:30:20 +00:00
|
|
|
)
|
|
|
|
|
2022-10-18 21:33:45 +00:00
|
|
|
type cnrSource struct {
|
|
|
|
// cache of raw client.
|
|
|
|
src container.Source
|
|
|
|
// raw client; no need to cache request results
|
|
|
|
// since sync is performed once in epoch and is
|
|
|
|
// expected to receive different results every
|
|
|
|
// call.
|
|
|
|
cli *containerClient.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c cnrSource) Get(id cid.ID) (*container.Container, error) {
|
|
|
|
return c.src.Get(id)
|
|
|
|
}
|
|
|
|
|
2023-08-18 14:20:30 +00:00
|
|
|
func (c cnrSource) DeletionInfo(cid cid.ID) (*container.DelInfo, error) {
|
2023-08-24 12:27:24 +00:00
|
|
|
return c.src.DeletionInfo(cid)
|
2023-08-18 14:20:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 21:33:45 +00:00
|
|
|
func (c cnrSource) List() ([]cid.ID, error) {
|
2023-03-24 08:57:35 +00:00
|
|
|
return c.cli.ContainersOf(nil)
|
2022-10-18 21:33:45 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 13:30:20 +00:00
|
|
|
func initTreeService(c *cfg) {
|
2022-07-26 09:48:55 +00:00
|
|
|
treeConfig := treeconfig.Tree(c.appCfg)
|
|
|
|
if !treeConfig.Enabled() {
|
2023-04-12 14:35:10 +00:00
|
|
|
c.log.Info(logs.FrostFSNodeTreeServiceIsNotEnabledSkipInitialization)
|
2022-07-18 10:16:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-16 16:31:50 +00:00
|
|
|
c.treeService = tree.New(
|
2022-10-18 21:33:45 +00:00
|
|
|
tree.WithContainerSource(cnrSource{
|
|
|
|
src: c.cfgObject.cnrSource,
|
|
|
|
cli: c.shared.cnrClient,
|
|
|
|
}),
|
2022-09-08 12:44:27 +00:00
|
|
|
tree.WithEACLSource(c.cfgObject.eaclSource),
|
2022-04-22 13:30:20 +00:00
|
|
|
tree.WithNetmapSource(c.netMapSource),
|
|
|
|
tree.WithPrivateKey(&c.key.PrivateKey),
|
|
|
|
tree.WithLogger(c.log),
|
2022-07-19 08:03:13 +00:00
|
|
|
tree.WithStorage(c.cfgObject.cfgLocalStorage.localStorage),
|
2022-07-26 09:48:55 +00:00
|
|
|
tree.WithContainerCacheSize(treeConfig.CacheSize()),
|
2022-12-14 16:28:44 +00:00
|
|
|
tree.WithReplicationTimeout(treeConfig.ReplicationTimeout()),
|
2022-07-26 09:48:55 +00:00
|
|
|
tree.WithReplicationChannelCapacity(treeConfig.ReplicationChannelCapacity()),
|
2023-05-24 07:01:50 +00:00
|
|
|
tree.WithReplicationWorkerCount(treeConfig.ReplicationWorkerCount()),
|
2023-06-23 08:25:08 +00:00
|
|
|
tree.WithAuthorizedKeys(treeConfig.AuthorizedKeys()),
|
2023-05-24 07:01:50 +00:00
|
|
|
tree.WithMetrics(c.metricsCollector.TreeService()))
|
2022-04-22 13:30:20 +00:00
|
|
|
|
2022-05-06 11:58:36 +00:00
|
|
|
for _, srv := range c.cfgGRPC.servers {
|
2022-05-16 16:31:50 +00:00
|
|
|
tree.RegisterTreeServiceServer(srv, c.treeService)
|
2022-05-06 11:58:36 +00:00
|
|
|
}
|
2022-04-22 13:30:20 +00:00
|
|
|
|
|
|
|
c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
|
2022-05-16 16:31:50 +00:00
|
|
|
c.treeService.Start(ctx)
|
2022-04-22 13:30:20 +00:00
|
|
|
}))
|
2022-05-06 11:58:36 +00:00
|
|
|
|
2022-12-10 10:59:18 +00:00
|
|
|
if d := treeConfig.SyncInterval(); d == 0 {
|
|
|
|
addNewEpochNotificationHandler(c, func(_ event.Event) {
|
|
|
|
err := c.treeService.SynchronizeAll()
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
c.log.Error(logs.FrostFSNodeCouldNotSynchronizeTreeService, zap.Error(err))
|
2022-12-10 10:59:18 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
go func() {
|
|
|
|
tick := time.NewTicker(d)
|
|
|
|
defer tick.Stop()
|
|
|
|
|
|
|
|
for range tick.C {
|
|
|
|
err := c.treeService.SynchronizeAll()
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
c.log.Error(logs.FrostFSNodeCouldNotSynchronizeTreeService, zap.Error(err))
|
2022-12-10 10:59:18 +00:00
|
|
|
if errors.Is(err, tree.ErrShuttingDown) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2022-10-06 20:18:46 +00:00
|
|
|
|
2022-09-07 09:11:06 +00:00
|
|
|
subscribeToContainerRemoval(c, func(e event.Event) {
|
|
|
|
ev := e.(containerEvent.DeleteSuccess)
|
|
|
|
|
|
|
|
// This is executed asynchronously, so we don't care about the operation taking some time.
|
2023-04-12 14:35:10 +00:00
|
|
|
c.log.Debug(logs.FrostFSNodeRemovingAllTreesForContainer, zap.Stringer("cid", ev.ID))
|
2022-09-07 09:11:06 +00:00
|
|
|
err := c.treeService.DropTree(context.Background(), ev.ID, "")
|
|
|
|
if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) {
|
|
|
|
// Ignore pilorama.ErrTreeNotFound but other errors, including shard.ErrReadOnly, should be logged.
|
2023-04-12 14:35:10 +00:00
|
|
|
c.log.Error(logs.FrostFSNodeContainerRemovalEventReceivedButTreesWerentRemoved,
|
2022-09-07 09:11:06 +00:00
|
|
|
zap.Stringer("cid", ev.ID),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-05-16 16:31:50 +00:00
|
|
|
c.onShutdown(c.treeService.Shutdown)
|
2022-04-22 13:30:20 +00:00
|
|
|
}
|