Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <crazycs520@gmail.com>
  • Loading branch information
crazycs520 committed Nov 6, 2023
1 parent 17fb82c commit 254584c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/infoschema/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,22 @@ func (h *InfoCache) getSchemaByTimestampNoLock(ts uint64) (InfoSchema, bool) {
// thus it may have better performance than binary search
for i, is := range h.cache {
if is.timestamp == 0 || ts < uint64(is.timestamp) {
// is.timestamp == 0 means the schema ts is unknown, so we can't use it, then just skip it.
// ts < is.timestamp means the schema is newer than ts, so we can't use it too, just skip it to find the older one.
continue
}
// ts >= is.timestamp must be true after the above condition.
if i == 0 {
// the first element is the latest schema, so we can return it directly.
return is.infoschema, true
}
if h.cache[i-1].infoschema.SchemaMetaVersion() == is.infoschema.SchemaMetaVersion()+1 && uint64(h.cache[i-1].timestamp) > ts {
// This first condition is to make sure the schema version is continuous. If last(cache[i-1]) schema-version is 10,
// but current(cache[i]) schema-version is not 9, then current schema is not suitable for ts.
// The second condition is to make sure the cache[i-1].timestamp > ts >= cache[i].timestamp, then the current schema is suitable for ts.
return is.infoschema, true
}
// current schema is not suitable for ts, then break the loop to avoid the unnecessary search.
break
}

Expand Down

0 comments on commit 254584c

Please sign in to comment.