From b447cc953ee5ed93e3590f1ee86d4f4df5fe7efc Mon Sep 17 00:00:00 2001 From: liugq Date: Thu, 27 Jul 2023 18:03:33 +0800 Subject: [PATCH] fix calc percent of migration task --- plugin/task_manager/migration_api.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugin/task_manager/migration_api.go b/plugin/task_manager/migration_api.go index 44f7973d..f2898818 100644 --- a/plugin/task_manager/migration_api.go +++ b/plugin/task_manager/migration_api.go @@ -76,11 +76,17 @@ func (h *APIHandler) getDataMigrationTaskInfo(w http.ResponseWriter, req *http.R for i, index := range taskConfig.Indices { indexName := index.Source.GetUniqueIndexName() count := indexState[indexName].IndexDocs - percent := float64(count) / float64(index.Source.Docs) * 100 - if percent > 100 { + sourceDocs := indexState[indexName].SourceDocs + var percent float64 + if sourceDocs <= 0 { percent = 100 + }else{ + percent = float64(count) / float64(sourceDocs) * 100 + if percent > 100 { + percent = 100 + } } - taskConfig.Indices[i].Source.Docs = indexState[indexName].SourceDocs + taskConfig.Indices[i].Source.Docs = sourceDocs taskConfig.Indices[i].Target.Docs = count taskConfig.Indices[i].Percent = util.ToFixed(percent, 2) taskConfig.Indices[i].ErrorPartitions = indexState[indexName].ErrorPartitions