Skip to content

Commit

Permalink
Merge branch 'master' into dev-rpn-expr-abs
Browse files Browse the repository at this point in the history
Signed-off-by: mapleFU <1506118561@qq.com>
  • Loading branch information
mapleFU committed Jul 1, 2019
2 parents 75bdfce + a0f8be8 commit fe76295
Show file tree
Hide file tree
Showing 18 changed files with 594 additions and 216 deletions.
14 changes: 13 additions & 1 deletion components/tikv_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ impl<T> DerefMut for MustConsumeVec<T> {
impl<T> Drop for MustConsumeVec<T> {
fn drop(&mut self) {
if !self.is_empty() {
panic!("resource leak detected: {}.", self.tag);
safe_panic!("resource leak detected: {}.", self.tag);
}
}
}
Expand Down Expand Up @@ -754,4 +754,16 @@ mod tests {
assert!(!is_zero_duration(&Duration::new(1, 0)));
assert!(!is_zero_duration(&Duration::new(0, 1)));
}

#[test]
fn test_must_consume_vec_dtor_not_abort() {
let res = panic_hook::recover_safe(|| {
let mut v = MustConsumeVec::new("test");
v.push(2);
panic!("Panic with MustConsumeVec non-empty");
// It would abort if there was a double-panic in dtor, thus
// the test would fail.
});
res.unwrap_err();
}
}
43 changes: 43 additions & 0 deletions components/tikv_util/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,32 @@ macro_rules! try_opt_or {
}};
}

/// A safe panic macro that prevents double panic.
///
/// You probably want to use this macro instead of `panic!` in a `drop` method.
/// It checks whether the current thread is unwinding because of panic. If it is,
/// log an error message instead of causing double panic.
#[macro_export]
macro_rules! safe_panic {
() => ({
safe_panic!("explicit panic")
});
($msg:expr) => ({
if std::thread::panicking() {
error!(concat!($msg, ", double panic prevented"))
} else {
panic!($msg)
}
});
($fmt:expr, $($args:tt)+) => ({
if std::thread::panicking() {
error!(concat!($fmt, ", double panic prevented"), $($args)+)
} else {
panic!($fmt, $($args)+)
}
});
}

#[cfg(test)]
mod tests {
use std::error::Error;
Expand All @@ -184,4 +210,21 @@ mod tests {
format!("[{}:{}]: hi", file_name, line_number + 1)
);
}

#[test]
#[should_panic]
fn test_safe_panic() {
struct S;
impl Drop for S {
fn drop(&mut self) {
safe_panic!("safe panic on drop");
}
}

let res = panic_hook::recover_safe(|| {
let _s = S;
panic!("first panic");
});
res.unwrap_err();
}
}
39 changes: 39 additions & 0 deletions docs/how-to/configure/region-merge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Region Merge
summary: Learn how to configure Region Merge in TiKV.
category: how-to
---

# Region Merge

TiKV replicates a segment of data in Regions via the Raft state machine. As data writes increase, a Region Split happens when the size of the region or the number of keys has reached a threshold. Conversely, if the size of the Region or the amount of keys shrinks because of data deletion, we can use Region Merge to merge adjacent regions that are smaller. This relieves some stress on Raftstore.


## Merge process

Region Merge is initiated by the Placement Driver (PD). The steps are:

1. PD polls the sizes and number of keys of all regions on the TiKV node.

2. When the region size is less than `max-merge-region-size` or the number of keys the region includes is less than `max-merge-region-keys`, PD performs Region Merge on the smaller of the two adjacent Regions.

> **Note:**
>
> - All replicas of the merged Regions must belong to the same set of TiKVs.
> - Newly split Regions won't be merged within the period of time specified by `split-merge-interval`.
> - Region Merge won't happen within the period of time specified by `split-merge-interval` after PD starts or restarts.
>- Region Merge won't happen for two Regions that belong to different tables if `namespace-classifier = table` (default).
## Configure Region Merge

Region Merge is enabled by default. You can use `pd-ctl` or the PD configuration file to configure Region Merge.

To enable Region Merge, set the following parameters to a non-zero value:

- `max-merge-region-size`
- `max-merge-region-keys`
- `merge-schedule-limit`

You can use `split-merge-interval` to control the interval between the `split` and `merge` operations.

For detailed descriptions on the above parameters, refer to [PD Control](../../reference/tools/pd-control.md).
93 changes: 93 additions & 0 deletions docs/how-to/configure/store-limit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: Store Limits
summary: Learn how to configure scheduling rate limit on stores
category: how-to
---

# Store Limit

This section describes how to configure scheduling rate limit, specifically, at the store level.

In TiKV, PD generates different scheduling operators based on the information gathered from TiKV and scheduling strategies. The operators are then sent to TiKV to perform scheduling on Regions. You can use `*-schedule-limit` to set speed limits on different operators, but this may cause performance bottlenecks in certain scenarios because these parameters function globally on the entire cluster. Rate limit at the store level allows you to control scheduling more flexibly with more refined granularities.

## How to configure scheduling rate limits on stores

PD provides the following two methods to configure scheduling rate limits on stores:

- Configure the rate limit using **`store-balance-rate`**.

`store-balance-rate` specifies the maximum number of scheduling tasks allowed for each store per minute. The scheduling steps include adding peers or learners. Set this parameter in the PD configuration file. The default value is 15. This configuration is persistent.

Use the `pd-ctl` tool to modify `store-balance-rate` and make it persistent.

Example:

```bash
>> config set store-balance-rate 20
```

> **Note:**
>
> The modification only takes effect on stores added after this configuration change, and will be applied to all stores in the cluster after you restart TiKV. If you want this change to work immediately on all stores or some individual stores before the change without restarting, combine this configuration with the `pd-ctl` tool method below. See [Sample usages](#sample-usages) for more details.

- Use the `pd-ctl` tool to view or modify the upper limit of the scheduling rate. The commands are:

- **`stores show limit`**

Example:

```bash
» stores show limit // If store-balance-rate is set to 15, the corresponding rate for all stores should be 15.
{
"4": {
"rate": 15
},
"5": {
"rate": 15
},
...
}
```

- **`stores set limit <rate>`**

Example:

```bash
>> stores set limit 20 // Set the upper limit of scheduling rate for all stores to be 20 scheduling tasks per minute.
```

- **`store limit <store_id> <rate>`**

Example:

```bash
>> store limit 2 10 // Set the upper limit of scheduling speed for store 2 to be 10 scheduling tasks per minute.
```
> **Note:**
>
> This method is not persistent, and the configuration will lose its efficacy after you restart TiKV.

See [PD Control](../../reference/tools/pd-control.md) for more detailed description of these commands.

## Sample usages

- The following example modifies the rate limit to 20 and applies immediately to all stores. The configuration is still valid after restart.

```bash
>> config set store-balance-rate 20
>> stores set limit 20
```

- The following example modifies the rate limit for all stores to 20 and applies immediately. After restart, the configuration becomes invalid, and the rate limit for all stores specified by `store-balance-rate` takes over.

```bash
>> stores set limit 20
```

- The following example modifies the rate limit for store 2 to 20 and applies immediately. After restart, the configuration becomes invalid, and the rate limit for store 2 becomes the value specified by `store-balance-rate`.

```bash
>> store limit 2 20
```

Loading

0 comments on commit fe76295

Please sign in to comment.