mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-30 03:50:25 +08:00
指标统计使用事务
This commit is contained in:
@@ -27,8 +27,6 @@ func init() {
|
|||||||
var countKeys = 0
|
var countKeys = 0
|
||||||
for key := range metricStatKeysQueue {
|
for key := range metricStatKeysQueue {
|
||||||
err := func(key string) error {
|
err := func(key string) error {
|
||||||
var tx *dbs.Tx
|
|
||||||
|
|
||||||
metricStatsLocker.Lock()
|
metricStatsLocker.Lock()
|
||||||
req, ok := metricStatsMap[key]
|
req, ok := metricStatsMap[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -45,7 +43,20 @@ func init() {
|
|||||||
var itemId = types.Int64(pieces[3])
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user