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 operator abstraction #46279

Merged
merged 9 commits into from
Aug 22, 2023

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Aug 21, 2023

What problem does this PR solve?

Issue Number: ref #46258

Problem Summary:

What is changed and how it works?

This PR introduces the async data operator interface, which provide an abstraction for the planner of dist task framework.

// Operator is the basic operation unit in the task execution.
type Operator interface {
	Open() error
	Close() error
	Display() string
}

By composing the async operators, we can process the data concurrently:

words := `Bob hiT a ball, the hIt BALL flew far after it was hit.`
var mostCommonWord string
splitter := makeSplitter(words)
lower := makeLower()
counter := makeCounter()
collector := makeCollector(&mostCommonWord)

Compose[string](splitter, lower)
Compose[string](lower, counter)
Compose[strCnt](counter, collector)

pipeline := NewAsyncPipeline(splitter, lower, counter, collector)
pipeline.Execute()

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 21, 2023
@tiprow
Copy link

tiprow bot commented Aug 21, 2023

Hi @tangenta. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@codecov
Copy link

codecov bot commented Aug 21, 2023

Codecov Report

Merging #46279 (3726322) into master (533998e) will decrease coverage by 0.6618%.
Report is 12 commits behind head on master.
The diff coverage is 95.4545%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #46279        +/-   ##
================================================
- Coverage   73.3815%   72.7198%   -0.6618%     
================================================
  Files          1285       1309        +24     
  Lines        394832     399639      +4807     
================================================
+ Hits         289734     290617       +883     
- Misses        86650      90608      +3958     
+ Partials      18448      18414        -34     
Flag Coverage Δ
integration 25.6501% <0.0000%> (?)
unit 73.3979% <95.4545%> (+0.0163%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 54.0444% <ø> (ø)
parser 85.0845% <ø> (+0.0178%) ⬆️
br 47.9067% <ø> (-4.3111%) ⬇️

Copy link
Contributor

@ywqzzy ywqzzy left a comment

Choose a reason for hiding this comment

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

LGTM

return "simpleSink"
}

type simpleOperator[T, R any] struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

For add index, will we use IngestOperator which wraps AsyncOperator instead of simpleOperator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you can overwrite the Display() method.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 22, 2023

@ywqzzy: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

LGTM

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

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

3/10, will review later

disttask/operator/operator.go Outdated Show resolved Hide resolved
disttask/operator/operator.go Outdated Show resolved Hide resolved
disttask/operator/operator.go Show resolved Hide resolved
disttask/operator/operator.go Outdated Show resolved Hide resolved
disttask/operator/pipeline.go Show resolved Hide resolved
disttask/operator/operator.go Outdated Show resolved Hide resolved
disttask/operator/wrapper.go Show resolved Hide resolved
}

// NewAsyncOperator create an AsyncOperator.
func NewAsyncOperator[T, R any](name string, workerNum int, transform func(T) R) *AsyncOperator[T, R] {
Copy link
Contributor

Choose a reason for hiding this comment

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

previously i thought we need impl each operator separately, now it seems we have a common operator and we need to impl a different transform

Copy link
Contributor

Choose a reason for hiding this comment

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

and it's not that flexible as each input T we generate a output R, but in some case we only generate one output from all input data.(right now, we're using a special sink as a collector)

Copy link
Contributor

Choose a reason for hiding this comment

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

and it's not that flexible as each input T we generate a output R, but in some case we only generate one output from all input data.(right now, we're using a special sink as a collector)

Do you mean that one operator should have multiple type of input?

Copy link
Contributor Author

@tangenta tangenta Aug 22, 2023

Choose a reason for hiding this comment

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

Let me change it to two constructors:

// NewAsyncOperatorWithTransform create an AsyncOperator with a transform function.
func NewAsyncOperatorWithTransform[T, R any](name string, workerNum int, transform func(T) R) *AsyncOperator[T, R] {
	pool := workerpool.NewWorkerPool(name, util.DistTask, workerNum, newAsyncWorkerCtor(transform))
	return NewAsyncOperator(pool)
}

// NewAsyncOperator create an AsyncOperator.
func NewAsyncOperator[T, R any](pool *workerpool.WorkerPool[T, R]) *AsyncOperator[T, R] {
	return &AsyncOperator[T, R]{
		pool: pool,
	}
}

We can pass a custom worker pool for different businesses.

If this still cannot meet the requirement, we can define our own async operator by implementing Operator + WithSource/WithSink interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean that one operator should have multiple type of input?

now we have one output row for each input row(suppose it's row-based), we may want a operator that aggregate multiple or all input rows into a single output row.

@Benjamin2037
Copy link
Collaborator

Seems no err handling code, next pr?

@tangenta
Copy link
Contributor Author

@Benjamin2037 Yes, I will implement the error handling in next PR.

Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 22, 2023
Copy link
Contributor

@GMHDBJD GMHDBJD left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, GMHDBJD, ywqzzy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 22, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 22, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-08-22 13:43:39.764532506 +0000 UTC m=+1243384.313548494: ☑️ agreed by D3Hunter.
  • 2023-08-22 15:01:34.93883819 +0000 UTC m=+1248059.487854161: ☑️ agreed by GMHDBJD.

@ti-chi-bot ti-chi-bot bot merged commit 1ea6499 into pingcap:master Aug 22, 2023
15 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants