Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disttask: add proto pkg for framework and example #41989

Merged
merged 5 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
"server/conn_test.go": "server/conn_test.go",
"planner/core/rule_partition_eliminate.go": "planner/core/rule_partition_eliminate code",
"distsql/": "ignore distsql code",
"disttask": "disttask code",
"dumpling/export": "dumpling/export code",
"lock/": "lock file",
"errno/": "errno code",
Expand Down
8 changes: 8 additions & 0 deletions disttask/example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "example",
srcs = ["proto.go"],
importpath = "github.com/pingcap/tidb/disttask/example",
visibility = ["//visibility:public"],
)
35 changes: 35 additions & 0 deletions disttask/example/proto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package proto

// TaskStep of Example.
const (
StepOne = iota
StepTwo
)

// TaskType of Example.
const (
TaskTypeExample = "Example"
)

// TaskExample is the example task.
type TaskExample struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to add a comment for the exported type.


// SubtaskExample is the example subtask.
type SubtaskExample struct{}

// MinimalTaskExample is the minimal example task.
type MinimalTaskExample struct{}
8 changes: 8 additions & 0 deletions disttask/framework/proto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "proto",
srcs = ["task.go"],
importpath = "github.com/pingcap/tidb/disttask/framework/proto",
visibility = ["//visibility:public"],
)
77 changes: 77 additions & 0 deletions disttask/framework/proto/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package proto

import (
"time"
)

// task state machine
// 1. succeed: pending -> running -> succeed
// 2. failed: pending -> running -> reverting -> failed/revert_failed
// 3. canceled: pending -> running -> reverting -> canceled/revert_failed
// 3. pause/resume: pending -> running -> pausing -> paused -> running
//
// subtask state machine
// 1. succeed/failed: pending -> running -> succeed/failed
// 2. canceled: pending -> running -> canceled
// 3. rollback: revert_pending -> reverting -> reverted/revert_failed
// 4. pause/resume: pending -> running -> paused -> running
const (
TaskStatePending = "pending"
TaskStateRunning = "running"
TaskStateSucceed = "succeed"
TaskStateReverting = "reverting"
TaskStateFailed = "failed"
TaskStateRevertFailed = "revert_failed"
TaskStateCanceled = "canceled"
TaskStatePausing = "pausing"
TaskStatePaused = "paused"
TaskStateRevertPending = "revert_pending"
TaskStateReverted = "reverted"
)

// TaskStep is the step of task.
const (
StepInit int64 = -1
)

// Task represents the task of distribute framework.
type Task struct {
ID int64
Type string
State string
Step int64
DispatcherID string
Concurrency uint64
StartTime time.Time
Meta []byte
}

// Subtask represents the subtask of distribute framework.
// Each task is divided into multiple subtasks by dispatcher.
type Subtask struct {
ID int64
Type string
TaskID int64
State string
SchedulerID string
StartTime time.Time
Meta []byte
}

// MinimalTask is the minimal task of distribute framework.
// Each subtask is divided into multiple minimal tasks by scheduler.
type MinimalTask interface{}