diff --git a/.golangci.yml b/.golangci.yml index 870ee6d43d9..a6c7a6830d5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,36 +2,9 @@ linters: enable: - unconvert - unparam -<<<<<<< HEAD -======= - - revive - depguard linters-settings: - revive: - ignore-generated-header: false - severity: error - confidence: 0.8 - error-code: -1 - warning-code: -1 - rules: - - name: blank-imports - - name: context-as-argument - - name: dot-imports - - name: error-return - - name: error-strings - - name: error-naming - - name: exported - - name: if-return - - name: var-naming - - name: package-comments - - name: range - - name: receiver-naming - - name: indent-error-flow - - name: superfluous-else - - name: modifies-parameter - - name: unreachable-code - depguard: list-type: blacklist include-go-root: false @@ -42,4 +15,3 @@ 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" ->>>>>>> 2ed02366d (pkg,cdc: do not use log package (#3902)) diff --git a/cdc/processor/pipeline/mounter.go b/cdc/processor/pipeline/mounter.go index 1bfc94b43c4..2e156b9cdbd 100644 --- a/cdc/processor/pipeline/mounter.go +++ b/cdc/processor/pipeline/mounter.go @@ -15,12 +15,12 @@ package pipeline import ( "context" - "log" "sync" "time" "github.com/edwingeng/deque" "github.com/pingcap/failpoint" + "github.com/pingcap/log" "github.com/pingcap/ticdc/cdc/model" "github.com/pingcap/ticdc/pkg/notify" "github.com/pingcap/ticdc/pkg/pipeline" diff --git a/cdc/scheduler/util/table_set.go b/cdc/scheduler/util/table_set.go deleted file mode 100644 index 963f7a30b1d..00000000000 --- a/cdc/scheduler/util/table_set.go +++ /dev/null @@ -1,211 +0,0 @@ -// 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, -// See the License for the specific language governing permissions and -// limitations under the License. - -package util - -import ( - "github.com/pingcap/log" - "github.com/pingcap/ticdc/cdc/model" - "go.uber.org/zap" -) - -// TableSet provides a data structure to store the tables' states for the -// scheduler. -type TableSet struct { - // all tables' records - tableIDMap map[model.TableID]*TableRecord - - // a non-unique index to facilitate looking up tables - // assigned to a given capture. - captureIndex map[model.CaptureID]map[model.TableID]*TableRecord -} - -// TableRecord is a record to be inserted into TableSet. -type TableRecord struct { - TableID model.TableID - CaptureID model.CaptureID - Status TableStatus -} - -// Clone returns a copy of the TableSet. -// This method is future-proof in case we add -// something not trivially copyable. -func (r *TableRecord) Clone() *TableRecord { - return &TableRecord{ - TableID: r.TableID, - CaptureID: r.CaptureID, - Status: r.Status, - } -} - -// TableStatus is a type representing the table's replication status. -type TableStatus int32 - -const ( - AddingTable = TableStatus(iota) + 1 - RemovingTable - RunningTable -) - -// NewTableSet creates a new TableSet. -func NewTableSet() *TableSet { - return &TableSet{ - tableIDMap: map[model.TableID]*TableRecord{}, - captureIndex: map[model.CaptureID]map[model.TableID]*TableRecord{}, - } -} - -// AddTableRecord inserts a new TableRecord. -// It returns true if it succeeds. Returns false if there is a duplicate. -func (s *TableSet) AddTableRecord(record *TableRecord) (successful bool) { - if _, ok := s.tableIDMap[record.TableID]; ok { - // duplicate tableID - return false - } - recordCloned := record.Clone() - s.tableIDMap[record.TableID] = recordCloned - - captureIndexEntry := s.captureIndex[record.CaptureID] - if captureIndexEntry == nil { - captureIndexEntry = make(map[model.TableID]*TableRecord) - s.captureIndex[record.CaptureID] = captureIndexEntry - } - - captureIndexEntry[record.TableID] = recordCloned - return true -} - -// UpdateTableRecord updates an existing TableRecord. -// All modifications to a table's status should be done by this method. -func (s *TableSet) UpdateTableRecord(record *TableRecord) (successful bool) { - oldRecord, ok := s.tableIDMap[record.TableID] - if !ok { - // table does not exist - return false - } - - // If there is no need to modify the CaptureID, we simply - // update the record. - if record.CaptureID == oldRecord.CaptureID { - recordCloned := record.Clone() - s.tableIDMap[record.TableID] = recordCloned - s.captureIndex[record.CaptureID][record.TableID] = recordCloned - return true - } - - // If the CaptureID is changed, we do a proper RemoveTableRecord followed - // by AddTableRecord. - if record.CaptureID != oldRecord.CaptureID { - if ok := s.RemoveTableRecord(record.TableID); !ok { - log.Panic("unreachable", zap.Any("record", record)) - } - if ok := s.AddTableRecord(record); !ok { - log.Panic("unreachable", zap.Any("record", record)) - } - } - return true -} - -// GetTableRecord tries to obtain a record with the specified tableID. -func (s *TableSet) GetTableRecord(tableID model.TableID) (*TableRecord, bool) { - rec, ok := s.tableIDMap[tableID] - if ok { - return rec.Clone(), ok - } - return nil, false -} - -// RemoveTableRecord removes the record with tableID. Returns false -// if none exists. -func (s *TableSet) RemoveTableRecord(tableID model.TableID) bool { - record, ok := s.tableIDMap[tableID] - if !ok { - return false - } - delete(s.tableIDMap, record.TableID) - - captureIndexEntry, ok := s.captureIndex[record.CaptureID] - if !ok { - log.Panic("unreachable", zap.Int64("table-id", tableID)) - } - delete(captureIndexEntry, record.TableID) - if len(captureIndexEntry) == 0 { - delete(s.captureIndex, record.CaptureID) - } - return true -} - -// RemoveTableRecordByCaptureID removes all table records associated with -// captureID. -func (s *TableSet) RemoveTableRecordByCaptureID(captureID model.CaptureID) []*TableRecord { - captureIndexEntry, ok := s.captureIndex[captureID] - if !ok { - return nil - } - - var ret []*TableRecord - for tableID, record := range captureIndexEntry { - delete(s.tableIDMap, tableID) - // Since the record has been removed, - // there is no need to clone it before returning. - ret = append(ret, record) - } - delete(s.captureIndex, captureID) - return ret -} - -// CountTableByCaptureID counts the number of tables associated with the captureID. -func (s *TableSet) CountTableByCaptureID(captureID model.CaptureID) int { - return len(s.captureIndex[captureID]) -} - -// GetDistinctCaptures counts distinct captures with tables. -func (s *TableSet) GetDistinctCaptures() []model.CaptureID { - var ret []model.CaptureID - for captureID := range s.captureIndex { - ret = append(ret, captureID) - } - return ret -} - -// GetAllTables returns all stored information on all tables. -func (s *TableSet) GetAllTables() map[model.TableID]*TableRecord { - ret := make(map[model.TableID]*TableRecord) - for tableID, record := range s.tableIDMap { - ret[tableID] = record.Clone() - } - return ret -} - -// GetAllTablesGroupedByCaptures returns all stored information grouped by associated CaptureID. -func (s *TableSet) GetAllTablesGroupedByCaptures() map[model.CaptureID]map[model.TableID]*TableRecord { - ret := make(map[model.CaptureID]map[model.TableID]*TableRecord) - for captureID, tableIDMap := range s.captureIndex { - tableIDMapCloned := make(map[model.TableID]*TableRecord) - for tableID, record := range tableIDMap { - tableIDMapCloned[tableID] = record.Clone() - } - ret[captureID] = tableIDMapCloned - } - return ret -} - -// CountTableByStatus counts the number of tables with the given status. -func (s *TableSet) CountTableByStatus(status TableStatus) (count int) { - for _, record := range s.tableIDMap { - if record.Status == status { - count++ - } - } - return -} diff --git a/cdc/sink/codec/canal.go b/cdc/sink/codec/canal.go index 6a3eff052e4..89fc7f4a4eb 100644 --- a/cdc/sink/codec/canal.go +++ b/cdc/sink/codec/canal.go @@ -20,13 +20,10 @@ import ( "github.com/golang/protobuf/proto" // nolint:staticcheck "github.com/pingcap/errors" -<<<<<<< HEAD + "github.com/pingcap/log" mm "github.com/pingcap/parser/model" "github.com/pingcap/parser/mysql" parser_types "github.com/pingcap/parser/types" -======= - "github.com/pingcap/log" ->>>>>>> 2ed02366d (pkg,cdc: do not use log package (#3902)) "github.com/pingcap/ticdc/cdc/model" cerror "github.com/pingcap/ticdc/pkg/errors" canal "github.com/pingcap/ticdc/proto/canal" diff --git a/integration/tests/case_date_time.go b/integration/tests/case_date_time.go index d318f7761ab..ac060b94036 100644 --- a/integration/tests/case_date_time.go +++ b/integration/tests/case_date_time.go @@ -17,18 +17,11 @@ import ( "errors" "time" -<<<<<<< HEAD:integration/tests/case_date_time.go + "github.com/pingcap/log" "github.com/pingcap/ticdc/integration/framework" "github.com/pingcap/ticdc/integration/framework/avro" "github.com/pingcap/ticdc/integration/framework/canal" "github.com/pingcap/ticdc/integration/framework/mysql" -======= - "github.com/pingcap/log" - "github.com/pingcap/ticdc/tests/mq_protocol_tests/framework" - "github.com/pingcap/ticdc/tests/mq_protocol_tests/framework/avro" - "github.com/pingcap/ticdc/tests/mq_protocol_tests/framework/canal" - "github.com/pingcap/ticdc/tests/mq_protocol_tests/framework/mysql" ->>>>>>> 2ed02366d (pkg,cdc: do not use log package (#3902)):tests/mq_protocol_tests/cases/case_date_time.go ) // DateTimeCase is base impl of test case for different types data diff --git a/pkg/context/context.go b/pkg/context/context.go index af2261d688e..fe129cd907a 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -17,17 +17,12 @@ import ( "context" "time" -<<<<<<< HEAD - "github.com/pingcap/ticdc/pkg/pdtime" - - "github.com/pingcap/ticdc/pkg/version" - -======= "github.com/pingcap/log" ->>>>>>> 2ed02366d (pkg,cdc: do not use log package (#3902)) "github.com/pingcap/ticdc/cdc/kv" "github.com/pingcap/ticdc/cdc/model" "github.com/pingcap/ticdc/pkg/config" + "github.com/pingcap/ticdc/pkg/pdtime" + "github.com/pingcap/ticdc/pkg/version" tidbkv "github.com/pingcap/tidb/kv" "github.com/tikv/client-go/v2/oracle" pd "github.com/tikv/pd/client" diff --git a/pkg/context/context_test.go b/pkg/context/context_test.go index 08c0886c338..b0caee01c3f 100644 --- a/pkg/context/context_test.go +++ b/pkg/context/context_test.go @@ -136,11 +136,7 @@ func (s *contextSuite) TestThrowPanic(c *check.C) { defer testleak.AfterTest(c)() defer func() { panicMsg := recover() -<<<<<<< HEAD - c.Assert(panicMsg, check.Equals, "an error has escaped, please report a bug{error 26 0 mock error}") -======= - require.Equal(t, panicMsg, "an error has escaped, please report a bug") ->>>>>>> 2ed02366d (pkg,cdc: do not use log package (#3902)) + c.Assert(panicMsg, check.Equals, "an error has escaped, please report a bug") }() stdCtx := context.Background() ctx := NewContext(stdCtx, &GlobalVars{})