-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
inforschema, executor, util/kvcache, util/statement_summary : Add STATEMENTS_SUMMARY_EVICTED into information_schema #24513
Merged
Merged
Changes from 34 commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
1a96cbb
util/kvcache: enhance LRU Cache
ClSlaid 0c8920a
Merge branch 'master' into master
ClSlaid 25ae806
Merge branch 'master' into master
ClSlaid 529e346
Util/kvcache: Typo fix
ClSlaid 38fa019
util/kvcache/simple_lru.go: typo fix
ClSlaid d78ca46
util/kvcache: fix test
ClSlaid 1cddd8f
Merge branch 'master' into master
crazycs520 33d865f
util/kvcache: synced onEvict func -> asynced
ClSlaid 2d75e37
Merge branch 'master' of github.com:ClSlaid/tidb
ClSlaid 05703d8
util/kvcache: formatted
ClSlaid eaf1caa
Merge branch 'master' into master
crazycs520 0163613
Merge branch 'master' into master
ti-chi-bot 0935f75
Merge branch 'master' into master
ti-chi-bot c0227b6
Statements Summary Evicted Prototype Commit
ClSlaid 0a168fe
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid b447b86
Fix STATEMENTS_SUMMARY_EVICTED
ClSlaid 8e8792b
util/stmtsummary: Fix evicted.go
ClSlaid 2a8ed11
Merge branch 'pingcap:master' into master
ClSlaid 12b6a87
Merge branch 'master' into master
ClSlaid 373d344
util/stmtsummary: Delete debug code
ClSlaid 0f24624
util/stmtsummary: add test to EVICTED_COUNT
ClSlaid e2a18b1
util/stmtsummary: Add test to evicted count
ClSlaid 6b7da7e
go.sum: disable fail-point
ClSlaid ebad974
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid 3fcd196
fix merge problems
ClSlaid 073ff06
clean up evicted count
ClSlaid 32e8df9
typo fix
ClSlaid 1092e72
performance improve and typo fix
ClSlaid 7e8a8d8
simplify logic in addEvicted
ClSlaid 252b43a
beautify evicted.go && typo fix
ClSlaid 015b145
fix nil pointer bug in evicted.go
ClSlaid e061027
fix zero quota test for kvcache
ClSlaid d3bf818
Add test to evicted.go and some bug fixes
ClSlaid f59155b
typo fix in executor and infoschema
ClSlaid efcad35
typo fix
ClSlaid 80167a3
try fix git merge problem
ClSlaid dbc94c7
Add more test to evicted count
ClSlaid 756c53e
evicted test full cover
ClSlaid 43a4adc
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid be4b4e4
fix merge conflict
ClSlaid c6ce248
fix nil pointer problem
ClSlaid a8be817
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid fdec81a
test refactoring
ClSlaid 01a92a4
format and add license.
ClSlaid 9c503e5
fix empty table error and clean up useless codes.
ClSlaid b2278b2
Add test to table and more test to evicted count
ClSlaid d3ea973
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid a3ed839
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid 9b243a5
typo fix
ClSlaid eaffa1c
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid 413ed0d
make check
ClSlaid c91e5e3
OUTDATED AGAIN???: Merge branch 'master' of github.com:pingcap/tidb
ClSlaid 0bd1f5e
fix go.sum
ClSlaid f282833
try fix data racing
ClSlaid 16c83f9
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid cca919b
try fix data racing.
ClSlaid 52cb27b
try fix data racing again.
ClSlaid a31059d
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid 4c9e65f
Merge branch 'master' into master
crazycs520 b7a87e1
try fix data racing again again.
ClSlaid 5725827
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid b0776f5
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid b50b213
revoke change in unrelated files.
ClSlaid 3b9fa88
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid cafa16a
Merge branch 'master' into master
crazycs520 f880324
change interval in tables_test.go
ClSlaid f740b34
Merge branch 'master' of github.com:pingcap/tidb
ClSlaid 6c69920
Merge branch 'master' into master
ti-chi-bot caab2da
Merge branch 'master' into master
ti-chi-bot 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
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
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,164 @@ | ||
package stmtsummary | ||
djshow832 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"container/list" | ||
"time" | ||
|
||
"github.com/pingcap/parser/mysql" | ||
"github.com/pingcap/tidb/types" | ||
) | ||
|
||
// stmtSummaryByDigestEvicted contents digests evicted from stmtSummaryByDigestMap | ||
type stmtSummaryByDigestEvicted struct { | ||
// record evicted data in intervals | ||
// latest history data is Back() | ||
history *list.List | ||
} | ||
|
||
// element being stored in stmtSummaryByDigestEvicted | ||
type stmtSummaryByDigestEvictedElement struct { | ||
// beginTime is the begin time of current interval | ||
beginTime int64 | ||
// endTime is the end time of current interval | ||
endTime int64 | ||
// *Kinds* of digest being evicted | ||
digestKeyMap map[string]struct{} | ||
} | ||
|
||
// spawn a new pointer to stmtSummaryByDigestEvicted | ||
func newStmtSummaryByDigestEvicted() *stmtSummaryByDigestEvicted { | ||
return &stmtSummaryByDigestEvicted{ | ||
history: list.New(), | ||
} | ||
} | ||
|
||
// spawn a new pointer to stmtSummaryByDigestEvictedElement | ||
func newStmtSummaryByDigestEvictedElement(beginTime int64, endTime int64) *stmtSummaryByDigestEvictedElement { | ||
return &stmtSummaryByDigestEvictedElement{ | ||
beginTime: beginTime, | ||
endTime: endTime, | ||
digestKeyMap: make(map[string]struct{}), | ||
} | ||
} | ||
|
||
// AddEvicted is used add an evicted record to stmtSummaryByDigestEvicted | ||
func (ssbde *stmtSummaryByDigestEvicted) AddEvicted(evictedKey *stmtSummaryByDigestKey, evictedValue *stmtSummaryByDigest, historySize int) { | ||
crazycs520 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
evictedValue.Lock() | ||
defer evictedValue.Unlock() | ||
if evictedValue == nil { | ||
return | ||
} | ||
|
||
for e, h := evictedValue.history.Back(), ssbde.history.Back(); e != nil; e = e.Prev() { | ||
evictedElement := e.Value.(*stmtSummaryByDigestElement) | ||
eBeginTime := evictedElement.beginTime | ||
eEndTime := evictedElement.endTime | ||
|
||
// no record in ssbde.history, direct insert | ||
if ssbde.history.Len() == 0 { | ||
record := newStmtSummaryByDigestEvictedElement(eBeginTime, eEndTime) | ||
record.addEvicted(evictedKey, evictedElement) | ||
ssbde.history.PushFront(record) | ||
continue | ||
} | ||
|
||
// prevent exceeding history size | ||
for ssbde.history.Len() >= historySize && ssbde.history.Len() > 1 { | ||
ssbde.history.Remove(ssbde.history.Front()) | ||
} | ||
|
||
// look for matching history interval | ||
// if there are no records in ssbde.history, following code will not be executed. Such situation will probably lead to a bug. | ||
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. The comment situation seems never to happen? since line71 already handle this case, can we remove this comment now? It looks scary |
||
MATCHING: | ||
for ; h != nil; h = h.Prev() { | ||
historyElement := h.Value.(*stmtSummaryByDigestEvictedElement) | ||
|
||
switch historyElement.matchAndAdd(evictedKey, evictedElement) { | ||
case isMatch: | ||
// automatically added | ||
break MATCHING | ||
// not matching, create a new record and insert | ||
case isTooYoung: | ||
{ | ||
record := newStmtSummaryByDigestEvictedElement(eBeginTime, eEndTime) | ||
record.addEvicted(evictedKey, evictedElement) | ||
ssbde.history.InsertAfter(record, h) | ||
break MATCHING | ||
} | ||
default: // isTooOld | ||
{ | ||
if h == ssbde.history.Front() { | ||
// if digest older than all records in ssbde.history. | ||
record := newStmtSummaryByDigestEvictedElement(eBeginTime, eEndTime) | ||
record.addEvicted(evictedKey, evictedElement) | ||
ssbde.history.PushFront(record) | ||
break MATCHING | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Clear up all records in stmtSummaryByDigestEvicted | ||
func (ssbde *stmtSummaryByDigestEvicted) Clear() { | ||
ssbde.history.Init() | ||
} | ||
|
||
// add an evicted record to stmtSummaryByDigestEvictedElement | ||
func (seElement *stmtSummaryByDigestEvictedElement) addEvicted(digestKey *stmtSummaryByDigestKey, digestValue *stmtSummaryByDigestElement) { | ||
if digestKey != nil { | ||
seElement.digestKeyMap[string(digestKey.Hash())] = struct{}{} | ||
} | ||
} | ||
|
||
const ( | ||
isMatch = 0 | ||
isTooOld = 1 | ||
isTooYoung = 2 | ||
) | ||
|
||
// matchAndAdd check time interval of seElement and digestValue. | ||
// if matches, it will add the digest and return enum match | ||
// if digest too old, it will return enum tooOld and do nothing | ||
// if digest too young, it will return enum tooYoung and do nothing | ||
func (seElement *stmtSummaryByDigestEvictedElement) matchAndAdd(digestKey *stmtSummaryByDigestKey, digestValue *stmtSummaryByDigestElement) (statement int) { | ||
if seElement == nil || digestValue == nil { | ||
return isTooYoung | ||
} | ||
sBeginTime, sEndTime := seElement.beginTime, seElement.endTime | ||
eBeginTime, eEndTime := digestValue.beginTime, digestValue.endTime | ||
if sBeginTime <= eBeginTime && eEndTime <= sEndTime { | ||
seElement.addEvicted(digestKey, digestValue) | ||
return isMatch | ||
} else if eEndTime <= sBeginTime { | ||
return isTooOld | ||
} else { | ||
return isTooYoung | ||
} | ||
} | ||
|
||
// ToEvictedCountDatum converts history evicted record to `evicted count` record's datum | ||
func (ssbde *stmtSummaryByDigestEvicted) ToEvictedCountDatum() [][]types.Datum { | ||
records := make([][]types.Datum, 0, ssbde.history.Len()) | ||
for e := ssbde.history.Front(); e != nil; e = e.Next() { | ||
if record := e.Value.(*stmtSummaryByDigestEvictedElement).toEvictedCountDatum(); record != nil { | ||
records = append(records, record) | ||
} | ||
} | ||
return records | ||
} | ||
|
||
// toEvictedCountDatum converts evicted record to `EvictedCount` record's datum | ||
func (seElement *stmtSummaryByDigestEvictedElement) toEvictedCountDatum() []types.Datum { | ||
datum := types.MakeDatums( | ||
types.NewTime(types.FromGoTime(time.Unix(seElement.beginTime, 0)), mysql.TypeTimestamp, 0), | ||
types.NewTime(types.FromGoTime(time.Unix(seElement.endTime, 0)), mysql.TypeTimestamp, 0), | ||
int64(len(seElement.digestKeyMap)), | ||
) | ||
return datum | ||
} | ||
|
||
func (ssMap *stmtSummaryByDigestMap) ToEvictedCountDatum() [][]types.Datum { | ||
return ssMap.other.ToEvictedCountDatum() | ||
} |
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.
I think this line
return
is unnecessary😏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.
A former python user began coding in go, this is what happend to his typo.