Skip to content

Commit 938d839

Browse files
Merge branch 'master' into dependabot/cargo/nix-0.28
2 parents 1397714 + cd1533d commit 938d839

File tree

13 files changed

+84
-49
lines changed

13 files changed

+84
-49
lines changed

.github/workflows/rust.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions-rs/toolchain@v1
2020
with:
2121
profile: minimal
22-
toolchain: nightly-2023-07-01
22+
toolchain: nightly-2023-12-31
2323
override: true
2424
components: rustfmt, clippy, rust-src
2525
- uses: Swatinem/rust-cache@v1
@@ -34,6 +34,8 @@ jobs:
3434
git diff --exit-code
3535
- name: Clippy
3636
run: make clippy
37+
env:
38+
EXTRA_CARGO_ARGS: '--fix'
3739
- name: Run tests
3840
run: make test
3941
env:
@@ -60,7 +62,7 @@ jobs:
6062
uses: actions-rs/toolchain@v1
6163
with:
6264
profile: minimal
63-
toolchain: 1.67.1
65+
toolchain: 1.75.0
6466
override: true
6567
components: rustfmt, clippy, rust-src
6668
- uses: Swatinem/rust-cache@v1
@@ -87,7 +89,7 @@ jobs:
8789
uses: actions-rs/toolchain@v1
8890
with:
8991
profile: minimal
90-
toolchain: nightly-2023-07-01
92+
toolchain: nightly-2023-12-31
9193
override: true
9294
components: llvm-tools-preview
9395
- uses: Swatinem/rust-cache@v1
@@ -96,15 +98,16 @@ jobs:
9698
- name: Install grcov
9799
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install --locked grcov; fi
98100
- name: Run tests
99-
run: |
100-
make test_matrix
101+
run: make test_matrix
101102
env:
102-
RUSTFLAGS: '-Zinstrument-coverage'
103+
RUSTFLAGS: '-Cinstrument-coverage'
103104
LLVM_PROFILE_FILE: '%p-%m.profraw'
104105
EXTRA_CARGO_ARGS: '--verbose'
105106
- name: Run grcov
106107
run: grcov `find . \( -name "*.profraw" \) -print` --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov
107108
- name: Upload
108-
uses: codecov/codecov-action@v2
109+
uses: codecov/codecov-action@v3
110+
env:
111+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
109112
with:
110113
file: coverage.lcov

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## [Unreleased]
44

5+
### New Features
6+
7+
* Add a new Prometheus metric `raft_engine_write_compression_ratio` to track compression ratio of write #358
8+
9+
## [0.4.2] - 2024-04-16
10+
11+
### Behavior Changes
12+
13+
* Periodically flush unsynced bytes when rewriting to avoid I/O jitters if flushing too many bytes impede the foreground writes. (#347)
14+
* Errors will be returned if rewriting fails, instread of `panic` directly. (#343)
15+
516
## [0.4.1] - 2023-09-14
617

718
### Behavior Changes

Cargo.toml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "raft-engine"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
authors = ["The TiKV Project Developers"]
55
edition = "2018"
6-
rust-version = "1.66.0"
6+
rust-version = "1.75.0"
77
description = "A persistent storage engine for Multi-Raft logs"
88
readme = "README.md"
99
repository = "https://github.com/tikv/raft-engine"
@@ -42,7 +42,10 @@ hex = "0.4"
4242
if_chain = "1.0"
4343
lazy_static = "1.3"
4444
libc = "0.2"
45-
log = { version = "0.4", features = ["max_level_trace", "release_max_level_debug"] }
45+
log = { version = "0.4", features = [
46+
"max_level_trace",
47+
"release_max_level_debug",
48+
] }
4649
lz4-sys = "1.9"
4750
memmap2 = { version = "0.9", optional = true }
4851
nix = "0.28"
@@ -64,8 +67,12 @@ thiserror = "1.0"
6467
criterion = "0.4"
6568
ctor = "0.2"
6669
env_logger = "0.10"
67-
kvproto = { git = "https://github.com/pingcap/kvproto.git", default-features = false, features = ["protobuf-codec"] }
68-
raft = { git = "https://github.com/tikv/raft-rs", branch = "master", default-features = false, features = ["protobuf-codec"] }
70+
kvproto = { git = "https://github.com/pingcap/kvproto.git", default-features = false, features = [
71+
"protobuf-codec",
72+
] }
73+
raft = { git = "https://github.com/tikv/raft-rs", branch = "master", default-features = false, features = [
74+
"protobuf-codec",
75+
] }
6976
rand = "0.8"
7077
rand_distr = "0.4"
7178
tempfile = "3.6"
@@ -74,19 +81,10 @@ toml = "0.8"
7481
[features]
7582
default = ["internals", "scripting"]
7683
internals = []
77-
nightly = [
78-
"prometheus/nightly",
79-
]
80-
failpoints = [
81-
"fail/failpoints",
82-
]
83-
scripting = [
84-
"rhai",
85-
]
86-
swap = [
87-
"nightly",
88-
"memmap2",
89-
]
84+
nightly = ["prometheus/nightly"]
85+
failpoints = ["fail/failpoints"]
86+
scripting = ["rhai"]
87+
swap = ["nightly", "memmap2"]
9088
std_fs = []
9189

9290
nightly_group = ["nightly", "swap"]

ctl/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
[package]
22
name = "raft-engine-ctl"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
authors = ["The TiKV Project Developers"]
55
edition = "2018"
6-
rust-version = "1.61.0"
6+
rust-version = "1.75.0"
77
description = "A control tool for Raft Engine"
88
repository = "https://github.com/tikv/raft-engine"
99
license = "Apache-2.0"
1010

1111
[dependencies]
1212
clap = { version = "3.1", features = ["derive", "cargo"] }
1313
env_logger = "0.10"
14-
raft-engine = { path = "..", version = "0.4.1", features = ["scripting", "internals"] }
14+
raft-engine = { path = "..", version = "0.4.1", features = [
15+
"scripting",
16+
"internals",
17+
] }

src/engine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ where
142142
return Ok(0);
143143
}
144144
let start = Instant::now();
145-
let len = log_batch.finish_populate(
145+
let (len, compression_ratio) = log_batch.finish_populate(
146146
self.cfg.batch_compression_threshold.0 as usize,
147147
self.cfg.compression_level,
148148
)?;
@@ -225,6 +225,7 @@ where
225225
now = end;
226226
ENGINE_WRITE_DURATION_HISTOGRAM.observe(now.saturating_duration_since(start).as_secs_f64());
227227
ENGINE_WRITE_SIZE_HISTOGRAM.observe(len as f64);
228+
ENGINE_WRITE_COMPRESSION_RATIO_HISTOGRAM.observe(compression_ratio);
228229
Ok(len)
229230
}
230231

src/env/log_fd/unix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl LogFd {
8383
while readed < buf.len() {
8484
let bytes = match pread(self.0, &mut buf[readed..], offset as i64) {
8585
Ok(bytes) => bytes,
86-
Err(e) if e == Errno::EINTR => continue,
86+
Err(Errno::EINTR) => continue,
8787
Err(e) => return Err(from_nix_error(e, "pread")),
8888
};
8989
// EOF
@@ -106,7 +106,7 @@ impl LogFd {
106106
while written < content.len() {
107107
let bytes = match pwrite(self.0, &content[written..], offset as i64) {
108108
Ok(bytes) => bytes,
109-
Err(e) if e == Errno::EINTR => continue,
109+
Err(Errno::EINTR) => continue,
110110
Err(e) if e == Errno::ENOSPC => return Err(from_nix_error(e, "nospace")),
111111
Err(e) => return Err(from_nix_error(e, "pwrite")),
112112
};

src/file_pipe_log/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub mod debug {
218218
let log_file_format = LogFileContext::new(file_id, Version::default());
219219
for batch in bs.iter_mut() {
220220
let offset = writer.offset() as u64;
221-
let len = batch
221+
let (len, _) = batch
222222
.finish_populate(1 /* compression_threshold */, None)
223223
.unwrap();
224224
batch.prepare_write(&log_file_format).unwrap();

src/file_pipe_log/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ mod tests {
713713
// Retire files.
714714
assert_eq!(pipe_log.purge_to(last).unwrap() as u64, last - first);
715715
// Try to read recycled file.
716-
for (_, handle) in handles.into_iter().enumerate() {
716+
for handle in handles.into_iter() {
717717
assert!(pipe_log.read_bytes(handle).is_err());
718718
}
719719
// Try to reuse.

src/log_batch.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -767,28 +767,32 @@ impl LogBatch {
767767
&mut self,
768768
compression_threshold: usize,
769769
compression_level: Option<usize>,
770-
) -> Result<usize> {
770+
) -> Result<(usize, f64)> {
771771
let _t = StopWatch::new(perf_context!(log_populating_duration));
772772
debug_assert!(self.buf_state == BufState::Open);
773773
if self.is_empty() {
774774
self.buf_state = BufState::Encoded(self.buf.len(), 0);
775-
return Ok(0);
775+
return Ok((0, 0.0));
776776
}
777777
self.buf_state = BufState::Incomplete;
778778

779779
// entries
780-
let (header_offset, compression_type) = if compression_threshold > 0
780+
let (header_offset, compression_type, compression_ratio) = if compression_threshold > 0
781781
&& self.buf.len() >= LOG_BATCH_HEADER_LEN + compression_threshold
782782
{
783783
let buf_len = self.buf.len();
784-
lz4::append_compress_block(
784+
let compression_ratio = lz4::append_compress_block(
785785
&mut self.buf,
786786
LOG_BATCH_HEADER_LEN,
787787
compression_level.unwrap_or(lz4::DEFAULT_LZ4_COMPRESSION_LEVEL),
788788
)?;
789-
(buf_len - LOG_BATCH_HEADER_LEN, CompressionType::Lz4)
789+
(
790+
buf_len - LOG_BATCH_HEADER_LEN,
791+
CompressionType::Lz4,
792+
compression_ratio,
793+
)
790794
} else {
791-
(0, CompressionType::None)
795+
(0, CompressionType::None, 0.0)
792796
};
793797

794798
// checksum
@@ -830,7 +834,7 @@ impl LogBatch {
830834
}
831835

832836
self.buf_state = BufState::Encoded(header_offset, footer_roffset - LOG_BATCH_HEADER_LEN);
833-
Ok(self.buf.len() - header_offset)
837+
Ok((self.buf.len() - header_offset, compression_ratio))
834838
}
835839

836840
/// Make preparations for the write of `LogBatch`.
@@ -1328,7 +1332,7 @@ mod tests {
13281332
offset: 0,
13291333
};
13301334
let old_approximate_size = batch.approximate_size();
1331-
let len = batch.finish_populate(usize::from(compress), None).unwrap();
1335+
let (len, _) = batch.finish_populate(usize::from(compress), None).unwrap();
13321336
assert!(old_approximate_size >= len);
13331337
assert_eq!(batch.approximate_size(), len);
13341338
let mut batch_handle = mocked_file_block_handle;
@@ -1493,7 +1497,7 @@ mod tests {
14931497
batch1.merge(&mut batch2).unwrap();
14941498
assert!(batch2.is_empty());
14951499

1496-
let len = batch1.finish_populate(0, None).unwrap();
1500+
let (len, _) = batch1.finish_populate(0, None).unwrap();
14971501
batch1.prepare_write(&file_context).unwrap();
14981502
let encoded = batch1.encoded_bytes();
14991503
assert_eq!(len, encoded.len());
@@ -1549,7 +1553,8 @@ mod tests {
15491553
offset: 0,
15501554
};
15511555
let buf_len = batch.buf.len();
1552-
let len = batch.finish_populate(1, None).unwrap();
1556+
let (len, compression_ratio) = batch.finish_populate(1, None).unwrap();
1557+
assert!(compression_ratio == 0.0);
15531558
assert!(len == 0);
15541559
assert_eq!(batch.buf_state, BufState::Encoded(buf_len, 0));
15551560
let file_context = LogFileContext::new(mocked_file_block_handles.id, Version::V2);
@@ -1671,7 +1676,8 @@ mod tests {
16711676
},
16721677
];
16731678
let old_approximate_size = batch.approximate_size();
1674-
let len = batch.finish_populate(1, None).unwrap();
1679+
let (len, compression_ratio) = batch.finish_populate(1, None).unwrap();
1680+
assert!(compression_ratio > 0.0);
16751681
assert!(old_approximate_size >= len);
16761682
assert_eq!(batch.approximate_size(), len);
16771683
let checksum = batch.item_batch.checksum;

src/metrics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ lazy_static! {
201201
exponential_buckets(256.0, 1.8, 22).unwrap()
202202
)
203203
.unwrap();
204+
pub static ref ENGINE_WRITE_COMPRESSION_RATIO_HISTOGRAM: Histogram = register_histogram!(
205+
"raft_engine_write_compression_ratio",
206+
"Bucketed histogram of Raft Engine write compression ratio",
207+
exponential_buckets(0.0005, 1.8, 16).unwrap()
208+
)
209+
.unwrap();
204210
pub static ref LOG_ALLOCATE_DURATION_HISTOGRAM: Histogram = register_histogram!(
205211
"raft_engine_allocate_log_duration_seconds",
206212
"Bucketed histogram of Raft Engine allocate log duration",

0 commit comments

Comments
 (0)