Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 committed Dec 19, 2024
1 parent 2be7e83 commit 6a0fcd1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ type RegionRequestRuntimeStats struct {
FirstRPCStats RPCRuntimeStats
// OtherRPCStatsMap uses to record another types of RPC requests.
OtherRPCStatsMap map[tikvrpc.CmdType]*RPCRuntimeStats

RequestErrorStats
}

Expand Down Expand Up @@ -181,13 +180,15 @@ func (r *RegionRequestRuntimeStats) RecordRPCRuntimeStats(cmd tikvrpc.CmdType, d
stat.Consume += d
}

// GetRPCCount returns the total rpc types count.
func (r *RegionRequestRuntimeStats) GetRPCCount() int {
if r.FirstRPCStats.Count > 0 {
return len(r.OtherRPCStatsMap) + 1
}
return len(r.OtherRPCStatsMap)
}

// GetCmdRPCCount returns the rpc count of the specified cmd type.
func (r *RegionRequestRuntimeStats) GetCmdRPCCount(cmd tikvrpc.CmdType) uint32 {
if r.FirstRPCStats.Cmd == cmd {
return r.FirstRPCStats.Count
Expand Down Expand Up @@ -232,13 +233,13 @@ func (r *RegionRequestRuntimeStats) String() string {
}
var builder strings.Builder
if r.FirstRPCStats.Count > 0 {
r.FirstRPCStats.BuildString(&builder)
r.FirstRPCStats.buildString(&builder)
}
for _, v := range r.OtherRPCStatsMap {
if builder.Len() > 0 {
builder.WriteByte(',')
}
v.BuildString(&builder)
v.buildString(&builder)
}
if errStatsStr := r.RequestErrorStats.String(); errStatsStr != "" {
builder.WriteString(", rpc_errors:")
Expand All @@ -247,7 +248,7 @@ func (r *RegionRequestRuntimeStats) String() string {
return builder.String()
}

func (s *RPCRuntimeStats) BuildString(builder *strings.Builder) {
func (s *RPCRuntimeStats) buildString(builder *strings.Builder) {
builder.WriteString(s.Cmd.String())
builder.WriteString(":{num_rpc:")
builder.WriteString(strconv.FormatUint(uint64(s.Count), 10))
Expand Down
4 changes: 2 additions & 2 deletions internal/locate/region_request3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ func (s *testRegionRequestToThreeStoresSuite) TestSendReqFirstTimeout() {
s.Nil(err)
s.True(IsFakeRegionError(regionErr))
s.Equal(1, s.regionRequestSender.Stats.GetRPCCount())
s.Equal(uint32(3), s.regionRequestSender.Stats.GetCmdRPCCount(tikvrpc.CmdGet)) // 2 rpc
s.Equal(uint32(3), s.regionRequestSender.Stats.GetCmdRPCCount(tikvrpc.CmdGet)) // 3 rpc
s.Equal(3, len(reqTargetAddrs)) // each rpc to a different store.
s.Equal(0, bo.GetTotalBackoffTimes()) // no backoff since fast retry.
// warn: must rest MaxExecutionDurationMs before retry.
Expand All @@ -1188,7 +1188,7 @@ func (s *testRegionRequestToThreeStoresSuite) TestSendReqFirstTimeout() {
s.Nil(regionErr)
s.Equal([]byte("value"), resp.Resp.(*kvrpcpb.GetResponse).Value)
s.Equal(1, s.regionRequestSender.Stats.GetRPCCount())
s.Equal(uint32(1), s.regionRequestSender.Stats.GetCmdRPCCount(tikvrpc.CmdGet)) // 2 rpc
s.Equal(uint32(1), s.regionRequestSender.Stats.GetCmdRPCCount(tikvrpc.CmdGet)) // 1 rpc
s.Equal(0, bo.GetTotalBackoffTimes()) // no backoff since fast retry.
}
}
Expand Down
4 changes: 0 additions & 4 deletions internal/locate/region_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,3 @@ func TestGetErrMsg(t *testing.T) {
}, "should panic")
require.Equal(t, "no cause err", getErrMsg(err))
}

func TestDebugCs(t *testing.T) {
fmt.Printf("size: %v -------\n\n", unsafe.Sizeof(RPCRuntimeStats{}))
}
9 changes: 7 additions & 2 deletions txnkv/txnsnapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ package txnsnapshot
import (
"bytes"
"context"
"fmt"
"math"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -1201,7 +1201,12 @@ func (rs *SnapshotRuntimeStats) String() string {
}
ms := rs.backoffSleepMS[k]
d := time.Duration(ms) * time.Millisecond
buf.WriteString(fmt.Sprintf("%s_backoff:{num:%d, total_time:%s}", k, v, util.FormatDuration(d)))
buf.WriteString(k)
buf.WriteString("_backoff:{num:")
buf.WriteString(strconv.Itoa(v))
buf.WriteString(", total_time:")
buf.WriteString(util.FormatDuration(d))
buf.WriteString("}")
}
timeDetail := rs.timeDetail.String()
if timeDetail != "" {
Expand Down

0 comments on commit 6a0fcd1

Please sign in to comment.