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

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

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