Skip to content

Commit

Permalink
*: enable part revive for all code (pingcap#36703)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Aug 1, 2022
1 parent 4607cba commit 158ba1a
Show file tree
Hide file tree
Showing 258 changed files with 1,186 additions and 1,184 deletions.
163 changes: 89 additions & 74 deletions DEPS.bzl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ bazel_coverage_test: failpoint-enable bazel_ci_prepare

bazel_build: bazel_ci_prepare
mkdir -p bin
bazel --output_user_root=/home/jenkins/.tidb/tmp build -k --config=ci //tidb-server/... //br/cmd/... //cmd/... //util/... //dumpling/cmd/... //tidb-binlog/... --//build:with_nogo_flag=true
bazel --output_user_root=/home/jenkins/.tidb/tmp build -k --config=ci //... --//build:with_nogo_flag=true
cp bazel-out/k8-fastbuild/bin/tidb-server/tidb-server_/tidb-server ./bin
cp bazel-out/k8-fastbuild/bin/cmd/importer/importer_/importer ./bin
cp bazel-out/k8-fastbuild/bin/tidb-server/tidb-server-check_/tidb-server-check ./bin
Expand Down
1 change: 0 additions & 1 deletion bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,6 @@ func getEvolveParameters(sctx sessionctx.Context) (time.Duration, time.Time, tim
startTime, err := time.ParseInLocation(variable.FullDayTimeFormat, startTimeStr, time.UTC)
if err != nil {
return 0, time.Time{}, time.Time{}, err

}
endTime, err := time.ParseInLocation(variable.FullDayTimeFormat, endTimeStr, time.UTC)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,8 @@ func (bc *Client) BackupRanges(
// The error due to context cancel, stack trace is meaningless, the stack shall be suspended (also clear)
if errors.Cause(err) == context.Canceled {
return errors.SuspendStack(err)
} else {
return errors.Trace(err)
}
return errors.Trace(err)
}
return nil
})
Expand Down Expand Up @@ -1072,10 +1071,9 @@ func SendBackup(
}
logutil.CL(ctx).Error("fail to backup", zap.Uint64("StoreID", storeID), zap.Int("retry", retry))
return berrors.ErrFailedToConnect.Wrap(errBackup).GenWithStack("failed to create backup stream to store %d", storeID)
} else {
// finish backup
break
}
// finish backup
break
}
return nil
}
Expand Down
1 change: 0 additions & 1 deletion br/pkg/backup/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func (s *schemaInfo) encodeToSchema() (*backuppb.Schema, error) {
if err != nil {
return nil, errors.Trace(err)
}

}
var statsBytes []byte
if s.stats != nil {
Expand Down
1 change: 0 additions & 1 deletion br/pkg/glue/console_glue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func testPrettyString(t *testing.T) {
}
}
}

}

func testPrettyStringSlicing(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions br/pkg/gluetidb/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func (gs *tidbSession) CreateDatabase(ctx context.Context, schema *model.DBInfo)
schema.Charset = mysql.DefaultCharset
}
return d.CreateSchemaWithInfo(gs.se, schema, ddl.OnExistIgnore)

}

// CreatePlacementPolicy implements glue.Session.
Expand Down Expand Up @@ -341,7 +340,6 @@ func (s *mockSession) ExecuteInternal(ctx context.Context, sql string, args ...i
func (s *mockSession) CreateDatabase(ctx context.Context, schema *model.DBInfo) error {
log.Fatal("unimplemented CreateDatabase for mock session")
return nil

}

// CreatePlacementPolicy implements glue.Session.
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/lightning/backend/kv/kv2sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (t *TableKVDecoder) IterRawIndexKeys(h kv.Handle, rawRow []byte, fn func([]
row[i] = types.GetMinValue(&col.FieldType)
}
}
if err, _ := evaluateGeneratedColumns(t.se, row, t.tbl.Cols(), t.genCols); err != nil {
if _, err := evaluateGeneratedColumns(t.se, row, t.tbl.Cols(), t.genCols); err != nil {
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions br/pkg/lightning/backend/kv/sql2kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,17 @@ func KvPairsFromRow(row Row) []common.KvPair {
return row.(*KvPairs).pairs
}

func evaluateGeneratedColumns(se *session, record []types.Datum, cols []*table.Column, genCols []genCol) (err error, errCol *model.ColumnInfo) {
func evaluateGeneratedColumns(se *session, record []types.Datum, cols []*table.Column, genCols []genCol) (errCol *model.ColumnInfo, err error) {
mutRow := chunk.MutRowFromDatums(record)
for _, gc := range genCols {
col := cols[gc.index].ToInfo()
evaluated, err := gc.expr.Eval(mutRow.ToRow())
if err != nil {
return err, col
return col, err
}
value, err := table.CastValue(se, evaluated, col, false, false)
if err != nil {
return err, col
return col, err
}
mutRow.SetDatum(gc.index, value)
record[gc.index] = value
Expand Down Expand Up @@ -426,7 +426,7 @@ func (kvcodec *tableKVEncoder) Encode(
}

if len(kvcodec.genCols) > 0 {
if err, errCol := evaluateGeneratedColumns(kvcodec.se, record, cols, kvcodec.genCols); err != nil {
if errCol, err := evaluateGeneratedColumns(kvcodec.se, record, cols, kvcodec.genCols); err != nil {
return nil, logEvalGenExprFailed(logger, row, errCol, err)
}
}
Expand Down
1 change: 0 additions & 1 deletion br/pkg/lightning/backend/kv/sql2kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ func TestEncodeMissingAutoValue(t *testing.T) {
require.NoError(t, err)
require.Equalf(t, pairsExpect, pairs, "test table info: %+v", testTblInfo)
require.Equalf(t, rowID, tbl.Allocators(lkv.GetEncoderSe(encoder)).Get(testTblInfo.AllocType).Base(), "test table info: %+v", testTblInfo)

}
}

Expand Down
2 changes: 1 addition & 1 deletion br/pkg/lightning/backend/local/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ func (i dbSSTIngester) mergeSSTs(metas []*sstMeta, dir string) (*sstMeta, error)
return nil, err
}
if key == nil {
return nil, errors.New("all ssts are empty!")
return nil, errors.New("all ssts are empty")
}
newMeta.minKey = append(newMeta.minKey[:0], key...)
lastKey := make([]byte, 0)
Expand Down
1 change: 0 additions & 1 deletion br/pkg/lightning/backend/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@ func testMergeSSTs(t *testing.T, kvs [][]common.KvPair, meta *sstMeta) {
func TestMergeSSTs(t *testing.T) {
kvs := make([][]common.KvPair, 0, 5)
for i := 0; i < 5; i++ {

var pairs []common.KvPair
for j := 0; j < 10; j++ {
var kv common.KvPair
Expand Down
39 changes: 19 additions & 20 deletions br/pkg/lightning/backend/local/localhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,21 @@ func (local *local) SplitAndScatterRegionByRanges(
err = multierr.Append(err, err1)
syncLock.Unlock()
break
} else {
log.FromContext(ctx).Info("batch split region", zap.Uint64("region_id", splitRegion.Region.Id),
zap.Int("keys", endIdx-startIdx), zap.Binary("firstKey", keys[startIdx]),
zap.Binary("end", keys[endIdx-1]))
slices.SortFunc(newRegions, func(i, j *split.RegionInfo) bool {
return bytes.Compare(i.Region.StartKey, j.Region.StartKey) < 0
})
syncLock.Lock()
scatterRegions = append(scatterRegions, newRegions...)
syncLock.Unlock()
// the region with the max start key is the region need to be further split.
if bytes.Compare(splitRegion.Region.StartKey, newRegions[len(newRegions)-1].Region.StartKey) < 0 {
splitRegion = newRegions[len(newRegions)-1]
}
}
log.FromContext(ctx).Info("batch split region", zap.Uint64("region_id", splitRegion.Region.Id),
zap.Int("keys", endIdx-startIdx), zap.Binary("firstKey", keys[startIdx]),
zap.Binary("end", keys[endIdx-1]))
slices.SortFunc(newRegions, func(i, j *split.RegionInfo) bool {
return bytes.Compare(i.Region.StartKey, j.Region.StartKey) < 0
})
syncLock.Lock()
scatterRegions = append(scatterRegions, newRegions...)
syncLock.Unlock()
// the region with the max start key is the region need to be further split.
if bytes.Compare(splitRegion.Region.StartKey, newRegions[len(newRegions)-1].Region.StartKey) < 0 {
splitRegion = newRegions[len(newRegions)-1]
}

batchKeySize = 0
startIdx = endIdx
}
Expand Down Expand Up @@ -319,13 +319,12 @@ func (local *local) SplitAndScatterRegionByRanges(

if len(retryKeys) == 0 {
break
} else {
slices.SortFunc(retryKeys, func(i, j []byte) bool {
return bytes.Compare(i, j) < 0
})
minKey = codec.EncodeBytes([]byte{}, retryKeys[0])
maxKey = codec.EncodeBytes([]byte{}, nextKey(retryKeys[len(retryKeys)-1]))
}
slices.SortFunc(retryKeys, func(i, j []byte) bool {
return bytes.Compare(i, j) < 0
})
minKey = codec.EncodeBytes([]byte{}, retryKeys[0])
maxKey = codec.EncodeBytes([]byte{}, nextKey(retryKeys[len(retryKeys)-1]))
}
if err != nil {
return errors.Trace(err)
Expand Down
1 change: 0 additions & 1 deletion br/pkg/lightning/backend/local/localhelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ func TestStoreWriteLimiter(t *testing.T) {
// In theory, gotTokens should be less than or equal to maxTokens.
// But we allow a little of error to avoid the test being flaky.
require.LessOrEqual(t, gotTokens, maxTokens+1)

}(uint64(i))
}
wg.Wait()
Expand Down
1 change: 0 additions & 1 deletion br/pkg/lightning/backend/tidb/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ func (b *targetInfoGetter) FetchRemoteTableModels(ctx context.Context, schemaNam
}
}
}

}
return nil
})
Expand Down
1 change: 0 additions & 1 deletion br/pkg/lightning/checkpoints/checkpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ func TestCheckpointMarshallUnmarshall(t *testing.T) {
}

func TestSeparateCompletePath(t *testing.T) {

testCases := []struct {
complete string
expectFileName string
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/lightning/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ func NormalizeOrWrapErr(rfcErr *errors.Error, err error, args ...interface{}) er
normalizedErr := NormalizeError(err)
if berrors.Is(normalizedErr, ErrUnknown) {
return rfcErr.Wrap(err).GenWithStackByArgs(args...)
} else {
return normalizedErr
}
return normalizedErr
}
3 changes: 1 addition & 2 deletions br/pkg/lightning/mydump/parquet_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,8 @@ func getDatumLen(v reflect.Value) int {
if v.Kind() == reflect.Ptr {
if v.IsNil() {
return 0
} else {
return getDatumLen(v.Elem())
}
return getDatumLen(v.Elem())
}
if v.Kind() == reflect.String {
return len(v.String())
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/lightning/mydump/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ func MakeTableRegions(
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for info := range fileChan {
regions, sizes, err := makeSourceFileRegion(execCtx, meta, info, columns, cfg, ioWorkers, store)
select {
case resultChan <- fileRegionRes{info: info, regions: regions, sizes: sizes, err: err}:
case <-ctx.Done():
break
return
}
if err != nil {
log.FromContext(ctx).Error("make source file region error", zap.Error(err), zap.String("file_path", info.FileMeta.Path))
break
}
}
wg.Done()
}()
}

Expand Down
3 changes: 1 addition & 2 deletions br/pkg/lightning/restore/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ func TestDoChecksumWithTikv(t *testing.T) {
if i >= maxErrorRetryCount {
require.Equal(t, mockChecksumKVClientErr, errors.Cause(err))
continue
} else {
require.NoError(t, err)
}
require.NoError(t, err)

// after checksum, safepint should be small than start ts
ts := pdClient.currentSafePoint()
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/lightning/restore/chunk_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (s *chunkRestoreSuite) TestEncodeLoopDeliverLimit() {
if !ok {
break
}
count += 1
count++
if count <= 3 {
require.Len(s.T(), kvs, 1)
}
Expand Down
14 changes: 5 additions & 9 deletions br/pkg/lightning/restore/get_pre_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,12 @@ func (p *PreRestoreInfoGetterImpl) ReadFirstNRowsByFileMeta(ctx context.Context,
if err != nil {
if errors.Cause(err) != io.EOF {
return nil, nil, errors.Trace(err)
} else {
break
}
break
}
rows = append(rows, parser.LastRow().Row)
}
return parser.Columns(), rows, nil

}

// EstimateSourceDataSize estimates the datasize to generate during the import as well as some other sub-informaiton.
Expand Down Expand Up @@ -598,7 +596,6 @@ func (p *PreRestoreInfoGetterImpl) EstimateSourceDataSize(ctx context.Context) (
HasUnsortedBigTables: (unSortedBigTableCount > 0),
}
return result, nil

}

// sampleDataFromTable samples the source data file to get the extra data ratio for the index
Expand Down Expand Up @@ -713,7 +710,7 @@ outloop:
return 0.0, false, errors.Trace(err)
}
lastRow := parser.LastRow()
rowCount += 1
rowCount++

var dataChecksum, indexChecksum verification.KVChecksum
kvs, encodeErr := kvEncoder.Encode(logTask.Logger, lastRow.Row, lastRow.RowID, columnPermutation, sampleFile.Path, offset)
Expand All @@ -725,9 +722,8 @@ outloop:
}
if rowCount < maxSampleRowCount {
continue
} else {
break
}
break
}
if isRowOrdered {
kvs.ClassifyAndAppend(&dataKVs, &dataChecksum, &indexKVs, &indexChecksum)
Expand Down Expand Up @@ -794,8 +790,8 @@ func (p *PreRestoreInfoGetterImpl) FetchRemoteTableModels(ctx context.Context, s
// CheckVersionRequirements performs the check whether the target satisfies the version requirements.
// It implements the PreRestoreInfoGetter interface.
// Mydump database metas are retrieved from the context.
func (g *PreRestoreInfoGetterImpl) CheckVersionRequirements(ctx context.Context) error {
return g.targetInfoGetter.CheckVersionRequirements(ctx)
func (p *PreRestoreInfoGetterImpl) CheckVersionRequirements(ctx context.Context) error {
return p.targetInfoGetter.CheckVersionRequirements(ctx)
}

// GetTargetSysVariablesForImport gets some important systam variables for importing on the target.
Expand Down
1 change: 0 additions & 1 deletion br/pkg/lightning/restore/meta_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ func (m *dbTableMetaMgr) AllocTableRowIDs(ctx context.Context, rawRowIDMax int64
ck := verify.MakeKVChecksum(remoteCk.TotalBytes, remoteCk.TotalKVs, remoteCk.Checksum)
checksum = &ck
}

}

if checksum != nil {
Expand Down
6 changes: 1 addition & 5 deletions br/pkg/lightning/restore/meta_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ func newTableRestore(t *testing.T, kvStore kv.Storage) *TableRestore {
if err := m.CreateDatabase(&model.DBInfo{ID: dbInfo.ID}); err != nil {
return err
}
if err := m.CreateTableOrView(dbInfo.ID, ti.Core); err != nil {
return err
}
return nil
return m.CreateTableOrView(dbInfo.ID, ti.Core)
})
require.NoError(t, err)

Expand Down Expand Up @@ -426,7 +423,6 @@ func TestCheckTasksExclusively(t *testing.T) {
return newTasks, nil
})
require.NoError(t, err)

}

type testChecksumMgr struct {
Expand Down
4 changes: 1 addition & 3 deletions br/pkg/lightning/restore/precheck_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,8 @@ func (ci *checkpointCheckItem) checkpointIsValid(ctx context.Context, tableInfo
// there is no checkpoint
log.FromContext(ctx).Debug("no checkpoint detected", zap.String("table", uniqueName))
return nil, nil
} else {
return nil, errors.Trace(err)
}
return nil, errors.Trace(err)
}
// if checkpoint enable and not missing, we skip the check table empty progress.
if tableCheckPoint.Status <= checkpoints.CheckpointStatusMissing {
Expand Down Expand Up @@ -1142,7 +1141,6 @@ loop:
case <-gCtx.Done():
break loop
}

}
}
close(ch)
Expand Down
1 change: 0 additions & 1 deletion br/pkg/lightning/restore/precheck_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func (s *precheckImplSuite) SetupTest() {
s.cfg = config.NewConfig()
s.cfg.TikvImporter.Backend = config.BackendLocal
s.Require().NoError(s.setMockImportData(nil))

}

func (s *precheckImplSuite) setMockImportData(mockDataMap map[string]*mock.MockDBSourceData) error {
Expand Down
Loading

0 comments on commit 158ba1a

Please sign in to comment.