Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

backend/local: skip split regions if engine total size is smaller than region size #524

Merged
merged 5 commits into from
Jan 11, 2021

Conversation

glorv
Copy link
Contributor

@glorv glorv commented Dec 14, 2020

What problem does this PR solve?

Skip split regions there is only one range within the engine.

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

Related changes

lightning/backend/local.go Outdated Show resolved Hide resolved
@kennytm
Copy link
Collaborator

kennytm commented Jan 8, 2021

/run-all-tests

Copy link
Collaborator

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 One reviewer already commented LGTM (LGTM1) label Jan 8, 2021
@@ -1181,10 +1181,14 @@ func (local *local) ImportEngine(ctx context.Context, engineUUID uuid.UUID) erro
log.L().Info("start import engine", zap.Stringer("uuid", engineUUID),
zap.Int("ranges", len(ranges)))

// if all the kv can fit in one region, skip split regions. TiDB will split one region for
// the table when table is created.
needSplit := len(ranges) > 0 || lf.TotalSize > local.regionSplitSize || lf.Length > regionMaxKeyCount
Copy link
Contributor

Choose a reason for hiding this comment

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

is needSplit := len(ranges) > 1 enough? seems readAndSplitIntoRange has checked regionSplitSize and regionMaxKeyCount

// <= 96MB no need to split into range
if engineFile.TotalSize <= local.regionSplitSize && engineFile.Length <= regionMaxKeyCount {
ranges := []Range{{start: firstKey, end: endKey, length: int(engineFile.Length)}}
return ranges, nil
}

and splitRangeBySizeProps uses a tighter keysLimit so it will return more than 1 ranges

Copy link
Contributor Author

Choose a reason for hiding this comment

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

splitRangeBySizeProps may still generate ranges that exceed regionSplitSize, so if the split is triggered by remain ranges, it may be a single range but the range size is exceeded.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Now I suggest

Suggested change
needSplit := len(ranges) > 0 || lf.TotalSize > local.regionSplitSize || lf.Length > regionMaxKeyCount
needSplit := len(ranges) > 1 || lf.TotalSize > local.regionSplitSize || lf.Length > regionMaxKeyCount

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

Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

rest LGTM

@@ -1181,10 +1181,14 @@ func (local *local) ImportEngine(ctx context.Context, engineUUID uuid.UUID) erro
log.L().Info("start import engine", zap.Stringer("uuid", engineUUID),
zap.Int("ranges", len(ranges)))

// if all the kv can fit in one region, skip split regions. TiDB will split one region for
// the table when table is created.
needSplit := len(ranges) > 0 || lf.TotalSize > local.regionSplitSize || lf.Length > regionMaxKeyCount
Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Now I suggest

Suggested change
needSplit := len(ranges) > 0 || lf.TotalSize > local.regionSplitSize || lf.Length > regionMaxKeyCount
needSplit := len(ranges) > 1 || lf.TotalSize > local.regionSplitSize || lf.Length > regionMaxKeyCount

@lance6716
Copy link
Contributor

LGTM

@ti-srebot ti-srebot removed the status/LGT1 One reviewer already commented LGTM (LGTM1) label Jan 11, 2021
@ti-srebot ti-srebot added the status/LGT2 Two reviewers already commented LGTM, ready for merge (LGTM2) label Jan 11, 2021
@glorv
Copy link
Contributor Author

glorv commented Jan 11, 2021

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 161f005 into master Jan 11, 2021
glorv added a commit that referenced this pull request Jan 29, 2021
@glorv glorv deleted the skip-split branch February 20, 2021 07:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CanMerge status/LGT2 Two reviewers already commented LGTM, ready for merge (LGTM2)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants