Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: waiting cause for parallel_tasks_per_rollout (#16001)

Danny Xufa3d0c629545
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.go
index e5ae9100a7..a2010c620e 100644
--- a/backend/api/v1/rollout_service_converter.go
+++ b/backend/api/v1/rollout_service_converter.go
@@ -587,6 +587,12 @@ func convertToSchedulerInfoWaitingCause(ctx context.Context, s *store.Store, c *
},
},
}, nil
+ case *storepb.SchedulerInfo_WaitingCause_ParallelTasksLimit:
+ return &v1pb.TaskRun_SchedulerInfo_WaitingCause{
+ Cause: &v1pb.TaskRun_SchedulerInfo_WaitingCause_ParallelTasksLimit{
+ ParallelTasksLimit: cause.ParallelTasksLimit,
+ },
+ }, nil
default:
return nil, nil
}
diff --git a/backend/component/state/state.go b/backend/component/state/state.go
index df8a6ec3a8..483649e12a 100644
--- a/backend/component/state/state.go
+++ b/backend/component/state/state.go
@@ -39,7 +39,9 @@ type State struct {
// RunningPlanCheckRunsCancelFunc is the cancelFunc of running plan checks.
RunningPlanCheckRunsCancelFunc sync.Map // map[planCheckRunUID]context.CancelFunc
// InstanceOutstandingConnections is the maximum number of connections per instance.
- InstanceOutstandingConnections *connectionLimiter
+ InstanceOutstandingConnections *resourceLimiter
+ // RolloutOutstandingTasks is the maximum number of tasks per rollout.
+ RolloutOutstandingTasks *resourceLimiter
// IssueExternalApprovalRelayCancelChan cancels the external approval from relay for issue issueUID.
IssueExternalApprovalRelayCancelChan chan int
@@ -61,7 +63,8 @@ func New() (*State, error) {
return nil, errors.Wrapf(err, "failed to create auth expire cache")
}
return &State{
- InstanceOutstandingConnections: &connectionLimiter{connections: map[string]int{}},
+ InstanceOutstandingConnections: &resourceLimiter{connections: map[string]int{}},
+ RolloutOutstandingTasks: &resourceLimiter{connections: map[string]int{}},
IssueExternalApprovalRelayCancelChan: make(chan int, 1),
TaskSkippedOrDoneChan: make(chan int, 1000),
PlanCheckTickleChan: make(chan int, 1000),
@@ -70,12 +73,12 @@ func New() (*State, error) {
}, nil
}
-type connectionLimiter struct {
+type resourceLimiter struct {
sync.Mutex
connections map[string]int
}
-func (c *connectionLimiter) Increment(instanceID string, maxConnections int) bool {
+func (c *resourceLimiter) Increment(instanceID string, maxConnections int) bool {
c.Lock()
defer c.Unlock()
if maxConnections == 0 {
@@ -89,7 +92,7 @@ func (c *connectionLimiter) Increment(instanceID string, maxConnections int) boo
return false
}
-func (c *connectionLimiter) Decrement(instanceID string) {
+func (c *resourceLimiter) Decrement(instanceID string) {
c.Lock()
defer c.Unlock()
c.connections[instanceID]--
diff --git a/frontend/src/types/proto/v1/rollout_service.ts b/frontend/src/types/proto/v1/rollout_service.ts
index 5d4ce1fae7..d78e870faa 100644
--- a/frontend/src/types/proto/v1/rollout_service.ts
+++ b/frontend/src/types/proto/v1/rollout_service.ts
@@ -699,6 +699,7 @@ export interface TaskRun_SchedulerInfo {
export interface TaskRun_SchedulerInfo_WaitingCause {
connectionLimit?: boolean | undefined;
task?: TaskRun_SchedulerInfo_WaitingCause_Task | undefined;
+ parallelTasksLimit?: boolean | undefined;
}
export interface TaskRun_SchedulerInfo_WaitingCause_Task {
@@ -3777,7 +3778,7 @@ export const TaskRun_SchedulerInfo: MessageFns<TaskRun_SchedulerInfo> = {
};
function createBaseTaskRun_SchedulerInfo_WaitingCause(): TaskRun_SchedulerInfo_WaitingCause {
- return { connectionLimit: undefined, task: undefined };
+ return { connectionLimit: undefined, task: undefined, parallelTasksLimit: undefined };
}
export const TaskRun_SchedulerInfo_WaitingCause: MessageFns<TaskRun_SchedulerInfo_WaitingCause> = {
@@ -3788,6 +3789,9 @@ export const TaskRun_SchedulerInfo_WaitingCause: MessageFns<TaskRun_SchedulerInf
if (message.task !== undefined) {
TaskRun_SchedulerInfo_WaitingCause_Task.encode(message.task, writer.uint32(18).fork()).join();
}
+ if (message.parallelTasksLimit !== undefined) {
+ writer.uint32(24).bool(message.parallelTasksLimit);
+ }
return writer;
},
@@ -3814,6 +3818,14 @@ export const TaskRun_SchedulerInfo_WaitingCause: MessageFns<TaskRun_SchedulerInf
message.task = TaskRun_SchedulerInfo_WaitingCause_Task.decode(reader, reader.uint32());
continue;
}
+ case 3: {
+ if (tag !== 24) {
+ break;
+ }
+
+ message.parallelTasksLimit = reader.bool();
+ continue;
+ }
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -3827,6 +3839,7 @@ export const TaskRun_SchedulerInfo_WaitingCause: MessageFns<TaskRun_SchedulerInf
return {
connectionLimit: isSet(object.connectionLimit) ? globalThis.Boolean(object.connectionLimit) : undefined,
task: isSet(object.task) ? TaskRun_SchedulerInfo_WaitingCause_Task.fromJSON(object.task) : undefined,
+ parallelTasksLimit: isSet(object.parallelTasksLimit) ? globalThis.Boolean(object.parallelTasksLimit) : undefined,
};
},
@@ -3838,6 +3851,9 @@ export const TaskRun_SchedulerInfo_WaitingCause: MessageFns<TaskRun_SchedulerInf
if (message.task !== undefined) {
obj.task = TaskRun_SchedulerInfo_WaitingCause_Task.toJSON(message.task);
}
+ if (message.parallelTasksLimit !== undefined) {
+ obj.parallelTasksLimit = message.parallelTasksLimit;
+ }
return obj;
},
@@ -3850,6 +3866,7 @@ export const TaskRun_SchedulerInfo_WaitingCause: MessageFns<TaskRun_SchedulerInf
message.task = (object.task !== undefined && object.task !== null)
? TaskRun_SchedulerInfo_WaitingCause_Task.fromPartial(object.task)
: undefined;
+ message.parallelTasksLimit = object.parallelTasksLimit ?? undefined;
return message;
},
};
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index c7da321d17..be05d7a913 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -12366,6 +12366,8 @@ components:
taskUid:
type: integer
format: int32
+ parallelTasksLimit:
+ type: boolean
SchemaCatalog:
type: object
properties:
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index ff8502f651..bc42e929ca 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -4770,6 +4770,7 @@ We support three types of SMTP encryption: NONE, STARTTLS, and SSL/TLS.
| ----- | ---- | ----- | ----------- |
| connection_limit | [bool](#bool) | | |
| task_uid | [int32](#int32) | | |
+| parallel_tasks_limit | [bool](#bool) | | |
diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.html
index 7067f1f268..027ca8f86e 100644
--- a/proto/gen/grpc-doc/store/index.html
+++ b/proto/gen/grpc-doc/store/index.html
@@ -12231,6 +12231,13 @@ Format: instances/{instance}/databases/{database} </p></td>
<td><p> </p></td>
</tr>
+ <tr>
+ <td>parallel_tasks_limit</td>
+ <td><a href="#bool">bool</a></td>
+ <td></td>
+ <td><p> </p></td>
+ </tr>
+
</tbody>
</table>
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index b9b31aac95..50bb511ffa 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -10340,6 +10340,7 @@ When paginating, all other parameters provided to `ListTaskRuns` must match the
| ----- | ---- | ----- | ----------- |
| connection_limit | [bool](#bool) | | |
| task | [TaskRun.SchedulerInfo.WaitingCause.Task](#bytebase-v1-TaskRun-SchedulerInfo-WaitingCause-Task) | | |
+| parallel_tasks_limit | [bool](#bool) | | |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index cc95dde0d2..0d61b1a2be 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -28419,6 +28419,13 @@ Format: instances/{instance}/databases/{database} </p></td>
<td><p> </p></td>
</tr>
+ <tr>
+ <td>parallel_tasks_limit</td>
+ <td><a href="#bool">bool</a></td>
+ <td></td>
+ <td><p> </p></td>
+ </tr>
+
</tbody>
</table>
diff --git a/proto/generated-go/store/task_run.pb.go b/proto/generated-go/store/task_run.pb.go
index a7244601b2..e45be9e022 100644
--- a/proto/generated-go/store/task_run.pb.go
+++ b/proto/generated-go/store/task_run.pb.go
@@ -352,6 +352,7 @@ type SchedulerInfo_WaitingCause struct {
//
// *SchedulerInfo_WaitingCause_ConnectionLimit
// *SchedulerInfo_WaitingCause_TaskUid
+ // *SchedulerInfo_WaitingCause_ParallelTasksLimit
Cause isSchedulerInfo_WaitingCause_Cause `protobuf_oneof:"cause"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -412,6 +413,15 @@ func (x *SchedulerInfo_WaitingCause) GetTaskUid() int32 {
return 0
}
+func (x *SchedulerInfo_WaitingCause) GetParallelTasksLimit() bool {
+ if x != nil {
+ if x, ok := x.Cause.(*SchedulerInfo_WaitingCause_ParallelTasksLimit); ok {
+ return x.ParallelTasksLimit
+ }
+ }
+ return false
+}
+
type isSchedulerInfo_WaitingCause_Cause interface {
isSchedulerInfo_WaitingCause_Cause()
}
@@ -424,10 +434,16 @@ type SchedulerInfo_WaitingCause_TaskUid struct {
TaskUid int32 `protobuf:"varint,2,opt,name=task_uid,json=taskUid,proto3,oneof"`
}
+type SchedulerInfo_WaitingCause_ParallelTasksLimit struct {
+ ParallelTasksLimit bool `protobuf:"varint,3,opt,name=parallel_tasks_limit,json=parallelTasksLimit,proto3,oneof"`
+}
+
func (*SchedulerInfo_WaitingCause_ConnectionLimit) isSchedulerInfo_WaitingCause_Cause() {}
func (*SchedulerInfo_WaitingCause_TaskUid) isSchedulerInfo_WaitingCause_Cause() {}
+func (*SchedulerInfo_WaitingCause_ParallelTasksLimit) isSchedulerInfo_WaitingCause_Cause() {}
+
var File_store_task_run_proto protoreflect.FileDescriptor
const file_store_task_run_proto_rawDesc = "" +
@@ -451,14 +467,15 @@ const file_store_task_run_proto_rawDesc = "" +
"\x05Table\x12\x1a\n" +
"\bdatabase\x18\x01 \x01(\tR\bdatabase\x12\x16\n" +
"\x06schema\x18\x02 \x01(\tR\x06schema\x12\x14\n" +
- "\x05table\x18\x03 \x01(\tR\x05table\"\x80\x02\n" +
+ "\x05table\x18\x03 \x01(\tR\x05table\"\xb5\x02\n" +
"\rSchedulerInfo\x12;\n" +
"\vreport_time\x18\x01 \x01(\v2\x1a.google.protobuf.TimestampR\n" +
"reportTime\x12O\n" +
- "\rwaiting_cause\x18\x02 \x01(\v2*.bytebase.store.SchedulerInfo.WaitingCauseR\fwaitingCause\x1aa\n" +
+ "\rwaiting_cause\x18\x02 \x01(\v2*.bytebase.store.SchedulerInfo.WaitingCauseR\fwaitingCause\x1a\x95\x01\n" +
"\fWaitingCause\x12+\n" +
"\x10connection_limit\x18\x01 \x01(\bH\x00R\x0fconnectionLimit\x12\x1b\n" +
- "\btask_uid\x18\x02 \x01(\x05H\x00R\ataskUidB\a\n" +
+ "\btask_uid\x18\x02 \x01(\x05H\x00R\ataskUid\x122\n" +
+ "\x14parallel_tasks_limit\x18\x03 \x01(\bH\x00R\x12parallelTasksLimitB\a\n" +
"\x05causeB\x14Z\x12generated-go/storeb\x06proto3"
var (
@@ -511,6 +528,7 @@ func file_store_task_run_proto_init() {
file_store_task_run_proto_msgTypes[5].OneofWrappers = []any{
(*SchedulerInfo_WaitingCause_ConnectionLimit)(nil),
(*SchedulerInfo_WaitingCause_TaskUid)(nil),
+ (*SchedulerInfo_WaitingCause_ParallelTasksLimit)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
diff --git a/proto/generated-go/v1/rollout_service.pb.go b/proto/generated-go/v1/rollout_service.pb.go
index 11d028ce3b..7138ac9abb 100644
--- a/proto/generated-go/v1/rollout_service.pb.go
+++ b/proto/generated-go/v1/rollout_service.pb.go
@@ -2698,6 +2698,7 @@ type TaskRun_SchedulerInfo_WaitingCause struct {
//
// *TaskRun_SchedulerInfo_WaitingCause_ConnectionLimit
// *TaskRun_SchedulerInfo_WaitingCause_Task_
+ // *TaskRun_SchedulerInfo_WaitingCause_ParallelTasksLimit
Cause isTaskRun_SchedulerInfo_WaitingCause_Cause `protobuf_oneof:"cause"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -2758,6 +2759,15 @@ func (x *TaskRun_SchedulerInfo_WaitingCause) GetTask() *TaskRun_SchedulerInfo_Wa
return nil
}
+func (x *TaskRun_SchedulerInfo_WaitingCause) GetParallelTasksLimit() bool {
+ if x != nil {
+ if x, ok := x.Cause.(*TaskRun_SchedulerInfo_WaitingCause_ParallelTasksLimit); ok {
+ return x.ParallelTasksLimit
+ }
+ }
+ return false
+}
+
type isTaskRun_SchedulerInfo_WaitingCause_Cause interface {
isTaskRun_SchedulerInfo_WaitingCause_Cause()
}
@@ -2770,11 +2780,18 @@ type TaskRun_SchedulerInfo_WaitingCause_Task_ struct {
Task *TaskRun_SchedulerInfo_WaitingCause_Task `protobuf:"bytes,2,opt,name=task,proto3,oneof"`
}
+type TaskRun_SchedulerInfo_WaitingCause_ParallelTasksLimit struct {
+ ParallelTasksLimit bool `protobuf:"varint,3,opt,name=parallel_tasks_limit,json=parallelTasksLimit,proto3,oneof"`
+}
+
func (*TaskRun_SchedulerInfo_WaitingCause_ConnectionLimit) isTaskRun_SchedulerInfo_WaitingCause_Cause() {
}
func (*TaskRun_SchedulerInfo_WaitingCause_Task_) isTaskRun_SchedulerInfo_WaitingCause_Cause() {}
+func (*TaskRun_SchedulerInfo_WaitingCause_ParallelTasksLimit) isTaskRun_SchedulerInfo_WaitingCause_Cause() {
+}
+
type TaskRun_SchedulerInfo_WaitingCause_Task struct {
state protoimpl.MessageState `protogen:"open.v1"`
// Format: projects/{project}/rollouts/{rollout}/stages/{stage}/tasks/{task}
@@ -3646,7 +3663,7 @@ const file_v1_rollout_service_proto_rawDesc = "" +
"\x14DATABASE_DATA_UPDATE\x10\b\x12\x18\n" +
"\x14DATABASE_DATA_EXPORT\x10\f:Y\xeaAV\n" +
"\x11bytebase.com/Task\x12Aprojects/{project}/rollouts/{rollout}/stages/{stage}/tasks/{task}B\t\n" +
- "\apayloadJ\x04\b\x02\x10\x03\"\xb6\x0e\n" +
+ "\apayloadJ\x04\b\x02\x10\x03\"\xea\x0e\n" +
"\aTaskRun\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\x12\x18\n" +
"\acreator\x18\x03 \x01(\tR\acreator\x12A\n" +
@@ -3674,14 +3691,15 @@ const file_v1_rollout_service_proto_rawDesc = "" +
"\x05Table\x12\x1a\n" +
"\bdatabase\x18\x01 \x01(\tR\bdatabase\x12\x16\n" +
"\x06schema\x18\x02 \x01(\tR\x06schema\x12\x14\n" +
- "\x05table\x18\x03 \x01(\tR\x05table\x1a\xe7\x02\n" +
+ "\x05table\x18\x03 \x01(\tR\x05table\x1a\x9b\x03\n" +
"\rSchedulerInfo\x12;\n" +
"\vreport_time\x18\x01 \x01(\v2\x1a.google.protobuf.TimestampR\n" +
"reportTime\x12T\n" +
- "\rwaiting_cause\x18\x02 \x01(\v2/.bytebase.v1.TaskRun.SchedulerInfo.WaitingCauseR\fwaitingCause\x1a\xc2\x01\n" +
+ "\rwaiting_cause\x18\x02 \x01(\v2/.bytebase.v1.TaskRun.SchedulerInfo.WaitingCauseR\fwaitingCause\x1a\xf6\x01\n" +
"\fWaitingCause\x12+\n" +
"\x10connection_limit\x18\x01 \x01(\bH\x00R\x0fconnectionLimit\x12J\n" +
- "\x04task\x18\x02 \x01(\v24.bytebase.v1.TaskRun.SchedulerInfo.WaitingCause.TaskH\x00R\x04task\x1a0\n" +
+ "\x04task\x18\x02 \x01(\v24.bytebase.v1.TaskRun.SchedulerInfo.WaitingCause.TaskH\x00R\x04task\x122\n" +
+ "\x14parallel_tasks_limit\x18\x03 \x01(\bH\x00R\x12parallelTasksLimit\x1a0\n" +
"\x04Task\x12\x12\n" +
"\x04task\x18\x01 \x01(\tR\x04task\x12\x14\n" +
"\x05issue\x18\x02 \x01(\tR\x05issueB\a\n" +
@@ -4025,6 +4043,7 @@ func file_v1_rollout_service_proto_init() {
file_v1_rollout_service_proto_msgTypes[34].OneofWrappers = []any{
(*TaskRun_SchedulerInfo_WaitingCause_ConnectionLimit)(nil),
(*TaskRun_SchedulerInfo_WaitingCause_Task_)(nil),
+ (*TaskRun_SchedulerInfo_WaitingCause_ParallelTasksLimit)(nil),
}
file_v1_rollout_service_proto_msgTypes[45].OneofWrappers = []any{}
type x struct{}
diff --git a/proto/store/store/task_run.proto b/proto/store/store/task_run.proto
index 37f0828de7..d8f6e19621 100644
--- a/proto/store/store/task_run.proto
+++ b/proto/store/store/task_run.proto
@@ -52,6 +52,7 @@ message SchedulerInfo {
oneof cause {
bool connection_limit = 1;
int32 task_uid = 2;
+ bool parallel_tasks_limit = 3;
}
}
WaitingCause waiting_cause = 2;
diff --git a/proto/v1/v1/rollout_service.proto b/proto/v1/v1/rollout_service.proto
index f5f2185a08..30f61c0701 100644
--- a/proto/v1/v1/rollout_service.proto
+++ b/proto/v1/v1/rollout_service.proto
@@ -521,6 +521,7 @@ message TaskRun {
oneof cause {
bool connection_limit = 1;
Task task = 2;
+ bool parallel_tasks_limit = 3;
}
message Task {
// Format: projects/{project}/rollouts/{rollout}/stages/{stage}/tasks/{task}