libblobd_direct/op/
inspect_object.rs

1use super::OpError;
2use super::OpResult;
3use crate::ctx::Ctx;
4use chrono::DateTime;
5use chrono::Utc;
6use std::sync::atomic::Ordering::Relaxed;
7use std::sync::Arc;
8
9pub struct OpInspectObjectInput {
10  pub key: Vec<u8>,
11  // Only useful if versioning is enabled.
12  pub id: Option<u128>,
13}
14
15pub struct OpInspectObjectOutput {
16  pub id: u128,
17  pub size: u64,
18  pub created: DateTime<Utc>,
19}
20
21pub(crate) async fn op_inspect_object(
22  ctx: Arc<Ctx>,
23  req: OpInspectObjectInput,
24) -> OpResult<OpInspectObjectOutput> {
25  let Some(obj) = ctx
26    .committed_objects
27    .get(&req.key)
28    .filter(|o| req.id.is_none() || Some(o.id()) == req.id)
29    .map(|e| e.value().clone())
30  else {
31    return Err(OpError::ObjectNotFound);
32  };
33  ctx.metrics.0.inspect_op_count.fetch_add(1, Relaxed);
34  Ok(OpInspectObjectOutput {
35    id: obj.id(),
36    size: obj.size,
37    created: obj.created,
38  })
39}