From c819b094356c23d2d9d387ffd5a0b67cb9ecab61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E6=89=8B=E6=8E=89=E5=8C=85=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E5=B8=88?= Date: Wed, 24 Mar 2021 11:53:37 +0800 Subject: [PATCH] =?UTF-8?q?*=EF=BC=9A=20remove=20redundant=20type=20conver?= =?UTF-8?q?sions=20(#1526)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debug-tools/binlog-event-blackhole/fetcher.go | 2 +- dm/master/server.go | 2 +- pkg/binlog/event/event.go | 4 ++-- pkg/binlog/event/event_test.go | 4 ++-- pkg/utils/relay.go | 2 +- relay/writer/file_util_test.go | 2 +- syncer/db_test.go | 2 +- syncer/dml.go | 4 ++-- syncer/syncer_test.go | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/debug-tools/binlog-event-blackhole/fetcher.go b/debug-tools/binlog-event-blackhole/fetcher.go index 56a8a3ec5b..25bb7bf82c 100644 --- a/debug-tools/binlog-event-blackhole/fetcher.go +++ b/debug-tools/binlog-event-blackhole/fetcher.go @@ -142,7 +142,7 @@ func readEventsWithoutGoMySQL(ctx context.Context, conn *client.Conn) (uint64, u log.L().Warn("receive EOF packet, retrying") continue default: - log.L().Warn("invalid stream header, retrying", zap.Uint8("header", uint8(data[0]))) + log.L().Warn("invalid stream header, retrying", zap.Uint8("header", data[0])) continue } } diff --git a/dm/master/server.go b/dm/master/server.go index 7a45942074..4359c0d05e 100644 --- a/dm/master/server.go +++ b/dm/master/server.go @@ -552,7 +552,7 @@ func (s *Server) GetSubTaskCfg(ctx context.Context, req *pb.GetSubTaskCfgRequest Msg: err.Error(), }, nil } - cfgs = append(cfgs, string(cfgBytes)) + cfgs = append(cfgs, cfgBytes) } return &pb.GetSubTaskCfgResponse{ diff --git a/pkg/binlog/event/event.go b/pkg/binlog/event/event.go index 2c6c20324e..e4efe30c16 100644 --- a/pkg/binlog/event/event.go +++ b/pkg/binlog/event/event.go @@ -132,7 +132,7 @@ func GenFormatDescriptionEvent(header *replication.EventHeader, latestPos uint32 // mysql-server version, 50 bytes serverVer := make([]byte, mysqlVersionLen) - copy(serverVer, []byte(mysqlVersion)) + copy(serverVer, mysqlVersion) err = binary.Write(payload, binary.LittleEndian, serverVer) if err != nil { return nil, terror.ErrBinlogWriteBinaryData.AnnotateDelegate(err, "write mysql-server version %v", serverVer) @@ -825,7 +825,7 @@ func GenDummyEvent(header *replication.EventHeader, latestPos uint32, eventSize ) copy(nameBytes, dummyUserVarName) // name_length, 4 bytes - err := binary.Write(payload, binary.LittleEndian, uint32(nameLen)) + err := binary.Write(payload, binary.LittleEndian, nameLen) if err != nil { return nil, terror.ErrBinlogWriteBinaryData.AnnotateDelegate(err, "write USER_VAR_EVENT name length %d", nameLen) } diff --git a/pkg/binlog/event/event_test.go b/pkg/binlog/event/event_test.go index 7ee4dee349..0359b207b4 100644 --- a/pkg/binlog/event/event_test.go +++ b/pkg/binlog/event/event_test.go @@ -748,7 +748,7 @@ func (t *testEventSuite) TestGenDummyEvent(c *C) { verifyHeader(c, userVarEv.Header, expectedHeader, replication.USER_VAR_EVENT, latestPos, uint32(len(userVarEv.RawData))) // verify the body nameStart := uint32(eventHeaderLen + 4) - nameEnd := uint32(eventSize-1) - crc32Len + nameEnd := eventSize - 1 - crc32Len nameLen := nameEnd - nameStart c.Assert(nameLen, Equals, uint32(1)) // name-length==1 c.Assert(userVarEv.RawData[nameStart:nameEnd], DeepEquals, dummyUserVarName[:nameLen]) @@ -774,7 +774,7 @@ func (t *testEventSuite) TestGenDummyEvent(c *C) { c.Assert(queryEvBody.StatusVars, DeepEquals, []byte{}) c.Assert(queryEvBody.Schema, DeepEquals, []byte{}) queryStart := uint32(eventHeaderLen + 4 + 4 + 1 + 2 + 2 + 1) - queryEnd := uint32(eventSize) - crc32Len + queryEnd := eventSize - crc32Len queryLen := queryEnd - queryStart c.Assert(queryEvBody.Query, HasLen, int(queryLen)) if queryLen <= dummyQueryLen { diff --git a/pkg/utils/relay.go b/pkg/utils/relay.go index ce1f31ee7e..2f0528932e 100644 --- a/pkg/utils/relay.go +++ b/pkg/utils/relay.go @@ -142,7 +142,7 @@ func GenFakeRotateEvent(nextLogName string, logPos uint64, serverID uint32) (*re // body binary.LittleEndian.PutUint64(rawData[headerLen:], logPos) - copy(rawData[headerLen+8:], []byte(nextLogName)) + copy(rawData[headerLen+8:], nextLogName) // decode header h := &replication.EventHeader{} diff --git a/relay/writer/file_util_test.go b/relay/writer/file_util_test.go index f790386bc4..02262fafa7 100644 --- a/relay/writer/file_util_test.go +++ b/relay/writer/file_util_test.go @@ -77,7 +77,7 @@ func (t *testFileUtilSuite) TestCheckBinlogHeaderExist(c *check.C) { // invalid data invalidData := make([]byte, len(replication.BinLogFileHeader)) copy(invalidData, replication.BinLogFileHeader) - invalidData[0] = uint8(invalidData[0]) + 1 + invalidData[0] = invalidData[0] + 1 err = ioutil.WriteFile(filename, invalidData, 0644) c.Assert(err, check.IsNil) exist, err = checkBinlogHeaderExist(filename) diff --git a/syncer/db_test.go b/syncer/db_test.go index 846bb72f0d..0e1d24632e 100644 --- a/syncer/db_test.go +++ b/syncer/db_test.go @@ -73,7 +73,7 @@ func (s *testDBSuite) SetUpSuite(c *C) { func (s *testDBSuite) resetBinlogSyncer(c *C) { cfg := replication.BinlogSyncerConfig{ - ServerID: uint32(s.cfg.ServerID), + ServerID: s.cfg.ServerID, Flavor: "mysql", Host: s.cfg.From.Host, Port: uint16(s.cfg.From.Port), diff --git a/syncer/dml.go b/syncer/dml.go index 38d81318ee..8b5f19f0a4 100644 --- a/syncer/dml.go +++ b/syncer/dml.go @@ -340,7 +340,7 @@ func columnValue(value interface{}, ft *types.FieldType) string { case int32: data = strconv.FormatInt(int64(v), 10) case int64: - data = strconv.FormatInt(int64(v), 10) + data = strconv.FormatInt(v, 10) case uint8: data = strconv.FormatUint(uint64(v), 10) case uint16: @@ -348,7 +348,7 @@ func columnValue(value interface{}, ft *types.FieldType) string { case uint32: data = strconv.FormatUint(uint64(v), 10) case uint64: - data = strconv.FormatUint(uint64(v), 10) + data = strconv.FormatUint(v, 10) case float32: data = strconv.FormatFloat(float64(v), 'f', -1, 32) case float64: diff --git a/syncer/syncer_test.go b/syncer/syncer_test.go index dd9967b93a..068d0f08c2 100644 --- a/syncer/syncer_test.go +++ b/syncer/syncer_test.go @@ -218,7 +218,7 @@ func (s *testSyncerSuite) resetEventsGenerator(c *C) { latestGTIDStr := "3ccc475b-2343-11e7-be21-6c0b84d59f30:14" latestGTID, err := gtid.ParserGTID(s.cfg.Flavor, latestGTIDStr) c.Assert(err, IsNil) - s.eventsGenerator, err = event.NewGenerator(s.cfg.Flavor, uint32(s.cfg.ServerID), 0, latestGTID, previousGTIDSet, 0) + s.eventsGenerator, err = event.NewGenerator(s.cfg.Flavor, s.cfg.ServerID, 0, latestGTID, previousGTIDSet, 0) if err != nil { c.Fatal(err) }