From a9f62491eb039822d8b958071312a89238bdaa1a Mon Sep 17 00:00:00 2001 From: oocococo Date: Wed, 22 Dec 2021 13:31:19 +0800 Subject: [PATCH 1/2] fix a log issue --- kv/raftstore/runner/raftlog_gc.go | 2 +- kv/raftstore/runner/scheduler_task.go | 2 +- kv/raftstore/runner/split_checker.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kv/raftstore/runner/raftlog_gc.go b/kv/raftstore/runner/raftlog_gc.go index 4a9bf2e5f..5639e70a0 100644 --- a/kv/raftstore/runner/raftlog_gc.go +++ b/kv/raftstore/runner/raftlog_gc.go @@ -76,7 +76,7 @@ func (r *raftLogGCTaskHandler) reportCollected(collected uint64) { func (r *raftLogGCTaskHandler) Handle(t worker.Task) { logGcTask, ok := t.(*RaftLogGCTask) if !ok { - log.Error("unsupported worker.Task: %+v", t) + log.Errorf("unsupported worker.Task: %+v", t) return } log.Debugf("execute gc log. [regionId: %d, endIndex: %d]", logGcTask.RegionID, logGcTask.EndIdx) diff --git a/kv/raftstore/runner/scheduler_task.go b/kv/raftstore/runner/scheduler_task.go index d5a3f49f0..e22b719d9 100644 --- a/kv/raftstore/runner/scheduler_task.go +++ b/kv/raftstore/runner/scheduler_task.go @@ -57,7 +57,7 @@ func (r *SchedulerTaskHandler) Handle(t worker.Task) { case *SchedulerStoreHeartbeatTask: r.onStoreHeartbeat(t.(*SchedulerStoreHeartbeatTask)) default: - log.Error("unsupported worker.Task: %+v", t) + log.Errorf("unsupported worker.Task: %+v", t) } } diff --git a/kv/raftstore/runner/split_checker.go b/kv/raftstore/runner/split_checker.go index 126761228..72a2ed369 100644 --- a/kv/raftstore/runner/split_checker.go +++ b/kv/raftstore/runner/split_checker.go @@ -37,7 +37,7 @@ func NewSplitCheckHandler(engine *badger.DB, router message.RaftRouter, conf *co func (r *splitCheckHandler) Handle(t worker.Task) { spCheckTask, ok := t.(*SplitCheckTask) if !ok { - log.Error("unsupported worker.Task: %+v", t) + log.Errorf("unsupported worker.Task: %+v", t) return } region := spCheckTask.Region From a90df284edd41c2c164c4a5557cc24d51bc38be2 Mon Sep 17 00:00:00 2001 From: oocococo Date: Wed, 5 Jan 2022 16:33:37 +0800 Subject: [PATCH 2/2] style(key format): consist "key" format --- kv/raftstore/meta/keys.go | 6 +++--- kv/raftstore/runner/region_task.go | 5 ++--- kv/raftstore/runner/split_checker.go | 4 +--- kv/raftstore/util/error.go | 2 +- kv/test_raftstore/cluster.go | 3 +-- kv/test_raftstore/utils.go | 5 ++--- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/kv/raftstore/meta/keys.go b/kv/raftstore/meta/keys.go index 8d311adaf..62b619603 100644 --- a/kv/raftstore/meta/keys.go +++ b/kv/raftstore/meta/keys.go @@ -88,10 +88,10 @@ func IsRaftStateKey(key []byte) bool { func DecodeRegionMetaKey(key []byte) (uint64, byte, error) { if len(RegionMetaMinKey)+8+1 != len(key) { - return 0, 0, errors.Errorf("invalid region meta key length for key %v", key) + return 0, 0, errors.Errorf("invalid region meta key length for key %s", key) } if !bytes.HasPrefix(key, RegionMetaMinKey) { - return 0, 0, errors.Errorf("invalid region meta key prefix for key %v", key) + return 0, 0, errors.Errorf("invalid region meta key prefix for key %s", key) } regionID := binary.BigEndian.Uint64(key[len(RegionMetaMinKey):]) return regionID, key[len(key)-1], nil @@ -117,7 +117,7 @@ func RegionStateKey(regionID uint64) []byte { /// RaftLogIndex gets the log index from raft log key generated by `raft_log_key`. func RaftLogIndex(key []byte) (uint64, error) { if len(key) != RegionRaftLogLen { - return 0, errors.Errorf("key %v is not a valid raft log key", key) + return 0, errors.Errorf("key %s is not a valid raft log key", key) } return binary.BigEndian.Uint64(key[RegionRaftLogLen-8:]), nil } diff --git a/kv/raftstore/runner/region_task.go b/kv/raftstore/runner/region_task.go index 8b7e5fb64..950514a78 100644 --- a/kv/raftstore/runner/region_task.go +++ b/kv/raftstore/runner/region_task.go @@ -1,7 +1,6 @@ package runner import ( - "encoding/hex" "fmt" "time" @@ -132,10 +131,10 @@ func (snapCtx *snapContext) handleApply(regionId uint64, notifier chan<- bool, s func (snapCtx *snapContext) cleanUpRange(regionId uint64, startKey, endKey []byte) { if err := engine_util.DeleteRange(snapCtx.engines.Kv, startKey, endKey); err != nil { log.Fatalf("failed to delete data in range, [regionId: %d, startKey: %s, endKey: %s, err: %v]", regionId, - hex.EncodeToString(startKey), hex.EncodeToString(endKey), err) + startKey, endKey, err) } else { log.Infof("succeed in deleting data in range. [regionId: %d, startKey: %s, endKey: %s]", regionId, - hex.EncodeToString(startKey), hex.EncodeToString(endKey)) + startKey, endKey) } } diff --git a/kv/raftstore/runner/split_checker.go b/kv/raftstore/runner/split_checker.go index 72a2ed369..f023b316a 100644 --- a/kv/raftstore/runner/split_checker.go +++ b/kv/raftstore/runner/split_checker.go @@ -1,8 +1,6 @@ package runner import ( - "encoding/hex" - "github.com/Connor1996/badger" "github.com/pingcap-incubator/tinykv/kv/config" "github.com/pingcap-incubator/tinykv/kv/raftstore/message" @@ -43,7 +41,7 @@ func (r *splitCheckHandler) Handle(t worker.Task) { region := spCheckTask.Region regionId := region.Id log.Debugf("executing split check worker.Task: [regionId: %d, startKey: %s, endKey: %s]", regionId, - hex.EncodeToString(region.StartKey), hex.EncodeToString(region.EndKey)) + region.StartKey, region.EndKey) key := r.splitCheck(regionId, region.StartKey, region.EndKey) if key != nil { _, userKey, err := codec.DecodeBytes(key) diff --git a/kv/raftstore/util/error.go b/kv/raftstore/util/error.go index 0f54d63d1..5843ad06f 100644 --- a/kv/raftstore/util/error.go +++ b/kv/raftstore/util/error.go @@ -31,7 +31,7 @@ type ErrKeyNotInRegion struct { } func (e *ErrKeyNotInRegion) Error() string { - return fmt.Sprintf("key %v is not in region %v", e.Key, e.Region) + return fmt.Sprintf("key %s is not in region %v", e.Key, e.Region) } type ErrEpochNotMatch struct { diff --git a/kv/test_raftstore/cluster.go b/kv/test_raftstore/cluster.go index 11de7afd5..f3ca9fea4 100644 --- a/kv/test_raftstore/cluster.go +++ b/kv/test_raftstore/cluster.go @@ -3,7 +3,6 @@ package test_raftstore import ( "bytes" "context" - "encoding/hex" "fmt" "io/ioutil" "math/rand" @@ -274,7 +273,7 @@ func (c *Cluster) GetRegion(key []byte) *metapb.Region { // retry to get the region again. SleepMS(20) } - panic(fmt.Sprintf("find no region for %s", hex.EncodeToString(key))) + panic(fmt.Sprintf("find no region for %s", key)) } func (c *Cluster) GetRandomRegion() *metapb.Region { diff --git a/kv/test_raftstore/utils.go b/kv/test_raftstore/utils.go index dc4ac9534..b8abdc8b6 100644 --- a/kv/test_raftstore/utils.go +++ b/kv/test_raftstore/utils.go @@ -2,7 +2,6 @@ package test_raftstore import ( "bytes" - "encoding/hex" "fmt" "time" @@ -100,7 +99,7 @@ func MustGetCf(engine *engine_util.Engines, cf string, key []byte, value []byte) } SleepMS(20) } - panic(fmt.Sprintf("can't get value %s for key %s", hex.EncodeToString(value), hex.EncodeToString(key))) + panic(fmt.Sprintf("can't get value %s for key %s", value, key)) } func MustGetCfEqual(engine *engine_util.Engines, cf string, key []byte, value []byte) { @@ -121,7 +120,7 @@ func MustGetCfNone(engine *engine_util.Engines, cf string, key []byte) { } SleepMS(20) } - panic(fmt.Sprintf("get value %s for key %s", hex.EncodeToString(val), hex.EncodeToString(key))) + panic(fmt.Sprintf("get value %s for key %s", val, key)) } func MustGetNone(engine *engine_util.Engines, key []byte) {