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

lightning: fix oom when mem/cpu ratio is low #43729

Merged
merged 2 commits into from
May 12, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions br/pkg/lightning/backend/kv/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ func (e *BaseKVEncoder) LogEvalGenExprFailed(row []types.Datum, colInfo *model.C
)
}

// TruncateWarns resets the warnings in session context.
func (e *BaseKVEncoder) TruncateWarns() {
e.SessionCtx.Vars.StmtCtx.TruncateWarnings(0)
}

func evalGeneratedColumns(se *Session, record []types.Datum, cols []*table.Column,
genCols []GeneratedCol) (errCol *model.ColumnInfo, err error) {
mutRow := chunk.MutRowFromDatums(record)
Expand Down
5 changes: 5 additions & 0 deletions br/pkg/lightning/backend/kv/sql2kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ func Row2KvPairs(row encode.Row) []common.KvPair {
// `columnPermutation` parameter.
func (kvcodec *tableKVEncoder) Encode(row []types.Datum,
rowID int64, columnPermutation []int, _ int64) (encode.Row, error) {
// we ignore warnings when encoding rows now, but warnings uses the same memory as parser, since the input
// row []types.Datum share the same underlying buf, and when doing CastValue, we're using hack.String/hack.Slice.
// when generating error such as mysql.ErrDataOutOfRange, the data will be part of the error, causing the buf
// unable to release. So we truncate the warnings here.
defer kvcodec.TruncateWarns()
var value types.Datum
var err error

Expand Down
5 changes: 5 additions & 0 deletions executor/importer/kv_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func newTableKVEncoder(

// Encode implements the kvEncoder interface.
func (en *tableKVEncoder) Encode(row []types.Datum, rowID int64) (*kv.Pairs, error) {
// we ignore warnings when encoding rows now, but warnings uses the same memory as parser, since the input
// row []types.Datum share the same underlying buf, and when doing CastValue, we're using hack.String/hack.Slice.
// when generating error such as mysql.ErrDataOutOfRange, the data will be part of the error, causing the buf
// unable to release. So we truncate the warnings here.
defer en.TruncateWarns()
record, err := en.parserData2TableData(row, rowID)
if err != nil {
return nil, err
Expand Down