# [KB]TiKV 节点 panic 报 Uniform sample_single called with low >= high

## Key Words

TiKV, panic,load base split

## Description

1. 有一个 版本为 v4.0.11 的 TiKV 集群其中一个 TiKV server 发生 panic 并且日志有 Uniform::sample_single called with low >= high 关键条目， 操作系统未有异常日志。日志：

```golang
UniformSampler::sample_single: low >= high"] [backtrace="stack backtrace:
   0: tikv_util::set_panic_hook::{{closure}}
             at /home/jenkins/agent/workspace/build_tikv_multi_branch_master/tikv/components/tikv_util/src/lib.rs:465
   1: std::panicking::rust_panic_with_hook
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8//library/std/src/panicking.rs:595
   2: std::panicking::begin_panic::{{closure}}
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/panicking.rs:520
   3: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/sys_common/backtrace.rs:141
   4: std::panicking::begin_panic
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/panicking.rs:519
   5: <rand::distributions::uniform::UniformInt<usize> as rand::distributions::uniform::UniformSampler>::sample_single
             at /rust/registry/src/github.com-1ecc6299db9ec823/rand-0.7.3/src/distributions/uniform.rs:439
      rand::Rng::gen_range
             at /rust/registry/src/github.com-1ecc6299db9ec823/rand-0.7.3/src/lib.rs:217
   6: raftstore::store::worker::pd::StatsMonitor<E>::start::{{closure}}
             at /home/jenkins/agent/workspace/build_tikv_multi_branch_master/tikv/components/raftstore/src/store/worker/split_controller.rs:86
      std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/sys_common/backtrace.rs:125
   7: std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/thread/mod.rs:474
      <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/panic.rs:322
      std::panicking::try::do_call
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/panicking.rs:379
      std::panicking::try
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/panicking.rs:343
      std::panic::catch_unwind
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/panic.rs:396
      std::thread::Builder::spawn_unchecked::{{closure}}
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/std/src/thread/mod.rs:473
      core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/core/src/ops/function.rs:227
   8: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/alloc/src/boxed.rs:1487
      <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8/library/alloc/src/boxed.rs:1487
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8//library/std/src/sys/unix/thread.rs:71
   9: start_thread
  10: __clone
```

## Root Cause

* Load Base Split 是 TiKV 在 4.0 版本引入的特性，旨在解决 Region 访问分布不均匀造成的热点问题，比如小表的全表扫描。当启用 load base split 后，TiKV 按照 qps 切分 region 时，逻辑上存在 bug, 有一定概率引发 TiKV panic 问题。

## Diagnostic Steps

N/A

## Resolution

升级到未受影响版本

## Workaround

通过调大 split.qps-threshold=100000。这个比较大的值，就不会触发 region 的 load base split，就可以避免走到逻辑错误的代码位置。影响是 PD 不会根据 region 的 qps 情况去做 split。

## Affected Versions

v4.0.0~v4.0.11

v5.0.0-rc
