Skip to content

Commit

Permalink
misc(ticdc): add more linters and fix issues found by misspell (#3898)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden authored Dec 23, 2021
1 parent 9f3a9d0 commit 6de2c10
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 19 deletions.
32 changes: 32 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ linters:
- unparam
- revive
- depguard
- misspell
- ineffassign
- typecheck
- varcheck
- unused
- structcheck
- deadcode
- gosimple
- goimports
- errcheck
- staticcheck
- stylecheck
- gosec
- asciicheck
- exportloopref
- makezero

linters-settings:
revive:
Expand Down Expand Up @@ -40,3 +56,19 @@ linters-settings:
# specify an error message to output when a blacklisted package is used
- log: "logging is allowed only by pingcap/log"
- github.com/juju/errors: "error handling is allowed only by pingcap/errors"
staticcheck:
checks: ["S1002","S1004","S1007","S1009","S1010","S1012","S1019","S1020","S1021","S1024","S1030","SA2*","SA3*","SA4009","SA5*","SA6000","SA6001","SA6005", "-SA2002"]
stylecheck:
checks: ["-ST1003"]
gosec:
excludes:
- G404
- G601

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- gosec
- makezero
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ tidy:

# TODO: Unified cdc and dm config.
check-static: tools/bin/golangci-lint
tools/bin/golangci-lint run --timeout 10m0s --skip-files kv_gen --skip-dirs dm
tools/bin/golangci-lint run --timeout 10m0s --skip-files kv_gen --skip-dirs dm,tests
cd dm && ../tools/bin/golangci-lint run --timeout 10m0s

check: check-copyright fmt check-static tidy terror_check errdoc check-leaktest-added check-merge-conflicts
Expand Down
4 changes: 2 additions & 2 deletions cdc/kv/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,7 @@ func (s *clientSuite) TestOutOfRegionRangeEvent(c *check.C) {
}

// TestResolveLockNoCandidate tests the resolved ts manager can work normally
// when no region exceeds reslove lock interval, that is what candidate means.
// when no region exceeds resolve lock interval, that is what candidate means.
func (s *clientSuite) TestResolveLockNoCandidate(c *check.C) {
defer testleak.AfterTest(c)()
defer s.TearDownTest(c)
Expand Down Expand Up @@ -2701,7 +2701,7 @@ func (s *clientSuite) TestResolveLockNoCandidate(c *check.C) {
case event := <-eventCh:
c.Assert(event.Resolved, check.NotNil)
case <-time.After(time.Second):
c.Error("resovled event not received")
c.Error("resolved event not received")
}
// will sleep 6s totally, to ensure resolve lock fired once
time.Sleep(time.Second)
Expand Down
4 changes: 2 additions & 2 deletions cdc/kv/region_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (w *regionWorker) resolveLock(ctx context.Context) error {
zap.Duration("duration", sinceLastResolvedTs), zap.Duration("since last event", sinceLastResolvedTs))
return errReconnect
}
// Only resolve lock if the resovled-ts keeps unchanged for
// Only resolve lock if the resolved-ts keeps unchanged for
// more than resolveLockPenalty times.
if rts.ts.penalty < resolveLockPenalty {
if lastResolvedTs > rts.ts.resolvedTs {
Expand Down Expand Up @@ -510,7 +510,7 @@ func (w *regionWorker) eventHandler(ctx context.Context) error {
// Principle: events from the same region must be processed linearly.
//
// When buffered events exceed high watermark, we start to use worker
// pool to improve throughtput, and we need a mechanism to quit worker
// pool to improve throughput, and we need a mechanism to quit worker
// pool when buffered events are less than low watermark, which means
// we should have a way to know whether events sent to the worker pool
// are all processed.
Expand Down
4 changes: 2 additions & 2 deletions cdc/model/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type RegionFeedEvent struct {
Val *RawKVEntry
Resolved *ResolvedSpan

// Additonal debug info
// Additional debug info
RegionID uint64
}

Expand Down Expand Up @@ -79,7 +79,7 @@ type RawKVEntry struct {
// Commit or resolved TS
CRTs uint64 `msg:"crts"`

// Additonal debug info
// Additional debug info
RegionID uint64 `msg:"region_id"`
}

Expand Down
2 changes: 1 addition & 1 deletion cdc/processor/pipeline/sorter.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (n *sorterNode) Receive(ctx pipeline.NodeContext) error {
!redo.IsConsistentEnabled(n.replConfig.Consistent.Level) {
// Do not send resolved ts events that is larger than
// barrier ts.
// When DDL puller stall, resolved events that outputed by
// When DDL puller stall, resolved events that outputted by
// sorter may pile up in memory, as they have to wait DDL.
//
// Disabled if redolog is on, it requires sink reports
Expand Down
2 changes: 1 addition & 1 deletion cdc/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ func (p *processor) pushResolvedTs2Table() {
if schemaResolvedTs < resolvedTs {
// Do not update barrier ts that is larger than
// DDL puller's resolved ts.
// When DDL puller stall, resolved events that outputed by sorter
// When DDL puller stall, resolved events that outputted by sorter
// may pile up in memory, as they have to wait DDL.
resolvedTs = schemaResolvedTs
}
Expand Down
2 changes: 1 addition & 1 deletion cdc/sink/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestSplitResolvedTxn(test *testing.T) {
input []*model.RowChangedEvent
resolvedTsMap map[model.TableID]uint64
expected map[model.TableID][]*model.SingleTableTxn
}{{{ // Testing basic transaction collocation, no txns with the same committs
}{{{ // Testing basic transaction collocation, no txns with the same commitTs
input: []*model.RowChangedEvent{
{StartTs: 1, CommitTs: 5, Table: &model.TableName{TableID: 1}},
{StartTs: 1, CommitTs: 5, Table: &model.TableName{TableID: 1}},
Expand Down
2 changes: 1 addition & 1 deletion cdc/sorter/encoding/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func EncodeTsKey(uniqueID uint32, tableID uint64, ts uint64) []byte {
return append(buf, uint64Buf[:]...)
}

// EncodeKey encodes a key accroding to event.
// EncodeKey encodes a key according to event.
// Format: uniqueID, tableID, CRTs, startTs, Put/Delete, Key.
func EncodeKey(uniqueID uint32, tableID uint64, event *model.PolymorphicEvent) []byte {
if event.RawKV == nil {
Expand Down
2 changes: 1 addition & 1 deletion cdc/sorter/leveldb/table_sorter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ func TestPoll(t *testing.T) {
expectMaxResolvedTs: 2,
expectExhaustedRTs: 2,
},
// exhaustedResolvedTs must advance if all resolved events are outputed.
// exhaustedResolvedTs must advance if all resolved events are outputted.
// Output: CRTs 2, StartTs 1, keys (0|1|2)
{
inputEvents: []*model.PolymorphicEvent{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/cli_changefeed_cyclic_create_marktables.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (o *cyclicCreateMarktablesOptions) getUpstreamCredential() *security.Creden
// flags related to template printing to it.
func (o *cyclicCreateMarktablesOptions) addFlags(cmd *cobra.Command) {
cmd.PersistentFlags().Uint64Var(&o.startTs, "start-ts", 0, "Start ts of changefeed")
cmd.PersistentFlags().StringVar(&o.cyclicUpstreamDSN, "cyclic-upstream-dsn", "", "(Expremental) Upsteam TiDB DSN in the form of [user[:password]@][net[(addr)]]/")
cmd.PersistentFlags().StringVar(&o.cyclicUpstreamDSN, "cyclic-upstream-dsn", "", "(Expremental) Upstream TiDB DSN in the form of [user[:password]@][net[(addr)]]/")
cmd.PersistentFlags().StringVar(&o.upstreamSslCaPath, "cyclic-upstream-ssl-ca", "", "CA certificate path for TLS connection")
cmd.PersistentFlags().StringVar(&o.upstreamSslCertPath, "cyclic-upstream-ssl-cert", "", "Certificate path for TLS connection")
cmd.PersistentFlags().StringVar(&o.upstreamSslKeyPath, "cyclic-upstream-ssl-key", "", "Private key path for TLS connection")
Expand Down
2 changes: 1 addition & 1 deletion pkg/cyclic/mark/mark.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func CreateMarkTables(ctx context.Context, upstreamDSN string, upstreamCred *sec
db, err := sql.Open("mysql", upstreamDSN)
if err != nil {
return cerror.WrapError(cerror.ErrCreateMarkTableFailed,
errors.Annotate(err, "Open upsteam database connection failed"))
errors.Annotate(err, "Open upstream database connection failed"))
}
err = db.PingContext(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cyclic/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.

// Package cyclic contains scaffolds for implementing cyclic replication
// among mutliple TiDB clusters/MySQL. It uses a mark table to identify and
// among multiple TiDB clusters/MySQL. It uses a mark table to identify and
// filter duplicate DMLs.
// CDC needs to watch DMLs to mark tables and ignore all DDLs to mark tables.
//
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Node interface {
// you can call `ctx.SendToNextNode(msg)` to send the message to the next node
Receive(ctx NodeContext) error

// Destory frees the resources in this node
// Destroy frees the resources in this node
// you can call `ctx.SendToNextNode(msg)` to send the message to the next node
// but it will return nil if you try to call the `ctx.Message()`
Destroy(ctx NodeContext) error
Expand Down
6 changes: 3 additions & 3 deletions pkg/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (e echoNode) Destroy(ctx NodeContext) error {
ctx.SendToNextNode(PolymorphicEventMessage(&model.PolymorphicEvent{
Row: &model.RowChangedEvent{
Table: &model.TableName{
Schema: "destory function is called in echo node",
Schema: "destroy function is called in echo node",
},
},
}))
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestPipelineUsage(t *testing.T) {
PolymorphicEventMessage(&model.PolymorphicEvent{
Row: &model.RowChangedEvent{
Table: &model.TableName{
Schema: "destory function is called in echo node",
Schema: "destroy function is called in echo node",
},
},
}),
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestPipelineAppendNode(t *testing.T) {
PolymorphicEventMessage(&model.PolymorphicEvent{
Row: &model.RowChangedEvent{
Table: &model.TableName{
Schema: "destory function is called in echo node",
Schema: "destroy function is called in echo node",
},
},
}),
Expand Down

0 comments on commit 6de2c10

Please sign in to comment.