-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
stmtv2: ignore corrupted line when scan #41374
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,8 +388,8 @@ func (r *HistoryReader) scheduleTasks( | |
case <-ctx.Done(): | ||
// notified by manager or parent ctx is canceled | ||
} | ||
close(rowsCh) // task done | ||
mgrWg.Wait() | ||
close(rowsCh) // task done | ||
} | ||
|
||
type stmtChecker struct { | ||
|
@@ -482,20 +482,23 @@ func parseBeginTsAndReseek(file *os.File) (int64, error) { | |
if _, err := file.Seek(0, io.SeekStart); err != nil { | ||
return 0, err | ||
} | ||
firstLine, err := readLine(bufio.NewReader(file)) | ||
if err != nil { | ||
return 0, err | ||
|
||
reader := bufio.NewReader(file) | ||
var record stmtTinyRecord | ||
for { // ignore invalid lines | ||
line, err := readLine(reader) | ||
if err != nil { | ||
return 0, err | ||
} | ||
err = json.Unmarshal(line, &record) | ||
if err == nil { | ||
break | ||
} | ||
} | ||
|
||
if _, err := file.Seek(0, io.SeekStart); err != nil { | ||
return 0, err | ||
} | ||
if len(firstLine) == 0 { | ||
return 0, nil | ||
} | ||
var record stmtTinyRecord | ||
if err := json.Unmarshal(firstLine, &record); err != nil { | ||
return 0, err | ||
} | ||
return record.Begin, nil | ||
} | ||
|
||
|
@@ -668,14 +671,19 @@ func (w *stmtScanWorker) putLines( | |
} | ||
|
||
func (w *stmtScanWorker) readlines(reader *bufio.Reader) ([][]byte, error) { | ||
firstLine, err := readLine(reader) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var firstLine []byte | ||
var record *stmtTinyRecord | ||
for { // ingore invalid lines | ||
var err error | ||
firstLine, err = readLine(reader) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
record, err := w.parse(firstLine) | ||
if err != nil { | ||
return nil, err | ||
record, err = w.parse(firstLine) | ||
if err == nil { | ||
break | ||
} | ||
} | ||
|
||
if w.needStop(record) { | ||
|
@@ -740,7 +748,7 @@ func (w *stmtParseWorker) run( | |
func (w *stmtParseWorker) handleLines( | ||
lines [][]byte, | ||
rowsCh chan<- [][]types.Datum, | ||
errCh chan<- error, | ||
_ chan<- error, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not remove it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case it becomes needed in future |
||
) { | ||
if len(lines) == 0 { | ||
return | ||
|
@@ -750,8 +758,8 @@ func (w *stmtParseWorker) handleLines( | |
for _, line := range lines { | ||
record, err := w.parse(line) | ||
if err != nil { | ||
w.putErr(err, errCh) | ||
return | ||
// ignore invalid lines | ||
continue | ||
} | ||
|
||
if w.needStop(record) { | ||
|
@@ -771,16 +779,6 @@ func (w *stmtParseWorker) handleLines( | |
} | ||
} | ||
|
||
func (w *stmtParseWorker) putErr( | ||
err error, | ||
errCh chan<- error, | ||
) { | ||
select { | ||
case errCh <- err: | ||
case <-w.ctx.Done(): | ||
} | ||
} | ||
|
||
func (w *stmtParseWorker) putRows( | ||
rows [][]types.Datum, | ||
rowsCh chan<- [][]types.Datum, | ||
|
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
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.
Is the corrupted line caused by this?
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.
No. But if err occurs, closing
rowsCh
before workers are done can cause sending to a closed channel and then panic.