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.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. )
  7. type UpdateCacheEntry struct {
  8. FileHash string
  9. Operation string
  10. }
  11. func NewUpdateCacheEntry(fileHash string, op string) UpdateCacheEntry {
  12. return UpdateCacheEntry{
  13. FileHash: fileHash,
  14. Operation: op,
  15. }
  16. }
  17. type UpdateCache struct {
  18. NodeID int
  19. Entries []UpdateCacheEntry
  20. }
  21. func NewUpdateCache(nodeID int, entries []UpdateCacheEntry) UpdateCache {
  22. return UpdateCache{
  23. NodeID: nodeID,
  24. Entries: entries,
  25. }
  26. }
  27. func (t *UpdateCache) TryMerge(other Event) bool {
  28. event, ok := other.(*UpdateCache)
  29. if !ok {
  30. return false
  31. }
  32. if event.NodeID != t.NodeID {
  33. return false
  34. }
  35. // TODO 可以考虑合并同FileHash和NodeID的记录
  36. t.Entries = append(t.Entries, event.Entries...)
  37. return true
  38. }
  39. func (t *UpdateCache) Execute(execCtx ExecuteContext) {
  40. for _, entry := range t.Entries {
  41. switch entry.Operation {
  42. case evtcst.UPDATE_CACHE_UNTEMP:
  43. err := mysql.Cache.DeleteTemp(execCtx.Args.DB.SQLCtx(), entry.FileHash, t.NodeID)
  44. if err != nil {
  45. logger.WithField("FileHash", entry.FileHash).
  46. WithField("NodeID", t.NodeID).
  47. Warnf("delete temp cache failed, err: %s", err.Error())
  48. }
  49. case evtcst.UPDATE_CACHE_CREATE_TEMP:
  50. err := mysql.Cache.CreateTemp(execCtx.Args.DB.SQLCtx(), entry.FileHash, t.NodeID)
  51. if err != nil {
  52. logger.WithField("FileHash", entry.FileHash).
  53. WithField("NodeID", t.NodeID).
  54. Warnf("create temp cache failed, err: %s", err.Error())
  55. }
  56. }
  57. }
  58. }

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