Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: out of range error in module ObjectStore base on OBKV #1089

Merged
merged 6 commits into from
Jul 21, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions components/object_store/src/obkv/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,13 @@ impl ObkvObjectMeta {
let batch_size = self.part_size;
let start_index = range.start / batch_size;
let start_offset = range.start % batch_size;
let end_index = range.end / batch_size;
let end_offset = range.end % batch_size;
let mut end_index = range.end / batch_size;
let mut end_offset = range.end % batch_size;

if end_offset == 0 {
end_index -= 1;
jiacai2050 marked this conversation as resolved.
Show resolved Hide resolved
end_offset = batch_size;
}

Ok(ConveredParts {
part_keys: &self.parts[start_index..=end_index],
Expand Down Expand Up @@ -213,7 +218,7 @@ impl<T: TableKv> MetaManager<T> {
pub async fn save(&self, meta: ObkvObjectMeta) -> Result<()> {
let mut batch = T::WriteBatch::default();
let encode_bytes = meta.encode()?;
batch.insert(meta.location.as_bytes(), &encode_bytes);
batch.insert_or_update(meta.location.as_bytes(), &encode_bytes);
self.client
.as_ref()
.write(WriteContext::default(), OBJECT_STORE_META, batch)
Expand Down Expand Up @@ -320,6 +325,15 @@ mod test {
assert!(expect.start_offset == 0);
assert!(expect.end_offset == 1);

let range1 = Range {
start: 0,
end: 1024,
};
let expect = meta.compute_covered_parts(range1).unwrap();
assert!(expect.part_keys.len() == 1);
assert!(expect.start_offset == 0);
assert!(expect.end_offset == 1024);

let range1 = Range {
start: 0,
end: 8190,
Expand Down Expand Up @@ -353,6 +367,16 @@ mod test {
};
let expect = meta.compute_covered_parts(range1);
assert!(expect.is_err());

let meta = build_test_meta1();
let range1 = Range {
start: 0,
end: 1024,
};
let expect = meta.compute_covered_parts(range1).unwrap();
assert!(expect.part_keys.len() == 1);
assert!(expect.start_offset == 0);
assert!(expect.end_offset == 1024);
}

fn build_test_meta() -> ObkvObjectMeta {
Expand All @@ -375,4 +399,16 @@ mod test {
version: String::from("123456fsdalfkassa;l;kjfaklasadffsd"),
}
}

fn build_test_meta1() -> ObkvObjectMeta {
MichaelLeeHZ marked this conversation as resolved.
Show resolved Hide resolved
ObkvObjectMeta {
location: String::from("/test/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxfdsfjlajflk"),
last_modified: 123456789,
size: 1024,
unique_id: Some(String::from("1245689u438uferjalfjkda")),
part_size: 1024,
parts: vec![String::from("/test/xx/0")],
version: String::from("123456fsdalfkassa;l;kjfaklasadffsd"),
}
}
}