| @@ -6,7 +6,6 @@ import ( | |||||
| "github.com/samber/lo" | "github.com/samber/lo" | ||||
| "gitlink.org.cn/cloudream/common/pkg/logger" | "gitlink.org.cn/cloudream/common/pkg/logger" | ||||
| "gitlink.org.cn/cloudream/db/model" | "gitlink.org.cn/cloudream/db/model" | ||||
| mysql "gitlink.org.cn/cloudream/db/sql" | |||||
| "gitlink.org.cn/cloudream/scanner/internal/config" | "gitlink.org.cn/cloudream/scanner/internal/config" | ||||
| agtcli "gitlink.org.cn/cloudream/rabbitmq/client/agent" | agtcli "gitlink.org.cn/cloudream/rabbitmq/client/agent" | ||||
| @@ -57,7 +56,7 @@ func (t *AgentCheckCache) Execute(execCtx ExecuteContext) { | |||||
| if t.FileHashes == nil { | if t.FileHashes == nil { | ||||
| var err error | var err error | ||||
| caches, err = mysql.Cache.GetNodeCaches(execCtx.Args.DB.SQLCtx(), t.NodeID) | |||||
| caches, err = execCtx.Args.DB.Cache().GetNodeCaches(execCtx.Args.DB.SQLCtx(), t.NodeID) | |||||
| if err != nil { | if err != nil { | ||||
| log.WithField("NodeID", t.NodeID).Warnf("get node caches failed, err: %s", err.Error()) | log.WithField("NodeID", t.NodeID).Warnf("get node caches failed, err: %s", err.Error()) | ||||
| return | return | ||||
| @@ -66,7 +65,7 @@ func (t *AgentCheckCache) Execute(execCtx ExecuteContext) { | |||||
| } else { | } else { | ||||
| for _, hash := range t.FileHashes { | for _, hash := range t.FileHashes { | ||||
| ch, err := mysql.Cache.Get(execCtx.Args.DB.SQLCtx(), hash, t.NodeID) | |||||
| ch, err := execCtx.Args.DB.Cache().Get(execCtx.Args.DB.SQLCtx(), hash, t.NodeID) | |||||
| // 记录不存在则跳过 | // 记录不存在则跳过 | ||||
| if err == sql.ErrNoRows { | if err == sql.ErrNoRows { | ||||
| continue | continue | ||||
| @@ -61,7 +61,7 @@ func (t *AgentCheckState) Execute(execCtx ExecuteContext) { | |||||
| return | return | ||||
| } | } | ||||
| caches, err := mysql.Cache.GetNodeCaches(execCtx.Args.DB.SQLCtx(), t.NodeID) | |||||
| caches, err := execCtx.Args.DB.Cache().GetNodeCaches(execCtx.Args.DB.SQLCtx(), t.NodeID) | |||||
| if err != nil { | if err != nil { | ||||
| log.WithField("NodeID", t.NodeID).Warnf("get node caches failed, err: %s", err.Error()) | log.WithField("NodeID", t.NodeID).Warnf("get node caches failed, err: %s", err.Error()) | ||||
| return | return | ||||
| @@ -52,12 +52,12 @@ func (t *CheckCache) Execute(execCtx ExecuteContext) { | |||||
| return nil | return nil | ||||
| } | } | ||||
| caches, err := mysql.Cache.GetNodeCaches(tx, t.NodeID) | |||||
| caches, err := execCtx.Args.DB.Cache().GetNodeCaches(tx, t.NodeID) | |||||
| if err != nil { | if err != nil { | ||||
| return fmt.Errorf("get node caches failed, err: %w", err) | return fmt.Errorf("get node caches failed, err: %w", err) | ||||
| } | } | ||||
| err = mysql.Cache.DeleteNodeAll(tx, t.NodeID) | |||||
| err = execCtx.Args.DB.Cache().DeleteNodeAll(tx, t.NodeID) | |||||
| if err != nil { | if err != nil { | ||||
| return fmt.Errorf("delete node all caches failed, err: %w", err) | return fmt.Errorf("delete node all caches failed, err: %w", err) | ||||
| } | } | ||||
| @@ -81,9 +81,9 @@ func (t *CheckRepCount) checkOneRepCount(fileHash string, execCtx ExecuteContext | |||||
| // 计算所需的最少备份数: | // 计算所需的最少备份数: | ||||
| // ObjectRep中期望备份数的最大值 | // ObjectRep中期望备份数的最大值 | ||||
| // 如果ObjectBlock存在对此文件的引用,则至少为1 | // 如果ObjectBlock存在对此文件的引用,则至少为1 | ||||
| needRepCount := mymath.Max(repMaxCnt, mymath.Max(1, blkCnt)) | |||||
| needRepCount := mymath.Max(repMaxCnt, mymath.Min(1, blkCnt)) | |||||
| repNodes, err := mysql.Cache.GetCachingFileNodes(tx, fileHash) | |||||
| repNodes, err := execCtx.Args.DB.Cache().GetCachingFileNodes(tx, fileHash) | |||||
| if err != nil { | if err != nil { | ||||
| return fmt.Errorf("get caching file nodes failed, err: %w", err) | return fmt.Errorf("get caching file nodes failed, err: %w", err) | ||||
| } | } | ||||
| @@ -106,7 +106,7 @@ func (t *CheckRepCount) checkOneRepCount(fileHash string, execCtx ExecuteContext | |||||
| if len(normalNodes) > needRepCount { | if len(normalNodes) > needRepCount { | ||||
| delNodes := chooseDeleteAvaiRepNodes(allNodes, normalNodes, len(normalNodes)-needRepCount) | delNodes := chooseDeleteAvaiRepNodes(allNodes, normalNodes, len(normalNodes)-needRepCount) | ||||
| for _, node := range delNodes { | for _, node := range delNodes { | ||||
| err := mysql.Cache.ChangeState(tx, fileHash, node.NodeID, consts.CACHE_STATE_TEMP) | |||||
| err := execCtx.Args.DB.Cache().SetTemp(tx, fileHash, node.NodeID) | |||||
| if err != nil { | if err != nil { | ||||
| return fmt.Errorf("change cache state failed, err: %w", err) | return fmt.Errorf("change cache state failed, err: %w", err) | ||||
| } | } | ||||
| @@ -134,7 +134,7 @@ func (t *CheckRepCount) checkOneRepCount(fileHash string, execCtx ExecuteContext | |||||
| } | } | ||||
| for _, node := range newNodes { | for _, node := range newNodes { | ||||
| err := mysql.Cache.CreatePinned(tx, fileHash, node.NodeID) | |||||
| err := execCtx.Args.DB.Cache().CreatePinned(tx, fileHash, node.NodeID) | |||||
| if err != nil { | if err != nil { | ||||
| return fmt.Errorf("create cache failed, err: %w", err) | return fmt.Errorf("create cache failed, err: %w", err) | ||||
| } | } | ||||
| @@ -3,7 +3,6 @@ package event | |||||
| import ( | import ( | ||||
| evtcst "gitlink.org.cn/cloudream/common/consts/event" | evtcst "gitlink.org.cn/cloudream/common/consts/event" | ||||
| "gitlink.org.cn/cloudream/common/pkg/logger" | "gitlink.org.cn/cloudream/common/pkg/logger" | ||||
| mysql "gitlink.org.cn/cloudream/db/sql" | |||||
| scevt "gitlink.org.cn/cloudream/rabbitmq/message/scanner/event" | scevt "gitlink.org.cn/cloudream/rabbitmq/message/scanner/event" | ||||
| ) | ) | ||||
| @@ -40,7 +39,7 @@ func (t *UpdateCache) Execute(execCtx ExecuteContext) { | |||||
| for _, entry := range t.Entries { | for _, entry := range t.Entries { | ||||
| switch entry.Operation { | switch entry.Operation { | ||||
| case evtcst.UPDATE_CACHE_DELETE_TEMP: | case evtcst.UPDATE_CACHE_DELETE_TEMP: | ||||
| err := mysql.Cache.DeleteTemp(execCtx.Args.DB.SQLCtx(), entry.FileHash, t.NodeID) | |||||
| err := execCtx.Args.DB.Cache().DeleteTemp(execCtx.Args.DB.SQLCtx(), entry.FileHash, t.NodeID) | |||||
| if err != nil { | if err != nil { | ||||
| log.WithField("FileHash", entry.FileHash). | log.WithField("FileHash", entry.FileHash). | ||||
| WithField("NodeID", t.NodeID). | WithField("NodeID", t.NodeID). | ||||
| @@ -52,7 +51,7 @@ func (t *UpdateCache) Execute(execCtx ExecuteContext) { | |||||
| Debugf("delete temp cache") | Debugf("delete temp cache") | ||||
| case evtcst.UPDATE_CACHE_CREATE_TEMP: | case evtcst.UPDATE_CACHE_CREATE_TEMP: | ||||
| err := mysql.Cache.CreateTemp(execCtx.Args.DB.SQLCtx(), entry.FileHash, t.NodeID) | |||||
| err := execCtx.Args.DB.Cache().CreateTemp(execCtx.Args.DB.SQLCtx(), entry.FileHash, t.NodeID) | |||||
| if err != nil { | if err != nil { | ||||
| log.WithField("FileHash", entry.FileHash). | log.WithField("FileHash", entry.FileHash). | ||||
| WithField("NodeID", t.NodeID). | WithField("NodeID", t.NodeID). | ||||
| @@ -2,7 +2,6 @@ package tickevent | |||||
| import ( | import ( | ||||
| "gitlink.org.cn/cloudream/common/pkg/logger" | "gitlink.org.cn/cloudream/common/pkg/logger" | ||||
| mysql "gitlink.org.cn/cloudream/db/sql" | |||||
| "gitlink.org.cn/cloudream/scanner/internal/event" | "gitlink.org.cn/cloudream/scanner/internal/event" | ||||
| ) | ) | ||||
| @@ -20,7 +19,7 @@ func (e *BatchCheckAllRepCount) Execute(ctx ExecuteContext) { | |||||
| log := logger.WithType[BatchCheckAllRepCount]("TickEvent") | log := logger.WithType[BatchCheckAllRepCount]("TickEvent") | ||||
| log.Debugf("begin") | log.Debugf("begin") | ||||
| fileHashes, err := mysql.Cache.BatchGetAllFileHashes(ctx.Args.DB.SQLCtx(), e.lastCheckStart, CHECK_CACHE_BATCH_SIZE) | |||||
| fileHashes, err := ctx.Args.DB.Cache().BatchGetAllFileHashes(ctx.Args.DB.SQLCtx(), e.lastCheckStart, CHECK_CACHE_BATCH_SIZE) | |||||
| if err != nil { | if err != nil { | ||||
| log.Warnf("batch get file hashes failed, err: %s", err.Error()) | log.Warnf("batch get file hashes failed, err: %s", err.Error()) | ||||
| return | return | ||||