Skip to content

Commit

Permalink
br: unified the lint rules with tidb. (pingcap#31644)
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer authored Jan 17, 2022
1 parent 8db3a8d commit a5435cd
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 105 deletions.
90 changes: 0 additions & 90 deletions .golangci_br.yml

This file was deleted.

9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ goword:tools/bin/goword

check-static: tools/bin/golangci-lint
GO111MODULE=on CGO_ENABLED=0 tools/bin/golangci-lint run -v $$($(PACKAGE_DIRECTORIES_TIDB_TESTS)) --config .golangci.yml
GO111MODULE=on CGO_ENABLED=0 tools/bin/golangci-lint run -v $$($(BR_PACKAGE_DIRECTORIES)) --config .golangci_br.yml

unconvert:tools/bin/unconvert
@echo "unconvert check(skip check the genenrated or copied code in lightning)"
Expand All @@ -65,7 +64,7 @@ lint:tools/bin/revive

vet:
@echo "vet"
$(GO) vet -all $(PACKAGES_TIDB_TESTS) 2>&1 | $(FAIL_ON_STDOUT)
$(GO) vet -all $(PACKAGES_TIDB_TESTS_WITHOUT_BR) 2>&1 | $(FAIL_ON_STDOUT)

tidy:
@echo "go mod tidy"
Expand Down Expand Up @@ -123,7 +122,7 @@ devgotest: failpoint-enable
# - 'ok ' to ignore passed directories
@echo "Running in native mode."
@export log_level=info; export TZ='Asia/Shanghai'; \
$(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -cover $(PACKAGES_TIDB_TESTS) -check.p true > gotest.log || { $(FAILPOINT_DISABLE); grep -v '^\([[]20\|PASS:\|ok \)' 'gotest.log'; exit 1; }
$(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -cover $(PACKAGES_TIDB_TESTS_WITHOUT_BR) -check.p true > gotest.log || { $(FAILPOINT_DISABLE); grep -v '^\([[]20\|PASS:\|ok \)' 'gotest.log'; exit 1; }
@$(FAILPOINT_DISABLE)

ut: failpoint-enable tools/bin/ut
Expand All @@ -133,7 +132,7 @@ ut: failpoint-enable tools/bin/ut
gotest: failpoint-enable
@echo "Running in native mode."
@export log_level=info; export TZ='Asia/Shanghai'; \
$(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -timeout 20m -cover $(PACKAGES_TIDB_TESTS) -coverprofile=coverage.txt -check.p true > gotest.log || { $(FAILPOINT_DISABLE); cat 'gotest.log'; exit 1; }
$(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -timeout 20m -cover $(PACKAGES_TIDB_TESTS_WITHOUT_BR) -coverprofile=coverage.txt -check.p true > gotest.log || { $(FAILPOINT_DISABLE); cat 'gotest.log'; exit 1; }
@$(FAILPOINT_DISABLE)

gotest_in_verify_ci: failpoint-enable tools/bin/gotestsum
Expand All @@ -142,7 +141,7 @@ gotest_in_verify_ci: failpoint-enable tools/bin/gotestsum
@export TZ='Asia/Shanghai'; \
CGO_ENABLED=1 tools/bin/gotestsum --junitfile "$(TEST_COVERAGE_DIR)/tidb-junit-report.xml" -- -v -p $(P) \
-ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -coverprofile="$(TEST_COVERAGE_DIR)/tidb_cov.unit_test.out" \
$(PACKAGES_TIDB_TESTS) -check.p true || { $(FAILPOINT_DISABLE); exit 1; }
$(PACKAGES_TIDB_TESTS_WITHOUT_BR) -check.p true || { $(FAILPOINT_DISABLE); exit 1; }
@$(FAILPOINT_DISABLE)

race: failpoint-enable
Expand Down
6 changes: 4 additions & 2 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ LINUX := "Linux"
MAC := "Darwin"

PACKAGE_LIST := go list ./...
PACKAGE_LIST_TIDB_TESTS := go list ./... | grep -vE "github.com\/pingcap\/tidb\/br|github.com\/pingcap\/tidb\/cmd|github.com\/pingcap\/tidb\/dumpling"
PACKAGE_LIST_TIDB_TESTS := go list ./... | grep -vE "github.com\/pingcap\/tidb\/cmd|github.com\/pingcap\/tidb\/dumpling"
PACKAGES ?= $$($(PACKAGE_LIST))
PACKAGES_TIDB_TESTS ?= $$($(PACKAGE_LIST_TIDB_TESTS))
PACKAGES_TIDB_TESTS_WITHOUT_BR ?= $$($(PACKAGE_LIST_TIDB_TESTS) | grep -v "br")
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/$(PROJECT)/||'
PACKAGE_DIRECTORIES_TIDB_TESTS := $(PACKAGE_LIST_TIDB_TESTS) | sed 's|github.com/pingcap/$(PROJECT)/||'
PACKAGE_DIRECTORIES_TIDB_TESTS_WITHOUT_BR := $(PACKAGE_LIST_TIDB_TESTS) | sed 's|github.com/pingcap/$(PROJECT)/||' | grep -v "br"
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")
FILES_TIDB_TESTS := $$(find $$($(PACKAGE_DIRECTORIES_TIDB_TESTS)) -name "*.go")
FILES_TIDB_TESTS := $$(find $$($(PACKAGE_DIRECTORIES_TIDB_TESTS_WITHOUT_BR)) -name "*.go")

UNCONVERT_PACKAGES_LIST := go list ./...| grep -vE "lightning\/checkpoints|lightning\/manual|lightning\/common"
UNCONVERT_PACKAGES := $$($(UNCONVERT_PACKAGES_LIST))
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/lightning/backend/kv/sql2kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func TestDecode(t *testing.T) {
SQLMode: mysql.ModeStrictAllTables,
Timestamp: 1234567890,
})
require.NoError(t, err)
require.NotNil(t, decoder)
require.Equal(t, decoder.Name(), "`test`.`c1`")
p := common.KvPair{
Expand All @@ -164,6 +165,7 @@ func TestDecode(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, p.Val)
rows, _, err := decoder.DecodeRawRowData(h, p.Val)
require.NoError(t, err)
require.Equal(t, rows, []types.Datum{
types.NewIntDatum(1),
})
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/lightning/backend/local/duplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,11 @@ type dupTask struct {
}

func (m *DuplicateManager) buildDupTasks() ([]dupTask, error) {
var tasks []dupTask
keyRanges, err := tableHandleKeyRanges(m.tbl.Meta())
if err != nil {
return nil, errors.Trace(err)
}
tasks := make([]dupTask, 0, len(keyRanges))
for _, kr := range keyRanges {
tableID := tablecodec.DecodeTableID(kr.StartKey)
tasks = append(tasks, dupTask{
Expand Down Expand Up @@ -587,7 +587,7 @@ func (m *DuplicateManager) splitLocalDupTaskByKeys(
return nil, errors.Trace(err)
}
ranges := splitRangeBySizeProps(Range{start: task.StartKey, end: task.EndKey}, sizeProps, sizeLimit, keysLimit)
var newDupTasks []dupTask
newDupTasks := make([]dupTask, 0, len(ranges))
for _, r := range ranges {
newDupTasks = append(newDupTasks, dupTask{
KeyRange: tidbkv.KeyRange{
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/lightning/backend/local/key_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestDupDetectKeyOrder(t *testing.T) {
{0x0, 0x1, 0x3, 0x4, 0x0, 0x0, 0x0},
}
keyAdapter := dupDetectKeyAdapter{}
var encodedKeys [][]byte
encodedKeys := make([][]byte, 0, len(keys))
for _, key := range keys {
encodedKeys = append(encodedKeys, keyAdapter.Encode(nil, key, 1))
}
Expand Down
2 changes: 0 additions & 2 deletions br/pkg/lightning/backend/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,6 @@ func (f *mockImportClientFactory) Create(_ context.Context, storeID uint64) (sst

func (f *mockImportClientFactory) Close() {}

type testMultiIngestSuite struct{}

func TestMultiIngest(t *testing.T) {
allStores := []*metapb.Store{
{
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/lightning/backend/tidb/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestWriteRowsErrorOnDup(t *testing.T) {
}

// TODO: temporarily disable this test before we fix strict mode
//nolint:unused
//nolint:unused,deadcode
func testStrictMode(t *testing.T) {
s := createMysqlSuite(t)
defer s.TearDownTest(t)
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,7 @@ func (s *tableRestoreSuite) TestCheckClusterResource(c *C) {
sourceSize += size
return nil
})
c.Assert(err, IsNil)
err = rc.clusterResource(ctx, sourceSize)
c.Assert(err, IsNil)

Expand Down
1 change: 1 addition & 0 deletions br/pkg/membuf/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ func TestBufferIsolation(t *testing.T) {
b3 := append([]byte(nil), b2...)
b1 = append(b1, 0, 1, 2, 3)
require.Equal(t, b3, b2)
require.NotEqual(t, b2, b1)
}
2 changes: 2 additions & 0 deletions br/pkg/restore/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestRestoreAutoIncID(t *testing.T) {
// try again, failed due to table exists.
table.Info.AutoIncID = globalAutoID + 200
err = db.CreateTable(context.Background(), &table, uniqueMap)
require.NoError(t, err)
// Check if AutoIncID is not altered.
autoIncID, err = strconv.ParseUint(tk.MustQuery("admin show `\"t\"` next_row_id").Rows()[0][3].(string), 10, 64)
require.NoErrorf(t, err, "Error query auto inc id: %s", err)
Expand All @@ -117,6 +118,7 @@ func TestRestoreAutoIncID(t *testing.T) {
table.Info.AutoIncID = globalAutoID + 300
uniqueMap[restore.UniqueTableName{"test", "\"t\""}] = true
err = db.CreateTable(context.Background(), &table, uniqueMap)
require.NoError(t, err)
// Check if AutoIncID is altered to globalAutoID + 300.
autoIncID, err = strconv.ParseUint(tk.MustQuery("admin show `\"t\"` next_row_id").Rows()[0][3].(string), 10, 64)
require.NoErrorf(t, err, "Error query auto inc id: %s", err)
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/restore/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ func TestPaginateScanRegion(t *testing.T) {

ctx := context.Background()
regionMap := make(map[uint64]*restore.RegionInfo)
regions := []*restore.RegionInfo{}
batch, err := restore.PaginateScanRegion(ctx, NewTestClient(stores, regionMap, 0), []byte{}, []byte{}, 3)
var regions []*restore.RegionInfo
var batch []*restore.RegionInfo
_, err := restore.PaginateScanRegion(ctx, NewTestClient(stores, regionMap, 0), []byte{}, []byte{}, 3)
require.Error(t, err)
require.Regexp(t, ".*scan region return empty result.*", err.Error())

Expand Down
2 changes: 2 additions & 0 deletions br/tests/br_key_locked/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ type Locker struct {
}

// generateLocks sends Prewrite requests to TiKV to generate locks, without committing and rolling back.
//nolint:gosec
func (c *Locker) generateLocks(pctx context.Context) error {
log.Info("genLock started")

Expand Down Expand Up @@ -340,6 +341,7 @@ func (c *Locker) lockBatch(ctx context.Context, keys [][]byte, primary []byte) (
}
}

//nolint:gosec
func randStr() string {
length := rand.Intn(128)
res := ""
Expand Down
2 changes: 2 additions & 0 deletions br/tests/br_rawkv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func testRandKey(startKey, endKey []byte, maxLen int) {
}
}

//nolint:gosec
func randKey(startKey, endKey []byte, maxLen int) []byte {
Retry:
for { // Regenerate on fail
Expand Down Expand Up @@ -213,6 +214,7 @@ Retry:
}
}

//nolint:gosec
func randValue() []byte {
result := make([]byte, 0, 512)
for i := 0; i < 512; i++ {
Expand Down

0 comments on commit a5435cd

Please sign in to comment.