Skip to content

Commit 24200cd

Browse files
committed
improve data block tests #205
1 parent e35ef40 commit 24200cd

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/table/block_index/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,21 @@ impl BlockIndex for BlockIndexImpl {
9999
Self::Full(index) => index.forward_reader(needle).map(BlockIndexIterImpl::Full),
100100
Self::VolatileFull(index) => {
101101
let mut it = index.iter();
102-
it.seek_lower(needle);
103-
Some(BlockIndexIterImpl::Volatile(it))
102+
103+
if it.seek_lower(needle) {
104+
Some(BlockIndexIterImpl::Volatile(it))
105+
} else {
106+
None
107+
}
104108
}
105109
Self::TwoLevel(index) => {
106110
let mut it = index.iter();
107-
it.seek_lower(needle);
108-
Some(BlockIndexIterImpl::TwoLevel(it))
111+
112+
if it.seek_lower(needle) {
113+
Some(BlockIndexIterImpl::TwoLevel(it))
114+
} else {
115+
None
116+
}
109117
}
110118
}
111119
}

src/table/data_block/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,15 @@ impl DataBlock {
336336
let mut reader = unwrap!(trailer.as_slice().get(offset..));
337337

338338
let hash_index_len = unwrap!(reader.read_u32::<LittleEndian>());
339+
let hash_index_offset = unwrap!(reader.read_u32::<LittleEndian>());
339340

340341
if hash_index_len == 0 {
342+
debug_assert_eq!(
343+
0, hash_index_offset,
344+
"hash index offset should be 0 if its length is 0"
345+
);
341346
None
342347
} else {
343-
let hash_index_offset = unwrap!(reader.read_u32::<LittleEndian>());
344-
345348
Some(HashIndexReader::new(
346349
&self.inner.data,
347350
hash_index_offset,
@@ -823,6 +826,7 @@ mod tests {
823826
});
824827

825828
assert_eq!(data_block.len(), items.len());
829+
assert_eq!(4, data_block.binary_index_len());
826830

827831
for needle in items {
828832
assert_eq!(
@@ -904,6 +908,7 @@ mod tests {
904908
});
905909

906910
assert_eq!(data_block.len(), items.len());
911+
assert!(data_block.get_hash_index_reader().is_none());
907912

908913
assert_eq!(
909914
Some(items.get(1).cloned().unwrap()),

0 commit comments

Comments
 (0)