Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The region statistics maybe not correct #5306

Closed
shafreeck opened this issue Aug 21, 2019 · 1 comment
Assignees
Labels

Comments

@shafreeck
Copy link
Contributor

@shafreeck shafreeck commented Aug 21, 2019

Bug Report

What version of TiKV are you using?

v2.1.15

What operating system and CPU are you using?

Unknow

Steps to reproduce

Unknow

What did you expect?

correct and normal region stats

What is happened?

The approximate_size is 1MB, and the approximate_keys is 2662654. It should have some mistake

{
  "id": 46253,
  "start_key": "7480000000000002FF3400000000000000F8",
  "end_key": "7480000000000002FF3C00000000000000F8",
  "epoch": {
    "conf_ver": 5,
    "version": 3175
  },
  "peers": [
    {
      "id": 46254,
      "store_id": 1
    },
    {
      "id": 46255,
      "store_id": 4
    },
    {
      "id": 46256,
      "store_id": 5
    }
  ],
  "leader": {
    "id": 46254,
    "store_id": 1
  },
  "written_bytes": 337,
  "approximate_size": 1,
  "approximate_keys": 2662654
}
@AndreMouche

This comment has been minimized.

Copy link
Member

@AndreMouche AndreMouche commented Sep 3, 2019

https://github.com/tikv/tikv/blob/v2.1.15/src/raftstore/store/util.rs#L406
in the following function

pub fn get_region_approximate_keys(db: &DB, region: &metapb::Region) -> Result<u64> {
    // try to get from RangeProperties first.
    match get_region_approximate_keys_cf(db, CF_WRITE, region) {
        Ok(v) => if v > 0 { // we should return Ok(v) directly.
            return Ok(v);
        },
        Err(e) => debug!(
            "old_version:get keys from RangeProperties failed with err:{:?}",
            e
        ),
    }

    let cf = rocksdb_util::get_cf_handle(db, CF_WRITE)?;
    let start = keys::enc_start_key(region);
    let end = keys::enc_end_key(region);
    let (_, keys) = get_range_entries_and_versions(db, cf, &start, &end).unwrap_or_default();
    Ok(keys)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.