You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/10/25 09:40:59 UTC
[incubator-devlake] branch main updated: fix: ReloadBlueprints is not safe (#6331)
This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 2837097d9 fix: ReloadBlueprints is not safe (#6331)
2837097d9 is described below
commit 2837097d98186403890be201ac77b9d458efac9f
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Wed Oct 25 17:40:54 2023 +0800
fix: ReloadBlueprints is not safe (#6331)
---
backend/helpers/dbhelper/txhelper.go | 5 +++--
backend/server/services/blueprint.go | 10 +++++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/backend/helpers/dbhelper/txhelper.go b/backend/helpers/dbhelper/txhelper.go
index a7da084d4..c9101f4ec 100644
--- a/backend/helpers/dbhelper/txhelper.go
+++ b/backend/helpers/dbhelper/txhelper.go
@@ -19,9 +19,10 @@ package dbhelper
import (
"fmt"
- "github.com/apache/incubator-devlake/core/log"
"time"
+ "github.com/apache/incubator-devlake/core/log"
+
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
@@ -46,7 +47,7 @@ func (l *TxHelper[E]) Begin() dal.Transaction {
// LockTablesTimeout locks tables with timeout
func (l *TxHelper[E]) LockTablesTimeout(timeout time.Duration, lockTables dal.LockTables) errors.Error {
- l.logger.Warn(fmt.Errorf("timeout"), "local tables")
+ l.logger.Info("try locking tables with timeout %v", timeout)
c := make(chan errors.Error, 1)
go func() {
c <- l.tx.LockTables(lockTables)
diff --git a/backend/server/services/blueprint.go b/backend/server/services/blueprint.go
index e295e694b..34eef95d9 100644
--- a/backend/server/services/blueprint.go
+++ b/backend/server/services/blueprint.go
@@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"strings"
+ "sync"
"github.com/apache/incubator-devlake/helpers/pluginhelper/services"
@@ -235,8 +236,15 @@ func DeleteBlueprint(id uint64) errors.Error {
return nil
}
+var blueprintReloadLock sync.Mutex
+
// ReloadBlueprints FIXME ...
-func ReloadBlueprints(c *cron.Cron) errors.Error {
+func ReloadBlueprints(c *cron.Cron) (err errors.Error) {
+ // preventing concurrent reloads. It would be better to use Table Lock , however, it requires massive refactor
+ // like the `bpManager` must accept transaction. Use mutex as a temporary fix.
+ blueprintReloadLock.Lock()
+ defer blueprintReloadLock.Unlock()
+
enable := true
isManual := false
blueprints, _, err := bpManager.GetDbBlueprints(&services.GetBlueprintQuery{