Skip to content

Commit 3101c7e

Browse files
committed
Minor fixes
- Create WAL/segments directories (if don't exist) when loading edge shard - Fix panic when handling offset during search - Add trailing commas to `format` macro calls
1 parent c87074c commit 3101c7e

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

lib/edge/src/lib.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::num::NonZero;
22
use std::path::{Path, PathBuf};
33
use std::sync::Arc;
44
use std::sync::atomic::AtomicBool;
5-
use std::{fmt, fs};
5+
use std::{cmp, fmt, fs};
66

77
use common::counter::hardware_accumulator::HwMeasurementAcc;
88
use common::counter::hardware_counter::HardwareCounterCell;
@@ -36,19 +36,39 @@ const SEGMENTS_PATH: &str = "segments";
3636
impl Shard {
3737
pub fn load(path: &Path, mut config: Option<SegmentConfig>) -> OperationResult<Self> {
3838
let wal_path = path.join(WAL_PATH);
39+
40+
if !wal_path.exists() {
41+
fs::create_dir(&wal_path).map_err(|err| {
42+
OperationError::service_error(format!(
43+
"failed to create WAL directory {}: {err}",
44+
wal_path.display(),
45+
))
46+
})?;
47+
}
48+
3949
let wal: SerdeWal<CollectionUpdateOperations> =
4050
SerdeWal::new(&wal_path, default_wal_options()).map_err(|err| {
4151
OperationError::service_error(format!(
4252
"failed to open WAL {}: {err}",
43-
wal_path.display()
53+
wal_path.display(),
4454
))
4555
})?;
4656

4757
let segments_path = path.join(SEGMENTS_PATH);
58+
59+
if !segments_path.exists() {
60+
fs::create_dir(&segments_path).map_err(|err| {
61+
OperationError::service_error(format!(
62+
"failed to create segmens directory {}: {err}",
63+
segments_path.display(),
64+
))
65+
})?;
66+
}
67+
4868
let segments_dir = fs::read_dir(&segments_path).map_err(|err| {
4969
OperationError::service_error(format!(
5070
"failed to read segments directory {}: {err}",
51-
segments_path.display()
71+
segments_path.display(),
5272
))
5373
})?;
5474

@@ -58,7 +78,7 @@ impl Shard {
5878
let entry = entry.map_err(|err| {
5979
OperationError::service_error(format!(
6080
"failed to read entry in segments directory {}: {err}",
61-
segments_path.display()
81+
segments_path.display(),
6282
))
6383
})?;
6484

@@ -79,15 +99,15 @@ impl Shard {
7999
{
80100
log::warn!(
81101
"Skipping hidden segment directory {}",
82-
segment_path.display()
102+
segment_path.display(),
83103
);
84104
continue;
85105
}
86106

87107
let segment = load_segment(&segment_path, &AtomicBool::new(false)).map_err(|err| {
88108
OperationError::service_error(format!(
89109
"failed to load segment {}: {err}",
90-
segment_path.display()
110+
segment_path.display(),
91111
))
92112
})?;
93113

@@ -119,7 +139,7 @@ impl Shard {
119139
segment.check_consistency_and_repair().map_err(|err| {
120140
OperationError::service_error(format!(
121141
"failed to repair segment {}: {err}",
122-
segment_path.display()
142+
segment_path.display(),
123143
))
124144
})?;
125145

@@ -300,7 +320,7 @@ impl Shard {
300320
}
301321
}
302322

303-
let _ = points.drain(..offset);
323+
let _ = points.drain(..cmp::min(points.len(), offset));
304324

305325
Ok(points)
306326
}

0 commit comments

Comments
 (0)