Skip to content

Commit 23a9a68

Browse files
committed
fix usize:u64 conversions
Signed-off-by: Abhik Jain <[email protected]>
1 parent 912c375 commit 23a9a68

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ mod segment;
77
use disk::DiskHandler;
88
use segment::Segment;
99

10+
// asdsa
11+
/// asdsadsa
12+
1013
/// The log which can store commits in memory, and push them onto disk when needed, as well as read
1114
/// from disk any valid segment. See [`Self::new`] for more information on how exactly log is
1215
/// stored onto disk.
@@ -24,17 +27,17 @@ pub struct CommitLog {
2427
/// well as last segment in memory.
2528
tail: u64,
2629
/// Maximum size of any segment in memory.
27-
max_segment_size: u64,
30+
max_segment_size: usize,
2831
/// Maximum number of segments in memory, apart from the active segment.
29-
max_segments: u64,
32+
max_segments: usize,
3033
/// The active segment, to which incoming [`Bytes`] are appended to. Note that the bytes are
3134
/// themselves not mutable.
3235
active_segment: Segment,
3336
/// Total size of active segment, used for enforcing the contraints.
3437
segments: VecDeque<Segment>,
3538
/// Total size of segments in memory apart from active_segment, used for enforcing the
3639
/// contraints.
37-
segments_size: u64,
40+
segments_size: usize,
3841
/// A set of opened file handles to all the segments stored onto the disk. This is optional.
3942
disk_handler: Option<DiskHandler>,
4043
}
@@ -45,7 +48,7 @@ impl CommitLog {
4548
/// `self.head` will be removed. If a valid path is passed, the directory will be created if
4649
/// does not exist, and the segment at `self.head` will be stored onto disk instead of simply
4750
/// being deleted.
48-
pub fn new(max_segment_size: u64, max_segments: u64, dir: Option<PathBuf>) -> io::Result<Self> {
51+
pub fn new(max_segment_size: usize, max_segments: usize, dir: Option<PathBuf>) -> io::Result<Self> {
4952
if max_segment_size < 1024 {
5053
return Err(io::Error::new(
5154
io::ErrorKind::InvalidInput,
@@ -116,7 +119,7 @@ impl CommitLog {
116119

117120
fn apply_retention(&mut self) -> io::Result<()> {
118121
if self.active_segment.size() >= self.max_segment_size {
119-
if self.segments.len() as u64 >= self.max_segments {
122+
if self.segments.len() >= self.max_segments {
120123
// TODO: unwrap might cause error if self.max_segments == 0
121124
let removed_segment = self.segments.pop_front().unwrap();
122125
self.segments_size -= removed_segment.size();

src/segment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use bytes::Bytes;
99
#[derive(Debug)]
1010
pub(super) struct Segment {
1111
data: Vec<(Bytes, u64)>,
12-
size: u64,
12+
size: usize,
1313
start_time: u64,
1414
end_time: u64,
1515
}
@@ -18,9 +18,9 @@ pub(super) struct Segment {
1818
impl Segment {
1919
/// Create a new segment with given capacity.
2020
#[inline]
21-
pub(super) fn with_capacity(capacity: u64) -> Self {
21+
pub(super) fn with_capacity(capacity: usize) -> Self {
2222
Self {
23-
data: Vec::with_capacity(capacity as usize),
23+
data: Vec::with_capacity(capacity),
2424
size: 0,
2525
start_time: 0,
2626
end_time: 0,
@@ -32,7 +32,7 @@ impl Segment {
3232
#[allow(dead_code)]
3333
#[inline]
3434
pub(super) fn new(capacity: u64, byte: Bytes, timestamp: u64) -> Self {
35-
let size = byte.len() as u64;
35+
let size = byte.len();
3636
let mut data = Vec::with_capacity(capacity as usize);
3737
data.push((byte, timestamp));
3838

@@ -58,7 +58,7 @@ impl Segment {
5858
}
5959

6060
self.end_time = now;
61-
self.size += byte.len() as u64;
61+
self.size += byte.len();
6262
self.data.push((byte, now));
6363
}
6464

@@ -72,7 +72,7 @@ impl Segment {
7272
}
7373

7474
self.end_time = timestamp;
75-
self.size += byte.len() as u64;
75+
self.size += byte.len();
7676
self.data.push((byte, timestamp));
7777
}
7878

@@ -119,7 +119,7 @@ impl Segment {
119119

120120
/// Get the total size in bytes of the segment.
121121
#[inline]
122-
pub(super) fn size(&self) -> u64 {
122+
pub(super) fn size(&self) -> usize {
123123
self.size
124124
}
125125

0 commit comments

Comments
 (0)