请教关于Tikv源码的问题.

最近看完了 Percolator的论文, 想把其中MVCC的原理跟Tikv的源码对应起来. Percolator的2-pc写入原理如下:

  • Percolator 的Cell结构 : row, col, st时间戳, Lock锁, Write指针.
  • prewrite阶段 检查锁冲突,写入Value, 写入Lock
  • commit阶段 写入write指针,清除Primary Lock

刚看到源码中 MvccReader, Cursor, SnapShot 三个概念就产生了疑惑, 能否讲一下这些结构体之间的关系、成员变量的含义, 以及对应到上面Percolator概念中的那些环节吗?

pub struct MvccReader<S: Snapshot> {

     snapshot: S,
     statistics: Statistics,
    // cursors are used for speeding up scans.
    data_cursor: Option<Cursor<S::Iter>>,
    lock_cursor: Option<Cursor<S::Iter>>,
    write_cursor: Option<Cursor<S::Iter>>,

    scan_mode: Option<ScanMode>,
    key_only: bool,

    fill_cache: bool,
    isolation_level: IsolationLevel,
}


pub struct Cursor<I: Iterator> {
   iter: I,
   scan_mode: ScanMode,
   // the data cursor can be seen will be
   min_key: Option<Vec<u8>>,
   max_key: Option<Vec<u8>>,

    // Use `Cell` to wrap these flags to provide interior mutability, so that `key()` and
    // `value()` don't need to have `&mut self`.
    cur_key_has_read: Cell<bool>,
    cur_value_has_read: Cell<bool>,
}


pub trait Snapshot: Send + Clone {}


pub struct Statistics {
    pub lock: CfStatistics,
    pub write: CfStatistics,
    pub data: CfStatistics,
}

pub struct CfStatistics {
    // How many keys that's effective to user. This counter should be increased
    // by the caller.
    pub processed: usize,
    pub get: usize,
    pub next: usize,
    pub prev: usize,
    pub seek: usize,
    pub seek_for_prev: usize,
    pub over_seek_bound: usize,
    pub flow_stats: FlowStatistics,
}

你好,

你的问题已经收到,正在分析,请稍等

可以参考下面的文章:

感谢,和事务这边研发沟通了一下,这个东西的说明确实是我们目前所缺失的,建议加入我们的 Transaction-SIG : 加入及时沟通平台,与我们事务的一线研发面对面沟通一下, 加入方式:

  1. 加入 Slack
  2. 加入事务聊天群 - transaction-sig

@csnever

2赞