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.

update_cache.go 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package event
  2. import (
  3. evtcst "gitlink.org.cn/cloudream/common/consts/event"
  4. "gitlink.org.cn/cloudream/common/utils/logger"
  5. mysql "gitlink.org.cn/cloudream/db/sql"
  6. scevt "gitlink.org.cn/cloudream/rabbitmq/message/scanner/event"
  7. )
  8. type UpdateCacheEntry = scevt.UpdateCacheEntry
  9. type UpdateCache struct {
  10. scevt.UpdateCache
  11. }
  12. func NewUpdateCache(nodeID int, entries []scevt.UpdateCacheEntry) *UpdateCache {
  13. return &UpdateCache{
  14. UpdateCache: scevt.NewUpdateCache(nodeID, entries),
  15. }
  16. }
  17. func (t *UpdateCache) TryMerge(other Event) bool {
  18. event, ok := other.(*UpdateCache)
  19. if !ok {
  20. return false
  21. }
  22. if event.NodeID != t.NodeID {
  23. return false
  24. }
  25. // TODO 可以考虑合并同FileHash和NodeID的记录
  26. t.Entries = append(t.Entries, event.Entries...)
  27. return true
  28. }
  29. func (t *UpdateCache) Execute(execCtx ExecuteContext) {
  30. logger.Debugf("begin update cache")
  31. for _, entry := range t.Entries {
  32. switch entry.Operation {
  33. case evtcst.UPDATE_CACHE_DELETE_TEMP:
  34. err := mysql.Cache.DeleteTemp(execCtx.Args.DB.SQLCtx(), entry.FileHash, t.NodeID)
  35. if err != nil {
  36. logger.WithField("FileHash", entry.FileHash).
  37. WithField("NodeID", t.NodeID).
  38. Warnf("delete temp cache failed, err: %s", err.Error())
  39. }
  40. logger.WithField("FileHash", entry.FileHash).
  41. WithField("NodeID", t.NodeID).
  42. Debugf("delete temp cache")
  43. case evtcst.UPDATE_CACHE_CREATE_TEMP:
  44. err := mysql.Cache.CreateTemp(execCtx.Args.DB.SQLCtx(), entry.FileHash, t.NodeID)
  45. if err != nil {
  46. logger.WithField("FileHash", entry.FileHash).
  47. WithField("NodeID", t.NodeID).
  48. Warnf("create temp cache failed, err: %s", err.Error())
  49. }
  50. logger.WithField("FileHash", entry.FileHash).
  51. WithField("NodeID", t.NodeID).
  52. Debugf("create temp cache")
  53. }
  54. }
  55. }
  56. func init() {
  57. RegisterMessageConvertor(func(msg scevt.UpdateCache) Event { return NewUpdateCache(msg.NodeID, msg.Entries) })
  58. }

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