diff --git a/integration_tests/snapshot_test.go b/integration_tests/snapshot_test.go index aee209543..3f0ef9716 100644 --- a/integration_tests/snapshot_test.go +++ b/integration_tests/snapshot_test.go @@ -347,6 +347,13 @@ func (s *testSnapshotSuite) TestSnapshotRuntimeStats() { "scan_detail: {total_process_keys: 20, total_process_keys_size: 20, total_keys: 30, get_snapshot_time: 1µs, " + "rocksdb: {delete_skipped_count: 10, key_skipped_count: 2, block: {cache_hit_count: 20, read_count: 40, read_byte: 30 Bytes}}}" s.Equal(expect, snapshot.FormatStats()) + snapshot.GetResolveLockDetail().ResolveLockTime = int64(time.Second) + expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " + + "time_detail: {total_process_time: 200ms, total_wait_time: 200ms}, " + + "resolve_lock_time:1s, " + + "scan_detail: {total_process_keys: 20, total_process_keys_size: 20, total_keys: 30, get_snapshot_time: 1µs, " + + "rocksdb: {delete_skipped_count: 10, key_skipped_count: 2, block: {cache_hit_count: 20, read_count: 40, read_byte: 30 Bytes}}}" + s.Equal(expect, snapshot.FormatStats()) } func (s *testSnapshotSuite) TestRCRead() { diff --git a/txnkv/txnsnapshot/snapshot.go b/txnkv/txnsnapshot/snapshot.go index 4b6344a94..1d51cf909 100644 --- a/txnkv/txnsnapshot/snapshot.go +++ b/txnkv/txnsnapshot/snapshot.go @@ -564,7 +564,7 @@ func (s *KVSnapshot) batchGetSingleRegion(bo *retry.Backoffer, batch batchKeys, resolveLocksOpts := txnlock.ResolveLocksOptions{ CallerStartTS: s.version, Locks: locks, - Detail: s.getResolveLockDetail(), + Detail: s.GetResolveLockDetail(), } resolveLocksRes, err := cli.ResolveLocksWithOpts(bo, resolveLocksOpts) msBeforeExpired := resolveLocksRes.TTL @@ -785,7 +785,7 @@ func (s *KVSnapshot) get(ctx context.Context, bo *retry.Backoffer, k []byte) ([] resolveLocksOpts := txnlock.ResolveLocksOptions{ CallerStartTS: s.version, Locks: locks, - Detail: s.getResolveLockDetail(), + Detail: s.GetResolveLockDetail(), } resolveLocksRes, err := cli.ResolveLocksWithOpts(bo, resolveLocksOpts) if err != nil { @@ -1092,7 +1092,8 @@ func (s *KVSnapshot) GetKVReadTimeout() time.Duration { return s.readTimeout } -func (s *KVSnapshot) getResolveLockDetail() *util.ResolveLockDetail { +// GetResolveLockDetail returns ResolveLockDetail, exports for testing. +func (s *KVSnapshot) GetResolveLockDetail() *util.ResolveLockDetail { s.mu.RLock() defer s.mu.RUnlock() if s.mu.stats == nil { @@ -1196,16 +1197,16 @@ func (rs *SnapshotRuntimeStats) String() string { buf.WriteString(", ") buf.WriteString(timeDetail) } - scanDetail := rs.scanDetail.String() - if scanDetail != "" { - buf.WriteString(", ") - buf.WriteString(scanDetail) - } if rs.resolveLockDetail.ResolveLockTime > 0 { buf.WriteString(", ") buf.WriteString("resolve_lock_time:") buf.WriteString(util.FormatDuration(time.Duration(rs.resolveLockDetail.ResolveLockTime))) } + scanDetail := rs.scanDetail.String() + if scanDetail != "" { + buf.WriteString(", ") + buf.WriteString(scanDetail) + } return buf.String() }