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

infoschema/slow_query: fix token too long #10328

Merged
merged 18 commits into from
May 9, 2019

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

This PR try to fix If there is row length more than bufio.MaxScanTokenSize, parse slow log will get error: bufio.Scanner: token too long.

What is changed and how it works?

Adjust bufio.Buffer before parse slow log and refine error msg.

  • Add QueryLogMaxLenRecord to record the max QueryLogMaxLen.

Attention: If the user set @@tidb_query_log_max_len=65536 and write a long slow query to slow log, then the tidb-restart. Because the QueryLogMaxLenRecord doesn't persistent Stores, so it will be the
QueryLogMaxLen default value 2048, and then query INFORMATION_SCHEMA.SLOW_QUERY will also get error: "read file buffer overflow, please try to enlarge the variable 'tidb_query_log_max_len', but I think the error message is more clear now, and just enlarge tidb_query_log_max_len then retry.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change
    Side effects

Related changes

  • Need to cherry-pick to the release branch

@crazycs520 crazycs520 added type/bugfix This PR fixes a bug. type/usability labels Apr 30, 2019
@crazycs520
Copy link
Contributor Author

@eurekaka @winkyao PTAL

@codecov
Copy link

codecov bot commented Apr 30, 2019

Codecov Report

Merging #10328 into master will increase coverage by 0.0183%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master     #10328        +/-   ##
================================================
+ Coverage   77.6692%   77.6875%   +0.0183%     
================================================
  Files           411        411                
  Lines         85447      85450         +3     
================================================
+ Hits          66366      66384        +18     
+ Misses        14118      14111         -7     
+ Partials       4963       4955         -8

@codecov
Copy link

codecov bot commented Apr 30, 2019

Codecov Report

Merging #10328 into master will increase coverage by 0.0235%.
The diff coverage is 91.3043%.

@@               Coverage Diff                @@
##             master     #10328        +/-   ##
================================================
+ Coverage   77.3236%   77.3471%   +0.0235%     
================================================
  Files           412        412                
  Lines         85825      85839        +14     
================================================
+ Hits          66363      66394        +31     
+ Misses        14412      14402        -10     
+ Partials       5050       5043         -7

if atomic.LoadUint64(&config.QueryLogMaxLenRecord) > (bufio.MaxScanTokenSize - 100) {
maxBuf := int(atomic.LoadUint64(&config.QueryLogMaxLenRecord) + 100)
scanner.Buffer([]byte{}, maxBuf)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use bufio.Reader.ReadLine to completely avoid this error?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can use ReadLine to implement a new scanner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea. Other question, should we add a max-single-line-length-limit? If user executes a long query.

At first, I think if we don't limit the max-single-line-length, then parse slow log may consume a lot of memory and then may make TiDB-server killed by the system.

But after careful consideration, I think no need to add max-single-line-length, the first reason is we have log rotate, the other reason is executing the long query may make tidb-server killed in executing. 😂 What do you think? @eurekaka @winkyao

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. PTAL @eurekaka @winkyao

@zhouqiang-cl
Copy link
Contributor

/run-all-tests

@crazycs520 crazycs520 force-pushed the fix-slow-log-token-too-long branch from ab58560 to b4e610e Compare May 5, 2019 08:42
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

@eurekaka PTAL

@crazycs520
Copy link
Contributor Author

/run-all-tests

lineByte = append(lineByte, tempLine...)

// Use the max value of max_allowed_packet to check the single line length.
if len(lineByte) > int(variable.MaxOfMaxAllowedPacket) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why using MaxOfMaxAllowedPacket instead of MaxAllowedPacket?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because MaxAllowedPacket may has been changed.

infoschema/slow_log.go Outdated Show resolved Hide resolved
Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

@eurekaka eurekaka added the status/LGT2 Indicates that a PR has LGTM 2. label May 8, 2019
@CLAassistant
Copy link

CLAassistant commented May 8, 2019

CLA assistant check
All committers have signed the CLA.

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

1 similar comment
@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

2 similar comments
@zhouqiang-cl
Copy link
Contributor

/run-all-tests

@zhouqiang-cl
Copy link
Contributor

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520 crazycs520 merged commit 5617809 into pingcap:master May 9, 2019
crazycs520 added a commit to crazycs520/tidb that referenced this pull request May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug. type/usability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants