You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/07/12 10:22:49 UTC

(incubator-devlake) 01/01: fix(framework): add lock when creating pipeline

This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch dev-1
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit bc029f594ae3537a8b4d5dc0f0a477ded4d24c41
Author: d4x1 <15...@qq.com>
AuthorDate: Fri Jul 12 18:22:37 2024 +0800

    fix(framework): add lock when creating pipeline
---
 backend/server/services/blueprint.go               | 8 ++++----
 backend/server/services/blueprint_makeplan_v200.go | 2 +-
 backend/server/services/pipeline_helper.go         | 7 ++++++-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/backend/server/services/blueprint.go b/backend/server/services/blueprint.go
index 28da22159..cf7d20ccf 100644
--- a/backend/server/services/blueprint.go
+++ b/backend/server/services/blueprint.go
@@ -367,7 +367,7 @@ func MakePlanForBlueprint(blueprint *models.Blueprint, syncPolicy *models.SyncPo
 	if err != nil {
 		return nil, err
 	}
-	return SequencializePipelinePlans(blueprint.BeforePlan, plan, blueprint.AfterPlan), nil
+	return SequentializePipelinePlans(blueprint.BeforePlan, plan, blueprint.AfterPlan), nil
 }
 
 // ParallelizePipelinePlans merges multiple pipelines into one unified plan
@@ -388,9 +388,9 @@ func ParallelizePipelinePlans(plans ...models.PipelinePlan) models.PipelinePlan
 	return merged
 }
 
-// SequencializePipelinePlans merges multiple pipelines into one unified plan
-// by assuming they must be executed in sequencial order
-func SequencializePipelinePlans(plans ...models.PipelinePlan) models.PipelinePlan {
+// SequentializePipelinePlans merges multiple pipelines into one unified plan
+// by assuming they must be executed in sequential order
+func SequentializePipelinePlans(plans ...models.PipelinePlan) models.PipelinePlan {
 	merged := make(models.PipelinePlan, 0)
 	// iterate all pipelineTasks and try to merge them into `merged`
 	for _, plan := range plans {
diff --git a/backend/server/services/blueprint_makeplan_v200.go b/backend/server/services/blueprint_makeplan_v200.go
index 045061e59..bd89d7de3 100644
--- a/backend/server/services/blueprint_makeplan_v200.go
+++ b/backend/server/services/blueprint_makeplan_v200.go
@@ -132,7 +132,7 @@ func GeneratePlanJsonV200(
 			}
 		}
 	}
-	plan := SequencializePipelinePlans(
+	plan := SequentializePipelinePlans(
 		planForProjectMapping,
 		ParallelizePipelinePlans(sourcePlans...),
 		ParallelizePipelinePlans(metricPlans...),
diff --git a/backend/server/services/pipeline_helper.go b/backend/server/services/pipeline_helper.go
index eec6a8c34..899110f5c 100644
--- a/backend/server/services/pipeline_helper.go
+++ b/backend/server/services/pipeline_helper.go
@@ -19,6 +19,7 @@ package services
 
 import (
 	"fmt"
+	"sync"
 	"time"
 
 	"github.com/apache/incubator-devlake/core/dal"
@@ -27,8 +28,12 @@ import (
 	"github.com/apache/incubator-devlake/helpers/dbhelper"
 )
 
+var createDbPipelineLock sync.Mutex
+
 // CreateDbPipeline returns a NewPipeline
 func CreateDbPipeline(newPipeline *models.NewPipeline) (pipeline *models.Pipeline, err errors.Error) {
+	createDbPipelineLock.Lock()
+	defer createDbPipelineLock.Unlock()
 	pipeline = &models.Pipeline{}
 	txHelper := dbhelper.NewTxHelper(basicRes, &err)
 	defer txHelper.End()
@@ -49,7 +54,7 @@ func CreateDbPipeline(newPipeline *models.NewPipeline) (pipeline *models.Pipelin
 			dal.From(&models.Pipeline{}),
 			dal.Where("blueprint_id = ? AND status IN ?", newPipeline.BlueprintId, models.PendingTaskStatus),
 		))
-		// some pipeline is ruunning , get the detail and output them.
+		// some pipeline is running, get the detail and output them.
 		if count > 0 {
 			return nil, errors.BadInput.New("there are pending pipelines of current blueprint already")
 		}