Skip to content

Commit 6b3c236

Browse files
authored
fix(server): corrent current offset when index cache is disabled (#1558)
This commit addresses an issue with the calculation of the current offset in the segment when the index cache is disabled. Previously, the logic incorrectly handled the absence of cached indexes, potentially leading to incorrect offset values. The updated logic ensures that the current offset is accurately calculated regardless of the cache setting, improving the reliability of segment handling.
1 parent 5c48f2d commit 6b3c236

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "server"
3-
version = "0.4.207"
3+
version = "0.4.208"
44
edition = "2021"
55
build = "src/build.rs"
66
license = "Apache-2.0"

server/src/streaming/segments/segment.rs

+26-28
Original file line numberDiff line numberDiff line change
@@ -124,35 +124,33 @@ impl Segment {
124124
self.size_bytes = IggyByteSize::from(log_size_bytes);
125125
self.last_index_position = log_size_bytes as _;
126126

127-
if self.config.segment.cache_indexes {
128-
self.indexes = Some(
129-
self.index_reader
130-
.as_ref()
131-
.unwrap()
132-
.load_all_indexes_impl()
133-
.await
134-
.with_error_context(|e| {
135-
format!("Failed to load indexes, error: {e} for {}", self)
136-
})
137-
.map_err(|_| IggyError::CannotReadFile)?,
138-
);
127+
self.indexes = Some(
128+
self.index_reader
129+
.as_ref()
130+
.unwrap()
131+
.load_all_indexes_impl()
132+
.await
133+
.with_error_context(|e| format!("Failed to load indexes, error: {e} for {}", self))
134+
.map_err(|_| IggyError::CannotReadFile)?,
135+
);
139136

140-
let last_index_offset = if self.indexes.as_ref().unwrap().is_empty() {
141-
0_u64
142-
} else {
143-
self.indexes.as_ref().unwrap().last().unwrap().offset as u64
144-
};
145-
146-
self.current_offset = self.start_offset + last_index_offset;
147-
148-
info!(
149-
"Loaded {} indexes for segment with start offset: {} and partition with ID: {} for topic with ID: {} and stream with ID: {}.",
150-
self.indexes.as_ref().unwrap().len(),
151-
self.start_offset,
152-
self.partition_id,
153-
self.topic_id,
154-
self.stream_id
155-
);
137+
let last_index_offset = if self.indexes.as_ref().unwrap().is_empty() {
138+
0_u64
139+
} else {
140+
self.indexes.as_ref().unwrap().last().unwrap().offset as u64
141+
};
142+
143+
self.current_offset = self.start_offset + last_index_offset;
144+
145+
info!("Loaded {} indexes for segment with start offset: {} and partition with ID: {} for topic with ID: {} and stream with ID: {}.",
146+
self.indexes.as_ref().unwrap().len(),
147+
self.start_offset,
148+
self.partition_id,
149+
self.topic_id,
150+
self.stream_id);
151+
152+
if !self.config.segment.cache_indexes {
153+
self.indexes = None;
156154
}
157155

158156
if self.is_full().await {

0 commit comments

Comments
 (0)