Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 committed Dec 20, 2024
1 parent 7bd30c8 commit eaab49f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions integration_tests/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
17 changes: 9 additions & 8 deletions txnkv/txnsnapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}

Expand Down

0 comments on commit eaab49f

Please sign in to comment.