Skip to content

Commit 7f858f6

Browse files
authored
Merge pull request #522 from drmingdrmer/release-0.7
Feature: add feature-flag: `bt` enables backtrace
2 parents 1d00244 + bbe8597 commit 7f858f6

File tree

12 files changed

+109
-20
lines changed

12 files changed

+109
-20
lines changed

.github/workflows/ci.yaml

+50
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,56 @@ jobs:
5555
args: --all-targets -- -D warnings -A clippy::bool-assert-comparison
5656

5757

58+
- name: Upload artifact
59+
uses: actions/upload-artifact@v2
60+
if: failure()
61+
with:
62+
path: |
63+
openraft/_log/
64+
65+
ut-on-stable-rust:
66+
name: unittest on stable rust
67+
runs-on: ubuntu-latest
68+
69+
steps:
70+
- name: Setup | Checkout
71+
uses: actions/checkout@v2
72+
73+
- name: Setup | Toolchain
74+
uses: actions-rs/[email protected]
75+
with:
76+
toolchain: "stable"
77+
override: true
78+
components: rustfmt, clippy
79+
80+
- name: Unit Tests
81+
uses: actions-rs/cargo@v1
82+
with:
83+
command: test
84+
env:
85+
# Parallel tests block each other and result in timeout.
86+
RUST_TEST_THREADS: 2
87+
RUST_LOG: debug
88+
RUST_BACKTRACE: full
89+
90+
91+
- name: Build | Release Mode | No features
92+
uses: actions-rs/cargo@v1
93+
with:
94+
command: build
95+
args: --release
96+
97+
98+
- name: Build | Release Mode | No features
99+
uses: actions-rs/cargo@v1
100+
with:
101+
command: build
102+
args: --release --all-features
103+
env:
104+
# Enable unstable feature on stalbe rust.
105+
RUSTC_BOOTSTRAP: 1
106+
107+
58108
- name: Upload artifact
59109
uses: actions/upload-artifact@v2
60110
if: failure()

change-log.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## v0.7.1
2+
3+
### Added:
4+
5+
- Added: [ea696474](https://github.com/datafuselabs/openraft/commit/ea696474191b82069fae465bb064a2e599537ede) add feature-flag: `bt` enables backtrace; by 张炎泼; 2022-03-12
6+
7+
`--features bt` enables backtrace when generating errors.
8+
By default errors does not contain backtrace info.
9+
10+
Thus openraft can be built on stable rust by default.
11+
12+
To use on stable rust with backtrace, set `RUSTC_BOOTSTRAP=1`, e.g.:
13+
```
14+
RUSTUP_TOOLCHAIN=stable RUSTC_BOOTSTRAP=1 make test
15+
```
16+
117
## v0.7.0
218
319

change-log/v0.7.1.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### Added:
2+
3+
- Added: [ea696474](https://github.com/datafuselabs/openraft/commit/ea696474191b82069fae465bb064a2e599537ede) add feature-flag: `bt` enables backtrace; by 张炎泼; 2022-03-12
4+
5+
`--features bt` enables backtrace when generating errors.
6+
By default errors does not contain backtrace info.
7+
8+
Thus openraft can be built on stable rust by default.
9+
10+
To use on stable rust with backtrace, set `RUSTC_BOOTSTRAP=1`, e.g.:
11+
```
12+
RUSTUP_TOOLCHAIN=stable RUSTC_BOOTSTRAP=1 make test
13+
```

memstore/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openraft-memstore"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
edition = "2021"
55
authors = [
66
"Databend Authors <[email protected]>",
@@ -16,9 +16,9 @@ repository = "https://github.com/datafuselabs/openraft"
1616
readme = "README.md"
1717

1818
[dependencies]
19-
anyerror = { version = "0.1.1", features=["anyhow"]}
19+
anyerror = { version = "0.1.6", features = ["anyhow"]}
2020
anyhow = "1.0.32"
21-
openraft = { version="0.7.0", path= "../openraft" }
21+
openraft = { version="0.7.1", path= "../openraft" }
2222
async-trait = "0.1.36"
2323
serde = { version="1.0.114", features=["derive"] }
2424
serde_json = "1.0.57"

memstore/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(backtrace)]
2-
31
#[cfg(test)]
42
mod test;
53

@@ -11,13 +9,13 @@ use std::ops::RangeBounds;
119
use std::sync::Arc;
1210
use std::sync::Mutex;
1311

14-
use anyerror::AnyError;
1512
use openraft::async_trait::async_trait;
1613
use openraft::raft::Entry;
1714
use openraft::raft::EntryPayload;
1815
use openraft::storage::HardState;
1916
use openraft::storage::LogState;
2017
use openraft::storage::Snapshot;
18+
use openraft::AnyError;
2119
use openraft::AppData;
2220
use openraft::AppDataResponse;
2321
use openraft::EffectiveMembership;

openraft/Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openraft"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
edition = "2021"
55
authors = [
66
"Databend Authors <[email protected]>",
@@ -17,7 +17,7 @@ readme = "../README.md"
1717

1818
[dependencies]
1919
anyhow = "1.0.32"
20-
anyerror = { version = "0.1.1", features=["anyhow"]}
20+
anyerror = { version = "0.1.6", features = ["anyhow"]}
2121
async-trait = "0.1.36"
2222
byte-unit = "4.0.12"
2323
bytes = "1.0"
@@ -44,5 +44,9 @@ tracing-subscriber = { version = "0.3.3", features=["env-filter"] }
4444
[features]
4545
docinclude = [] # Used only for activating `doc(include="...")` on nightly.
4646

47+
# Enable backtrace when generating an error.
48+
# Stable rust does not support backtrace.
49+
bt = ["anyerror/backtrace", "anyhow/backtrace"]
50+
4751
[package.metadata.docs.rs]
4852
features = ["docinclude"] # Activate `docinclude` during docs.rs build.

openraft/src/core/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
491491
Ok(res) => match res {
492492
Ok(snapshot) => {
493493
let _ = tx_compaction.try_send(SnapshotUpdate::SnapshotComplete(snapshot.meta.last_log_id));
494-
let _ = chan_tx.send(snapshot.meta.last_log_id); // This will always succeed.
494+
// This will always succeed.
495+
let _ = chan_tx.send(snapshot.meta.last_log_id);
495496
}
496497
Err(err) => {
497498
tracing::error!({error=%err}, "error while generating snapshot");

openraft/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub enum ReplicationError {
198198

199199
#[error(transparent)]
200200
IO {
201-
#[backtrace]
201+
#[cfg_attr(feature = "bt", backtrace)]
202202
#[from]
203203
source: std::io::Error,
204204
},
@@ -212,7 +212,7 @@ pub enum ReplicationError {
212212

213213
#[error(transparent)]
214214
Network {
215-
#[backtrace]
215+
#[cfg_attr(feature = "bt", backtrace)]
216216
source: anyhow::Error,
217217
},
218218
}

openraft/src/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#![doc = include_str!("../README.md")]
2-
#![feature(backtrace)]
2+
#![cfg_attr(feature = "bt", feature(backtrace))]
3+
4+
//! # Feature flags
5+
//!
6+
//! - `bt`: Enable backtrace: generate backtrace for errors. This requires a unstable feature `backtrace` thus it can
7+
//! not be used with stable rust, unless explicity allowing using unstable features in stable rust with
8+
//! `RUSTC_BOOTSTRAP=1`.
39
410
mod config;
511
mod core;
@@ -24,6 +30,8 @@ pub mod types;
2430
mod metrics_wait_test;
2531
mod storage_helper;
2632

33+
pub use anyerror;
34+
pub use anyerror::AnyError;
2735
pub use async_trait;
2836

2937
pub use crate::config::Config;

openraft/src/storage_error.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::backtrace::Backtrace;
21
use std::fmt::Formatter;
32

43
use anyerror::AnyError;
@@ -15,7 +14,7 @@ impl DefensiveError {
1514
DefensiveError {
1615
subject,
1716
violation,
18-
backtrace: format!("{:?}", Backtrace::capture()),
17+
backtrace: anyerror::backtrace_str(),
1918
}
2019
}
2120
}
@@ -59,8 +58,7 @@ impl StorageIOError {
5958
subject,
6059
verb,
6160
source,
62-
// TODO: use crate backtrace instead of std::backtrace.
63-
backtrace: format!("{:?}", Backtrace::capture()),
61+
backtrace: anyerror::backtrace_str(),
6462
}
6563
}
6664
}

openraft/src/types/v070/storage_error.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct DefensiveError {
1818
/// The description of the violation.
1919
pub violation: Violation,
2020

21-
pub backtrace: String,
21+
pub backtrace: Option<String>,
2222
}
2323

2424
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -116,15 +116,15 @@ pub enum StorageError {
116116
#[error(transparent)]
117117
Defensive {
118118
#[from]
119-
#[backtrace]
119+
#[cfg_attr(feature = "bt", backtrace)]
120120
source: DefensiveError,
121121
},
122122

123123
/// An error raised by io operation.
124124
#[error(transparent)]
125125
IO {
126126
#[from]
127-
#[backtrace]
127+
#[cfg_attr(feature = "bt", backtrace)]
128128
source: StorageIOError,
129129
},
130130
}
@@ -135,5 +135,5 @@ pub struct StorageIOError {
135135
pub(crate) subject: ErrorSubject,
136136
pub(crate) verb: ErrorVerb,
137137
pub(crate) source: AnyError,
138-
pub(crate) backtrace: String,
138+
pub(crate) backtrace: Option<String>,
139139
}

scripts/build_change_log.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'Add:': typs['new-feature'],
3737
'add:': typs['new-feature'],
3838
'feature:': typs['new-feature'],
39+
'Feature:': typs['new-feature'],
3940
'features:': typs['new-feature'],
4041
'new-features:': typs['new-feature'],
4142
'docs:': typs['doc'],

0 commit comments

Comments
 (0)