Skip to content

Commit c8db3cf

Browse files
committed
Fix type mismatch and clean up minor warnings; tests pass for atomic_lib.
- Map sled IVec -> Vec<u8) on fallback - Remove redundant clone and unused variable - Documented fastest operator benchmarking initialization comments remain
1 parent 8d462b0 commit c8db3cf

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

lib/src/db.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Db {
102102

103103
// OpenDAL operator: Sled (on-disk)
104104
let mut dal_sled = opendal::services::Sled::default();
105-
let dal_path = path.clone().join("opendal");
105+
let dal_path = path.join("opendal");
106106
dal_sled
107107
.datadir(dal_path.to_str().expect("wrong data dir string"))
108108
.tree("resources_v1");
@@ -118,28 +118,37 @@ impl Db {
118118
.finish();
119119

120120
// Simple speed check: write+read small payload and measure read latency
121-
fn measure_read_ns(rt: &tokio::runtime::Runtime, op: &opendal::Operator) -> AtomicResult<u128> {
121+
fn measure_read_ns(
122+
rt: &tokio::runtime::Runtime,
123+
op: &opendal::Operator,
124+
) -> AtomicResult<u128> {
122125
use std::time::Instant;
123126
rt.block_on(async {
124127
let key = format!("bench_{}", uuid::Uuid::new_v4());
125128
let payload = b"atomic-bench".to_vec();
126-
op.write(&key, payload).await.map_err(|e| format!("bench write error: {e}"))?;
129+
op.write(&key, payload)
130+
.await
131+
.map_err(|e| format!("bench write error: {e}"))?;
127132
let start = Instant::now();
128-
let _ = op.read(&key).await.map_err(|e| format!("bench read error: {e}"))?;
133+
let _ = op
134+
.read(&key)
135+
.await
136+
.map_err(|e| format!("bench read error: {e}"))?;
129137
let ns = start.elapsed().as_nanos();
130138
// best-effort cleanup
131139
let _ = op.delete(&key).await;
132140
Ok::<u128, String>(ns)
133-
}).map_err(|e| e.into())
141+
})
142+
.map_err(|e| e.into())
134143
}
135144

136145
let sled_ns = measure_read_ns(&rt, &sled_op)?;
137146
let dash_ns = measure_read_ns(&rt, &dash_op)?;
138147

139-
let (fastest_name, fastest_op) = if dash_ns <= sled_ns {
140-
("dashmap".to_string(), dash_op.clone())
148+
let fastest_op = if dash_ns <= sled_ns {
149+
dash_op.clone()
141150
} else {
142-
("sled".to_string(), sled_op.clone())
151+
sled_op.clone()
143152
};
144153

145154
let mut dal_ops = std::collections::HashMap::new();
@@ -239,10 +248,12 @@ impl Db {
239248
});
240249
// Fallback to Sled resources tree if OpenDAL miss
241250
if propval_maybe.is_none() {
251+
// Map sled IVec into Vec<u8> to match OpenDAL read type
242252
propval_maybe = self
243253
.resources
244254
.get(subject.as_bytes())
245-
.map_err(|e| format!("Can't open {} from sled resources: {}", subject, e))?;
255+
.map_err(|e| format!("Can't open {} from sled resources: {}", subject, e))?
256+
.map(|ivec| ivec.to_vec());
246257
}
247258
match propval_maybe.as_ref() {
248259
Some(binpropval) => {

0 commit comments

Comments
 (0)