You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

check_cache.go 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package event
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "github.com/jmoiron/sqlx"
  6. "github.com/samber/lo"
  7. "gitlink.org.cn/cloudream/common/consts"
  8. "gitlink.org.cn/cloudream/common/pkg/logger"
  9. "gitlink.org.cn/cloudream/db/model"
  10. scevt "gitlink.org.cn/cloudream/rabbitmq/message/scanner/event"
  11. )
  12. type CheckCache struct {
  13. scevt.CheckCache
  14. }
  15. func NewCheckCache(nodeID int) *CheckCache {
  16. return &CheckCache{
  17. CheckCache: scevt.NewCheckCache(nodeID),
  18. }
  19. }
  20. func (t *CheckCache) TryMerge(other Event) bool {
  21. event, ok := other.(*CheckCache)
  22. if !ok {
  23. return false
  24. }
  25. if event.NodeID != t.NodeID {
  26. return false
  27. }
  28. return true
  29. }
  30. func (t *CheckCache) Execute(execCtx ExecuteContext) {
  31. log := logger.WithType[AgentCheckStorage]("Event")
  32. log.Debugf("begin with %v", logger.FormatStruct(t))
  33. err := execCtx.Args.DB.DoTx(sql.LevelSerializable, func(tx *sqlx.Tx) error {
  34. node, err := execCtx.Args.DB.Node().GetByID(tx, t.NodeID)
  35. if err == sql.ErrNoRows {
  36. return nil
  37. }
  38. if err != nil {
  39. return fmt.Errorf("get node failed, err: %w", err)
  40. }
  41. if node.State != consts.NODE_STATE_UNAVAILABLE {
  42. return nil
  43. }
  44. caches, err := execCtx.Args.DB.Cache().GetNodeCaches(tx, t.NodeID)
  45. if err != nil {
  46. return fmt.Errorf("get node caches failed, err: %w", err)
  47. }
  48. err = execCtx.Args.DB.Cache().DeleteNodeAll(tx, t.NodeID)
  49. if err != nil {
  50. return fmt.Errorf("delete node all caches failed, err: %w", err)
  51. }
  52. execCtx.Executor.Post(NewCheckRepCount(lo.Map(caches, func(ch model.Cache, index int) string { return ch.FileHash })))
  53. return nil
  54. })
  55. if err != nil {
  56. log.WithField("NodeID", t.NodeID).Warn(err.Error())
  57. }
  58. }
  59. func init() {
  60. RegisterMessageConvertor(func(msg scevt.CheckCache) Event { return NewCheckCache(msg.NodeID) })
  61. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。