Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions api/v1alpha1/dataset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,24 @@ func (dataset *Dataset) RemoveDataOperationInProgress(operationType, name string
dataset.Status.OperationRef[operationType] = strings.Join(dataOpKeys, ",")
return dataset.Status.OperationRef[operationType]
}

// CanStartDataOperation checks if the data operation can be started on this dataset.
func (dataset *Dataset) CanStartDataOperation(operationType string, maxParallel int32, name string) bool {
if dataset.Status.OperationRef == nil {
return true
}

opRef, ok := dataset.Status.OperationRef[operationType]
if !ok || opRef == "" {
return true
}

opRefs := strings.Split(opRef, ",")
for _, op := range opRefs {
if op == name {
return true // Already in progress
}
}

return int32(len(opRefs)) < maxParallel
}
104 changes: 104 additions & 0 deletions api/v1alpha1/dataset_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,107 @@
})
}
}

func TestDataset_CanStartDataOperation(t *testing.T) {

Check warning on line 189 in api/v1alpha1/dataset_types_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "TestDataset_CanStartDataOperation" to match the regular expression ^(_|[a-zA-Z0-9]+)$

See more on https://sonarcloud.io/project/issues?id=fluid-cloudnative_fluid&issues=AZ1IObHY3XtLmXaftuWA&open=AZ1IObHY3XtLmXaftuWA&pullRequest=5754
type fields struct {
Status DatasetStatus
}
type args struct {
operationType string
maxParallel int32
name string
}
tests := []struct {
name string
fields fields
args args
want bool
}{
{
name: "empty_status",
fields: fields{
Status: DatasetStatus{},
},
args: args{
operationType: "DataLoad",
maxParallel: 1,
name: "load-1",

Check failure on line 212 in api/v1alpha1/dataset_types_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "load-1" 5 times.

See more on https://sonarcloud.io/project/issues?id=fluid-cloudnative_fluid&issues=AZ1IObHY3XtLmXaftuV_&open=AZ1IObHY3XtLmXaftuV_&pullRequest=5754
},
want: true,
},
{
name: "already_in_progress_reentrant",
fields: fields{
Status: DatasetStatus{
OperationRef: map[string]string{
"DataLoad": "load-1",
},
},
},
args: args{
operationType: "DataLoad",
maxParallel: 1,
name: "load-1",
},
want: true,
},
{
name: "blocked_by_max_parallel_1",
fields: fields{
Status: DatasetStatus{
OperationRef: map[string]string{
"DataLoad": "load-1",
},
},
},
args: args{
operationType: "DataLoad",
maxParallel: 1,
name: "load-2",
},
want: false,
},
{
name: "allowed_by_max_parallel_2",
fields: fields{
Status: DatasetStatus{
OperationRef: map[string]string{
"DataLoad": "load-1",
},
},
},
args: args{
operationType: "DataLoad",
maxParallel: 2,
name: "load-2",
},
want: true,
},
{
name: "blocked_by_max_parallel_2",
fields: fields{
Status: DatasetStatus{
OperationRef: map[string]string{
"DataLoad": "load-1,load-2",
},
},
},
args: args{
operationType: "DataLoad",
maxParallel: 2,
name: "load-3",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dataset := &Dataset{
Status: tt.fields.Status,
}
if got := dataset.CanStartDataOperation(tt.args.operationType, tt.args.maxParallel, tt.args.name); got != tt.want {
t.Errorf("CanStartDataOperation() = %v, want %v", got, tt.want)
}
})
}
}
5 changes: 5 additions & 0 deletions pkg/ddc/base/operation_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ func SetDataOperationInTargetDataset(ctx cruntime.ReconcileRequestContext, opera
return err
}

if !dataset.CanStartDataOperation(operationTypeName, operation.GetParallelTaskNumber(), dataOpKey) {
return fmt.Errorf("the dataset %s has reached the maximum number of parallel %s operations (limit: %d), please wait", targetDataset.Name, operationTypeName, operation.GetParallelTaskNumber())
}

// set current data operation in the target dataset
datasetToUpdate := dataset.DeepCopy()
Comment on lines +76 to 78
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lock limit is derived from operation.GetParallelTaskNumber(). For DataMigrate this returns Spec.Parallelism (parallel workers within a single DataMigrate), so a DataMigrate with Parallelism>1 would allow multiple concurrent DataMigrate CRs on the same Dataset, contradicting the PR description that DataMigrate is limited to 1. Consider separating “max concurrent operations per dataset” from “intra-operation parallelism” (e.g., a dedicated interface method or a hard-coded 1 for DataMigrate).

Copilot uses AI. Check for mistakes.
Comment on lines +76 to 78
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a plain fmt.Errorf here causes SetDataOperationInTargetDataset to log at error level on every retry (and the reconciler requeues periodically), even though lock contention is an expected state when parallelism is exceeded. Consider using a typed/sentinel error so callers can log at Info/Debug and/or emit a clearer event, and include the dataset namespace/current OperationRef in the message to help users diagnose what is blocking.

Copilot uses AI. Check for mistakes.

datasetToUpdate.SetDataOperationInProgress(operationTypeName, dataOpKey)
// different operation may set other fields
operation.SetTargetDatasetStatusInProgress(datasetToUpdate)
Expand Down
Loading