Skip to content

Commit c8ade5b

Browse files
committed
style: apply cargo fmt formatting
Apply rustfmt to fix CI formatting checks.
1 parent 8141c34 commit c8ade5b

File tree

4 files changed

+54
-35
lines changed

4 files changed

+54
-35
lines changed

core/common/src/types/message/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ pub use crate::commands::messages::poll_messages::PollMessages;
3939
pub use crate::commands::messages::send_messages::SendMessages;
4040
pub use iggy_message::{IggyMessage, MAX_PAYLOAD_SIZE, MAX_USER_HEADERS_SIZE};
4141
pub use index::IggyIndex;
42-
pub use index_cache_line_block::{
43-
IndexCacheLineBlock, CACHE_LINE_SIZE, ENTRIES_PER_CACHE_LINE,
44-
};
42+
pub use index_cache_line_block::{CACHE_LINE_SIZE, ENTRIES_PER_CACHE_LINE, IndexCacheLineBlock};
4543
pub use index_view::IggyIndexView;
4644
pub use indexes::IggyIndexes;
4745
pub use message_header::{

core/server/src/streaming/segments/indexes/indexes_mut.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
use crate::streaming::utils::aligned_buffer;
2020
use iggy_common::PooledBuffer;
21-
use iggy_common::{INDEX_SIZE, IggyIndexView, IndexCacheLineBlock, ENTRIES_PER_CACHE_LINE};
21+
use iggy_common::{ENTRIES_PER_CACHE_LINE, INDEX_SIZE, IggyIndexView, IndexCacheLineBlock};
2222
use std::fmt;
2323
use std::ops::{Deref, Index as StdIndex};
2424

@@ -411,7 +411,8 @@ impl IggyIndexesMut {
411411
let remaining_entries = self.count() % ENTRIES_PER_CACHE_LINE as u32;
412412
if remaining_entries > 0 {
413413
// Fall back to entry-level search for incomplete block
414-
return self.binary_search_position_for_timestamp_sync(target_timestamp)
414+
return self
415+
.binary_search_position_for_timestamp_sync(target_timestamp)
415416
.map(|pos| {
416417
let block_idx = pos / ENTRIES_PER_CACHE_LINE as u32;
417418
let entry_idx = (pos % ENTRIES_PER_CACHE_LINE as u32) as usize;
@@ -466,8 +467,13 @@ impl IggyIndexesMut {
466467
///
467468
/// # Returns
468469
/// The first index with timestamp >= target_timestamp, or None if not found
469-
pub fn find_by_timestamp_block_aware(&self, target_timestamp: u64) -> Option<IggyIndexView<'_>> {
470-
if let Some((block_idx, entry_idx)) = self.binary_search_blocks_by_timestamp(target_timestamp) {
470+
pub fn find_by_timestamp_block_aware(
471+
&self,
472+
target_timestamp: u64,
473+
) -> Option<IggyIndexView<'_>> {
474+
if let Some((block_idx, entry_idx)) =
475+
self.binary_search_blocks_by_timestamp(target_timestamp)
476+
{
471477
let global_index = block_idx * ENTRIES_PER_CACHE_LINE as u32 + entry_idx as u32;
472478
self.get(global_index)
473479
} else {

core/server/src/streaming/segments/indexes/indexes_mut_bench.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
mod benchmarks {
2121
use crate::configs::system::SystemConfig;
2222
use crate::streaming::segments::indexes::indexes_mut::IggyIndexesMut;
23-
use iggy_common::{MemoryPool, MEMORY_POOL};
23+
use iggy_common::{MEMORY_POOL, MemoryPool};
2424
use std::sync::{Arc, Once};
2525
use std::time::Instant;
2626

@@ -40,11 +40,7 @@ mod benchmarks {
4040
let mut indexes = IggyIndexesMut::with_capacity(size, 0);
4141

4242
for i in 0..size as u32 {
43-
indexes.insert(
44-
i,
45-
i * 1000,
46-
1000000 + (i as u64 * 1000),
47-
);
43+
indexes.insert(i, i * 1000, 1000000 + (i as u64 * 1000));
4844
}
4945

5046
indexes
@@ -149,7 +145,8 @@ mod benchmarks {
149145
fn bench_memory_footprint() {
150146
for size in [1_000, 10_000, 100_000, 1_000_000].iter() {
151147
let indexes = create_indexes(*size);
152-
let memory_bytes = indexes.count() as usize * std::mem::size_of::<iggy_common::IggyIndex>();
148+
let memory_bytes =
149+
indexes.count() as usize * std::mem::size_of::<iggy_common::IggyIndex>();
153150
let memory_mb = memory_bytes as f64 / 1024.0 / 1024.0;
154151

155152
println!(
@@ -206,7 +203,10 @@ mod benchmarks {
206203
let indexes = create_indexes(size);
207204

208205
println!("\nCache efficiency metrics for {} entries:", size);
209-
println!(" Index entry size: {} bytes", std::mem::size_of::<iggy_common::IggyIndex>());
206+
println!(
207+
" Index entry size: {} bytes",
208+
std::mem::size_of::<iggy_common::IggyIndex>()
209+
);
210210
println!(" Entries per cache line: 4");
211211
println!(" Total blocks: {}", indexes.block_count());
212212
println!(" Buffer aligned: {}", indexes.is_buffer_aligned());
@@ -222,7 +222,8 @@ mod benchmarks {
222222
let regular_cache_lines = regular_probes * 2.0;
223223
let block_cache_lines = block_probes; // Each block = 1 cache line
224224

225-
let cache_reduction = ((regular_cache_lines - block_cache_lines) / regular_cache_lines) * 100.0;
225+
let cache_reduction =
226+
((regular_cache_lines - block_cache_lines) / regular_cache_lines) * 100.0;
226227

227228
println!("\nExpected cache behavior:");
228229
println!(" Regular search probes: {:.0}", regular_probes);

core/server/src/streaming/segments/indexes/indexes_mut_block_tests.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
#[cfg(test)]
2020
mod tests {
21-
use crate::streaming::segments::indexes::indexes_mut::IggyIndexesMut;
22-
use iggy_common::{MemoryPool, MEMORY_POOL};
2321
use crate::configs::system::SystemConfig;
22+
use crate::streaming::segments::indexes::indexes_mut::IggyIndexesMut;
2423
use iggy_common::ENTRIES_PER_CACHE_LINE;
24+
use iggy_common::{MEMORY_POOL, MemoryPool};
2525
use std::sync::{Arc, Once};
2626

2727
static INIT: Once = Once::new();
@@ -45,8 +45,8 @@ mod tests {
4545

4646
for i in 0..count {
4747
indexes.insert(
48-
i, // offset
49-
i * 1000, // position
48+
i, // offset
49+
i * 1000, // position
5050
1000000 + (i as u64 * 1000), // timestamp
5151
);
5252
}
@@ -86,7 +86,7 @@ mod tests {
8686

8787
// Get middle block
8888
let block2 = indexes.get_block(2).expect("Block 2 should exist");
89-
assert_eq!(block2.get(0).unwrap().offset, 8); // 2 * 4 = 8
89+
assert_eq!(block2.get(0).unwrap().offset, 8); // 2 * 4 = 8
9090
assert_eq!(block2.get(1).unwrap().offset, 9);
9191
assert_eq!(block2.get(2).unwrap().offset, 10);
9292
assert_eq!(block2.get(3).unwrap().offset, 11);
@@ -167,16 +167,22 @@ mod tests {
167167
let indexes = create_test_indexes(20);
168168

169169
// Exact match
170-
let idx = indexes.find_by_timestamp_block_aware(1005000).expect("Should find");
170+
let idx = indexes
171+
.find_by_timestamp_block_aware(1005000)
172+
.expect("Should find");
171173
assert_eq!(idx.offset(), 5);
172174
assert_eq!(idx.timestamp(), 1005000);
173175

174176
// Between timestamps
175-
let idx = indexes.find_by_timestamp_block_aware(1005500).expect("Should find");
177+
let idx = indexes
178+
.find_by_timestamp_block_aware(1005500)
179+
.expect("Should find");
176180
assert_eq!(idx.offset(), 6); // Next higher
177181

178182
// Before first
179-
let idx = indexes.find_by_timestamp_block_aware(999000).expect("Should find");
183+
let idx = indexes
184+
.find_by_timestamp_block_aware(999000)
185+
.expect("Should find");
180186
assert_eq!(idx.offset(), 0);
181187

182188
// After last
@@ -189,12 +195,12 @@ mod tests {
189195
let indexes = create_test_indexes(100);
190196

191197
let test_timestamps = vec![
192-
1000000, // First
193-
1050000, // Middle
194-
1099000, // Last
195-
999000, // Before first
196-
1025500, // Between entries
197-
2000000, // After last
198+
1000000, // First
199+
1050000, // Middle
200+
1099000, // Last
201+
999000, // Before first
202+
1025500, // Between entries
203+
2000000, // After last
198204
];
199205

200206
for timestamp in test_timestamps {
@@ -206,12 +212,14 @@ mod tests {
206212
assert_eq!(
207213
block_idx.offset(),
208214
regular_idx.offset(),
209-
"Mismatch for timestamp {}", timestamp
215+
"Mismatch for timestamp {}",
216+
timestamp
210217
);
211218
assert_eq!(
212219
block_idx.timestamp(),
213220
regular_idx.timestamp(),
214-
"Mismatch for timestamp {}", timestamp
221+
"Mismatch for timestamp {}",
222+
timestamp
215223
);
216224
}
217225
(None, None) => {
@@ -257,15 +265,21 @@ mod tests {
257265
assert_eq!(indexes.block_count(), 250);
258266

259267
// Search near beginning
260-
let idx = indexes.find_by_timestamp_block_aware(1001000).expect("Should find");
268+
let idx = indexes
269+
.find_by_timestamp_block_aware(1001000)
270+
.expect("Should find");
261271
assert_eq!(idx.offset(), 1);
262272

263273
// Search in middle
264-
let idx = indexes.find_by_timestamp_block_aware(1500000).expect("Should find");
274+
let idx = indexes
275+
.find_by_timestamp_block_aware(1500000)
276+
.expect("Should find");
265277
assert_eq!(idx.offset(), 500);
266278

267279
// Search near end
268-
let idx = indexes.find_by_timestamp_block_aware(1999000).expect("Should find");
280+
let idx = indexes
281+
.find_by_timestamp_block_aware(1999000)
282+
.expect("Should find");
269283
assert_eq!(idx.offset(), 999);
270284
}
271285
}

0 commit comments

Comments
 (0)