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
lightning: refactor to reuse in load data, part1 #42469
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52ada50
refactor
D3Hunter c185b60
refactor
D3Hunter 4e03b97
refac
D3Hunter 9fdf204
fix ut
D3Hunter fe193fb
lint
D3Hunter a30f31b
lint
D3Hunter af1fe94
Merge remote-tracking branch 'origin/master' into refactor-lit-part1
D3Hunter File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "encode", | ||
srcs = ["encode.go"], | ||
importpath = "github.com/pingcap/tidb/br/pkg/lightning/backend/encode", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//br/pkg/lightning/log", | ||
"//br/pkg/lightning/verification", | ||
"//parser/mysql", | ||
"//table", | ||
"//types", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// 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 encode | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/tidb/br/pkg/lightning/log" | ||
"github.com/pingcap/tidb/br/pkg/lightning/verification" | ||
"github.com/pingcap/tidb/parser/mysql" | ||
"github.com/pingcap/tidb/table" | ||
"github.com/pingcap/tidb/types" | ||
) | ||
|
||
type EncodingConfig struct { | ||
SessionOptions | ||
Path string // path of data file | ||
Table table.Table | ||
Logger log.Logger | ||
} | ||
|
||
// EncodingBuilder consists of operations to handle encoding backend row data formats from source. | ||
type EncodingBuilder interface { | ||
// NewEncoder creates an encoder of a TiDB table. | ||
NewEncoder(ctx context.Context, config *EncodingConfig) (Encoder, error) | ||
// MakeEmptyRows creates an empty collection of encoded rows. | ||
MakeEmptyRows() Rows | ||
} | ||
|
||
// Encoder encodes a row of SQL values into some opaque type which can be | ||
// consumed by OpenEngine.WriteEncoded. | ||
type Encoder interface { | ||
// Close the encoder. | ||
Close() | ||
|
||
// Encode encodes a row of SQL values into a backend-friendly format. | ||
Encode(row []types.Datum, rowID int64, columnPermutation []int, offset int64) (Row, error) | ||
} | ||
|
||
// SessionOptions is the initial configuration of the session. | ||
type SessionOptions struct { | ||
SQLMode mysql.SQLMode | ||
Timestamp int64 | ||
SysVars map[string]string | ||
// a seed used for tableKvEncoder's auto random bits value | ||
AutoRandomSeed int64 | ||
// IndexID is used by the DuplicateManager. Only the key range with the specified index ID is scanned. | ||
IndexID int64 | ||
} | ||
|
||
// Rows represents a collection of encoded rows. | ||
type Rows interface { | ||
// SplitIntoChunks splits the rows into multiple consecutive parts, each | ||
// part having total byte size less than `splitSize`. The meaning of "byte | ||
// size" should be consistent with the value used in `Row.ClassifyAndAppend`. | ||
SplitIntoChunks(splitSize int) []Rows | ||
|
||
// Clear returns a new collection with empty content. It may share the | ||
// capacity with the current instance. The typical usage is `x = x.Clear()`. | ||
Clear() Rows | ||
} | ||
|
||
// Row represents a single encoded row. | ||
type Row interface { | ||
// ClassifyAndAppend separates the data-like and index-like parts of the | ||
// encoded row, and appends these parts into the existing buffers and | ||
// checksums. | ||
ClassifyAndAppend( | ||
data *Rows, | ||
dataChecksum *verification.KVChecksum, | ||
indices *Rows, | ||
indexChecksum *verification.KVChecksum, | ||
) | ||
|
||
// Size represents the total kv size of this Row. | ||
Size() uint64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to avoid import cycle