forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lightning: make pre-check output message clearer (pingcap#30439)
close pingcap#30395
- Loading branch information
Showing
6 changed files
with
122 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package restore | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/pingcap/check" | ||
"github.com/pingcap/failpoint" | ||
|
||
"github.com/pingcap/tidb/br/pkg/lightning/config" | ||
"github.com/pingcap/tidb/br/pkg/lightning/worker" | ||
"github.com/pingcap/tidb/br/pkg/storage" | ||
) | ||
|
||
var _ = Suite(&checkInfoSuite{}) | ||
|
||
type checkInfoSuite struct{} | ||
|
||
const passed CheckType = "pass" | ||
|
||
func (s *checkInfoSuite) TestLocalResource(c *C) { | ||
dir := c.MkDir() | ||
mockStore, err := storage.NewLocalStorage(dir) | ||
c.Assert(err, IsNil) | ||
|
||
err = failpoint.Enable("github.com/pingcap/tidb/br/pkg/lightning/common/GetStorageSize", "return(2048)") | ||
c.Assert(err, IsNil) | ||
defer func() { | ||
_ = failpoint.Disable("github.com/pingcap/tidb/br/pkg/lightning/common/GetStorageSize") | ||
}() | ||
|
||
cfg := config.NewConfig() | ||
cfg.Mydumper.SourceDir = dir | ||
cfg.TikvImporter.SortedKVDir = dir | ||
cfg.TikvImporter.Backend = "local" | ||
rc := &Controller{ | ||
cfg: cfg, | ||
store: mockStore, | ||
ioWorkers: worker.NewPool(context.Background(), 1, "io"), | ||
} | ||
|
||
// 1. source-size is smaller than disk-size, won't trigger error information | ||
rc.checkTemplate = NewSimpleTemplate() | ||
err = rc.localResource(1000) | ||
c.Assert(err, IsNil) | ||
tmpl := rc.checkTemplate.(*SimpleTemplate) | ||
c.Assert(tmpl.warnFailedCount, Equals, 1) | ||
c.Assert(tmpl.criticalFailedCount, Equals, 0) | ||
c.Assert(tmpl.normalMsgs[1], Matches, "local disk resources are rich, estimate sorted data size 1000B, local available is 2KiB") | ||
|
||
// 2. source-size is bigger than disk-size, with default disk-quota will trigger a critical error | ||
rc.checkTemplate = NewSimpleTemplate() | ||
err = rc.localResource(4096) | ||
c.Assert(err, IsNil) | ||
tmpl = rc.checkTemplate.(*SimpleTemplate) | ||
c.Assert(tmpl.warnFailedCount, Equals, 1) | ||
c.Assert(tmpl.criticalFailedCount, Equals, 1) | ||
c.Assert(tmpl.criticalMsgs[0], Matches, "local disk space may not enough to finish import, estimate sorted data size is 4KiB, but local available is 2KiB, please set `tikv-importer.disk-quota` to a smaller value than 2KiB or change `mydumper.sorted-kv-dir` to another disk with enough space to finish imports") | ||
|
||
// 3. source-size is bigger than disk-size, with a vaild disk-quota will trigger a warning | ||
rc.checkTemplate = NewSimpleTemplate() | ||
rc.cfg.TikvImporter.DiskQuota = config.ByteSize(1024) | ||
err = rc.localResource(4096) | ||
c.Assert(err, IsNil) | ||
tmpl = rc.checkTemplate.(*SimpleTemplate) | ||
c.Assert(tmpl.warnFailedCount, Equals, 1) | ||
c.Assert(tmpl.criticalFailedCount, Equals, 0) | ||
c.Assert(tmpl.normalMsgs[1], Matches, "local disk space may not enough to finish import, estimate sorted data size is 4KiB, but local available is 2KiB,we will use disk-quota \\(size: 1KiB\\) to finish imports, which may slow down import") | ||
} |
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