github.com/KinWaiYuen/client-go/v2@v2.5.4/txnkv/txnsnapshot/test_probe.go (about)

     1  // Copyright 2021 TiKV Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package txnsnapshot
    16  
    17  import (
    18  	"github.com/KinWaiYuen/client-go/v2/internal/locate"
    19  	"github.com/KinWaiYuen/client-go/v2/internal/retry"
    20  	"github.com/KinWaiYuen/client-go/v2/tikvrpc"
    21  	"github.com/pingcap/kvproto/pkg/kvrpcpb"
    22  )
    23  
    24  // SnapshotProbe exposes some snapshot utilities for testing purpose.
    25  type SnapshotProbe struct {
    26  	*KVSnapshot
    27  }
    28  
    29  // MergeRegionRequestStats merges RPC runtime stats into snapshot's stats.
    30  func (s SnapshotProbe) MergeRegionRequestStats(stats map[tikvrpc.CmdType]*locate.RPCRuntimeStats) {
    31  	s.mergeRegionRequestStats(stats)
    32  }
    33  
    34  // RecordBackoffInfo records backoff stats into snapshot's stats.
    35  func (s SnapshotProbe) RecordBackoffInfo(bo *retry.Backoffer) {
    36  	s.recordBackoffInfo(bo)
    37  }
    38  
    39  // MergeExecDetail merges exec stats into snapshot's stats.
    40  func (s SnapshotProbe) MergeExecDetail(detail *kvrpcpb.ExecDetailsV2) {
    41  	s.mergeExecDetail(detail)
    42  }
    43  
    44  // FormatStats dumps information of stats.
    45  func (s SnapshotProbe) FormatStats() string {
    46  	s.mu.Lock()
    47  	defer s.mu.Unlock()
    48  	return s.mu.stats.String()
    49  }
    50  
    51  // BatchGetSingleRegion gets a batch of keys from a region.
    52  func (s SnapshotProbe) BatchGetSingleRegion(bo *retry.Backoffer, region locate.RegionVerID, keys [][]byte, collectF func(k, v []byte)) error {
    53  	return s.batchGetSingleRegion(bo, batchKeys{region: region, keys: keys}, collectF)
    54  }
    55  
    56  // NewScanner returns a scanner to iterate given key range.
    57  func (s SnapshotProbe) NewScanner(start, end []byte, batchSize int, reverse bool) (*Scanner, error) {
    58  	return newScanner(s.KVSnapshot, start, end, batchSize, reverse)
    59  }
    60  
    61  // ConfigProbe exposes configurations and global variables for testing purpose.
    62  type ConfigProbe struct{}
    63  
    64  // GetScanBatchSize returns the batch size to scan ranges.
    65  func (c ConfigProbe) GetScanBatchSize() int {
    66  	return defaultScanBatchSize
    67  }
    68  
    69  // GetGetMaxBackoff returns the max sleep for get command.
    70  func (c ConfigProbe) GetGetMaxBackoff() int {
    71  	return getMaxBackoff
    72  }