mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-19 02:56:18 +00:00
fix(ecstore): address review comments for batch shard pread (#5680)
fix: address review comments for batch shard pread
This commit is contained in:
@@ -6701,7 +6701,7 @@ pub(crate) async fn batch_shard_pread(requests: Vec<(std::path::PathBuf, usize,
|
|||||||
let r = (|| -> Result<Bytes> {
|
let r = (|| -> Result<Bytes> {
|
||||||
let meta = std::fs::metadata(&file_path).map_err(DiskError::from)?;
|
let meta = std::fs::metadata(&file_path).map_err(DiskError::from)?;
|
||||||
let end = offset.checked_add(length).ok_or(DiskError::FileCorrupt)?;
|
let end = offset.checked_add(length).ok_or(DiskError::FileCorrupt)?;
|
||||||
if meta.len() < end as u64 {
|
if meta.len() < u64::try_from(end).unwrap_or(u64::MAX) {
|
||||||
return Err(DiskError::FileCorrupt);
|
return Err(DiskError::FileCorrupt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6710,7 +6710,7 @@ pub(crate) async fn batch_shard_pread(requests: Vec<(std::path::PathBuf, usize,
|
|||||||
let mut total = 0usize;
|
let mut total = 0usize;
|
||||||
while total < length {
|
while total < length {
|
||||||
let nbytes = file
|
let nbytes = file
|
||||||
.read_at(&mut buf[total..], (offset + total) as u64)
|
.read_at(&mut buf[total..], u64::try_from(offset + total).unwrap_or(u64::MAX))
|
||||||
.map_err(DiskError::from)?;
|
.map_err(DiskError::from)?;
|
||||||
if nbytes == 0 {
|
if nbytes == 0 {
|
||||||
return Err(DiskError::FileCorrupt);
|
return Err(DiskError::FileCorrupt);
|
||||||
@@ -17986,5 +17986,6 @@ mod test {
|
|||||||
assert!(results[0].is_ok());
|
assert!(results[0].is_ok());
|
||||||
assert_eq!(results[0].as_ref().unwrap().as_ref(), b"good data");
|
assert_eq!(results[0].as_ref().unwrap().as_ref(), b"good data");
|
||||||
assert!(results[1].is_err());
|
assert!(results[1].is_err());
|
||||||
|
assert!(matches!(results[1].as_ref().unwrap_err(), DiskError::Io(_)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ use metrics::counter;
|
|||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet, VecDeque},
|
collections::{HashMap, HashSet, VecDeque},
|
||||||
future::Future,
|
future::Future,
|
||||||
io::Cursor,
|
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
sync::OnceLock,
|
sync::OnceLock,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
@@ -1425,6 +1424,7 @@ async fn try_create_bitrot_readers_via_batch_pread(
|
|||||||
skip_verify_bitrot: bool,
|
skip_verify_bitrot: bool,
|
||||||
) -> Option<BitrotReaderSetup> {
|
) -> Option<BitrotReaderSetup> {
|
||||||
use crate::disk::local::batch_shard_pread;
|
use crate::disk::local::batch_shard_pread;
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
let (adj_off, adj_len) = adjust_shard_read_params(read_offset, read_length, shard_size, &checksum_algo);
|
let (adj_off, adj_len) = adjust_shard_read_params(read_offset, read_length, shard_size, &checksum_algo);
|
||||||
if adj_len > object_mmap_read_max_length() {
|
if adj_len > object_mmap_read_max_length() {
|
||||||
|
|||||||
Reference in New Issue
Block a user