From 0559e3a5e96c2ecc9e9246beeae2d0fff2cc4def Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sat, 27 Aug 2022 18:50:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E6=A0=87=E7=BB=9F=E8=AE=A1=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=BA=8B=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/rpc/services/service_metric_stat.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/internal/rpc/services/service_metric_stat.go b/internal/rpc/services/service_metric_stat.go index 2e998a4f..597dfa6d 100644 --- a/internal/rpc/services/service_metric_stat.go +++ b/internal/rpc/services/service_metric_stat.go @@ -27,8 +27,6 @@ func init() { var countKeys = 0 for key := range metricStatKeysQueue { err := func(key string) error { - var tx *dbs.Tx - metricStatsLocker.Lock() req, ok := metricStatsMap[key] if !ok { @@ -45,7 +43,20 @@ func init() { var itemId = types.Int64(pieces[3]) // 删除旧的数据 - err := models.SharedMetricStatDAO.DeleteNodeItemStats(tx, nodeId, serverId, itemId, req.Time) + tx, err := models.SharedMetricStatDAO.Instance.Begin() + if err != nil { + return err + } + + defer func() { + // 失败时不需要rollback + commitErr := tx.Commit() + if commitErr != nil { + remotelogs.Error("METRIC_STAT", "commit metric stats failed: "+commitErr.Error()) + } + }() + + err = models.SharedMetricStatDAO.DeleteNodeItemStats(tx, nodeId, serverId, itemId, req.Time) if err != nil { return err }