forge
Explore
Log in

Don't you dare go Hollow

in

Clone
★ 0

0 watching0 forksRustAGPL-3.0528.7 KiB9215377Tahinli27 days ago37 commits

objects.rs648 lines, 24.5 KiBHistoryRawDownload
1//! The object store's rows (contracts.md 5): services, which are namespaces with a quota, and the objects
2//! each service keeps under its own ids.
3//!
4//! Namespace: every function takes the service key from the caller's verified token (`svc`). Nothing a
5//! request says picks the namespace, so the same `external_id` in two services is two rows.
6//!
7//! Blobs: an object's bytes live at `objects/<service>/<sha256>`, so objects of one service with the same
8//! bytes share one blob. A blob is removed only by [`Store::retire_blob`], and only when no row names it
9//! and no write is in the middle of storing it. [`Store::hold_blob`] is that write's claim on the key, taken
10//! before the bytes are put and released after the row commits.
11//!
12//! Quota: `services.used_bytes` is the sum of the sizes of the service's objects. A put checks the new total
13//! inside its write transaction, which the single writer serialises, so two parallel puts cannot both pass.
14
15use std::collections::HashMap;
16use std::sync::{Arc, Mutex as StdMutex, PoisonError};
17
18use turso::{Connection, Row};
19
20use crate::blob::BlobStore;
21use crate::error::{Error, Result};
22use crate::store::{
23 Inner, Store, col_int, col_opt_text, col_text, db_err, fetch_all, fetch_opt, finish,
24 missing_row,
25};
26use crate::time::now_stamp;
27
28/// Quota of a service that has none yet: 10 GiB. Used when a service first makes an authorised call.
29pub const DEFAULT_SERVICE_QUOTA: i64 = 10 * 1024 * 1024 * 1024;
30
31/// The settings key of the quota a new service gets. It is read when the service row is created.
32pub const SERVICE_QUOTA_SETTING: &str = "default_service_quota_bytes";
33
34/// Longest `external_id` the contracts allow.
35pub const MAX_EXTERNAL_ID: usize = 128;
36
37/// Checks an `external_id` against contracts.md 5: 1 to 128 characters of `[A-Za-z0-9._-]`. The id is
38/// never part of a path (blobs are named by hash), so the charset only has to keep ids printable and
39/// unambiguous.
40pub fn check_external_id(id: &str) -> Result<()> {
41 let allowed = id
42 .bytes()
43 .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'.' | b'_' | b'-'));
44 if id.is_empty() || id.len() > MAX_EXTERNAL_ID || !allowed {
45 return Err(Error::Invalid("bad_external_id".into()));
46 }
47 Ok(())
48}
49
50/// The blob key of an object's bytes: `objects/<service>/<sha256>`. The hash is lower-case hex.
51pub fn object_blob_key(service: &str, sha256: &str) -> String {
52 format!("objects/{service}/{sha256}")
53}
54
55/// Column list for [`map_service`]. Keep the two in step.
56const SERVICE_COLS: &str = "key, quota_bytes, used_bytes, created_at";
57
58/// Column list for [`map_object`]. Keep the two in step.
59const OBJECT_COLS: &str =
60 "service, external_id, size, sha256, content_type, name, blob_key, created_at, updated_at";
61
62/// A service: a namespace of objects with its own quota.
63#[derive(Debug, Clone, PartialEq, Eq)]
64pub struct Service {
65 /// The family key the token's `svc` named, such as `iz`.
66 pub key: String,
67 /// The most bytes the service may store.
68 pub quota_bytes: i64,
69 /// The bytes its objects use, counted once per object (shared blobs count twice).
70 pub used_bytes: i64,
71 /// When the service first made a call.
72 pub created_at: String,
73}
74
75/// One object of a service.
76#[derive(Debug, Clone, PartialEq, Eq)]
77pub struct Object {
78 /// The service that owns the object.
79 pub service: String,
80 /// The id the service chose.
81 pub external_id: String,
82 /// Length in bytes.
83 pub size: i64,
84 /// Lower-case hex SHA-256 of the bytes.
85 pub sha256: String,
86 /// The `Content-Type` the service sent, stored as given.
87 pub content_type: String,
88 /// The `X-Object-Name` the service sent, if any.
89 pub name: Option<String>,
90 /// The blob that holds the bytes.
91 pub blob_key: String,
92 /// When the object was first stored.
93 pub created_at: String,
94 /// When the object was last replaced.
95 pub updated_at: String,
96}
97
98/// A service's usage, as `GET /api/v1/usage` reports it.
99#[derive(Debug, Clone, PartialEq, Eq)]
100pub struct Usage {
101 /// The service quota.
102 pub quota_bytes: i64,
103 /// Bytes used by its objects.
104 pub used_bytes: i64,
105 /// Number of objects.
106 pub objects: i64,
107}
108
109/// What a put stores. The bytes are already at `blob_key`.
110#[derive(Debug, Clone, PartialEq, Eq)]
111pub struct NewObject {
112 /// The namespace, from the verified token.
113 pub service: String,
114 /// The id the service chose. Already checked by [`check_external_id`].
115 pub external_id: String,
116 /// Length in bytes.
117 pub size: i64,
118 /// Lower-case hex SHA-256 of the bytes.
119 pub sha256: String,
120 /// The stored `Content-Type`.
121 pub content_type: String,
122 /// The cleaned `X-Object-Name`, if any.
123 pub name: Option<String>,
124 /// When true, a put over an existing object is refused (`If-None-Match: *`).
125 pub create_only: bool,
126}
127
128/// What a put did.
129#[derive(Debug, Clone, PartialEq, Eq)]
130pub enum PutOutcome {
131 /// The row is stored. `replaced_blob` is the blob the old bytes lived at, when that blob is not the new
132 /// one. The caller retires it with [`Store::retire_blob`].
133 Stored {
134 /// The object as stored. Boxed, so the refusal variants stay small.
135 object: Box<Object>,
136 /// `true` when the id was new, `false` when an existing object was replaced.
137 created: bool,
138 /// The blob the replaced bytes used, when it differs from the new one.
139 replaced_blob: Option<String>,
140 },
141 /// The new total would exceed the service quota. Nothing changed.
142 QuotaExceeded,
143 /// `create_only` was set and the id is taken. Nothing changed.
144 Exists,
145}
146
147/// The claim a write holds on a blob key between putting the bytes and committing the row. While it is
148/// held, [`Store::retire_blob`] leaves the key alone.
149pub struct BlobHold {
150 inner: Arc<Inner>,
151 key: String,
152}
153
154impl Drop for BlobHold {
155 fn drop(&mut self) {
156 let mut held = self
157 .inner
158 .blobs
159 .held
160 .lock()
161 .unwrap_or_else(PoisonError::into_inner);
162 if let Some(count) = held.get_mut(&self.key) {
163 *count -= 1;
164 if *count == 0 {
165 held.remove(&self.key);
166 }
167 }
168 }
169}
170
171/// The gate that orders blob writes against blob removal. `retire` is held while a removal decides and
172/// deletes, and while a write registers its claim, so a removal and a write of the same key never overlap.
173/// `held` counts the open claims per key. Both are in-process, which is right for one `in` process.
174#[derive(Default)]
175pub(crate) struct BlobGate {
176 retire: tokio::sync::Mutex<()>,
177 held: StdMutex<HashMap<String, usize>>,
178}
179
180/// Column `i` of a row selected with [`SERVICE_COLS`].
181fn map_service(row: &Row) -> Result<Service> {
182 Ok(Service {
183 key: col_text(row, 0)?,
184 quota_bytes: col_int(row, 1)?,
185 used_bytes: col_int(row, 2)?,
186 created_at: col_text(row, 3)?,
187 })
188}
189
190/// Maps a row selected with [`OBJECT_COLS`].
191fn map_object(row: &Row) -> Result<Object> {
192 Ok(Object {
193 service: col_text(row, 0)?,
194 external_id: col_text(row, 1)?,
195 size: col_int(row, 2)?,
196 sha256: col_text(row, 3)?,
197 content_type: col_text(row, 4)?,
198 name: col_opt_text(row, 5)?,
199 blob_key: col_text(row, 6)?,
200 created_at: col_text(row, 7)?,
201 updated_at: col_text(row, 8)?,
202 })
203}
204
205/// A service row by key.
206async fn service_row(conn: &Connection, key: &str) -> Result<Option<Service>> {
207 fetch_opt(
208 conn,
209 &format!("SELECT {SERVICE_COLS} FROM services WHERE key = ?1"),
210 (key.to_owned(),),
211 map_service,
212 )
213 .await
214}
215
216/// An object of a service by its id. Another service's id finds nothing.
217async fn object_row(conn: &Connection, service: &str, id: &str) -> Result<Option<Object>> {
218 fetch_opt(
219 conn,
220 &format!("SELECT {OBJECT_COLS} FROM objects WHERE service = ?1 AND external_id = ?2"),
221 (service.to_owned(), id.to_owned()),
222 map_object,
223 )
224 .await
225}
226
227impl Store {
228 /// The service with this key, if it has made a call before.
229 pub async fn service(&self, key: &str) -> Result<Option<Service>> {
230 let conn = self.read_conn().await;
231 service_row(&conn, key).await
232 }
233
234 /// Every service, by key. For the admin page.
235 pub async fn services(&self) -> Result<Vec<Service>> {
236 let conn = self.read_conn().await;
237 fetch_all(
238 &conn,
239 &format!("SELECT {SERVICE_COLS} FROM services ORDER BY key"),
240 (),
241 map_service,
242 )
243 .await
244 }
245
246 /// The service with this key, created with `default_quota` when it is new. Called on every
247 /// authorised machine call, so the common case is a read.
248 pub async fn ensure_service(&self, key: &str, default_quota: i64) -> Result<Service> {
249 if let Some(service) = self.service(key).await? {
250 return Ok(service);
251 }
252 {
253 let conn = self.inner.conn.lock().await;
254 // `OR IGNORE` keeps a concurrent first call from failing on the primary key.
255 conn.execute(
256 "INSERT OR IGNORE INTO services (key, quota_bytes, used_bytes, created_at) \
257 VALUES (?1, ?2, 0, ?3)",
258 (key.to_owned(), default_quota, now_stamp()),
259 )
260 .await
261 .map_err(db_err)?;
262 }
263 self.service(key).await?.ok_or_else(missing_row)
264 }
265
266 /// Sets a service's quota in bytes. Lowering it below the current use is allowed: the service then
267 /// cannot store more until it frees space.
268 pub async fn set_service_quota(&self, key: &str, bytes: i64) -> Result<()> {
269 if bytes < 0 {
270 return Err(Error::Invalid("quota_negative".into()));
271 }
272 let conn = self.inner.conn.lock().await;
273 let changed = conn
274 .execute(
275 "UPDATE services SET quota_bytes = ?2 WHERE key = ?1",
276 (key.to_owned(), bytes),
277 )
278 .await
279 .map_err(db_err)?;
280 if changed == 0 {
281 return Err(Error::NotFound);
282 }
283 Ok(())
284 }
285
286 /// The usage of a service: quota, bytes used and the object count. A service that does not exist has
287 /// none, so the answer is `NotFound`.
288 pub async fn service_usage(&self, service: &str) -> Result<Usage> {
289 let conn = self.read_conn().await;
290 let row = service_row(&conn, service).await?.ok_or(Error::NotFound)?;
291 let objects = fetch_opt(
292 &conn,
293 "SELECT COUNT(*) FROM objects WHERE service = ?1",
294 (service.to_owned(),),
295 |row| col_int(row, 0),
296 )
297 .await?
298 .unwrap_or(0);
299 Ok(Usage {
300 quota_bytes: row.quota_bytes,
301 used_bytes: row.used_bytes,
302 objects,
303 })
304 }
305
306 /// An object of `service` by its id, or `None`.
307 pub async fn service_object(&self, service: &str, id: &str) -> Result<Option<Object>> {
308 let conn = self.read_conn().await;
309 object_row(&conn, service, id).await
310 }
311
312 /// Stores an object row, replacing the object with the same id in the same service. In one
313 /// transaction: the new total must fit the quota (the old object's bytes are given back first), the row
314 /// is inserted or updated, and `used_bytes` is moved by the difference. A replace keeps the original
315 /// `created_at`.
316 ///
317 /// The bytes must already be at the blob key of `new.sha256`. The old bytes are not removed here: the
318 /// caller retires `replaced_blob` after this returns.
319 pub async fn put_object(&self, new: NewObject) -> Result<PutOutcome> {
320 let now = now_stamp();
321 let conn = self.inner.conn.lock().await;
322 let tx = conn.unchecked_transaction().await.map_err(db_err)?;
323 let outcome: Result<PutOutcome> = async {
324 let service = service_row(&tx, &new.service)
325 .await?
326 .ok_or(Error::NotFound)?;
327 let old = object_row(&tx, &new.service, &new.external_id).await?;
328 if new.create_only && old.is_some() {
329 return Ok(PutOutcome::Exists);
330 }
331 let old_size = old.as_ref().map_or(0, |object| object.size);
332 let used_after = service.used_bytes - old_size + new.size;
333 if used_after > service.quota_bytes {
334 return Ok(PutOutcome::QuotaExceeded);
335 }
336 let blob_key = object_blob_key(&new.service, &new.sha256);
337 let created = old.is_none();
338 let created_at = old
339 .as_ref()
340 .map_or_else(|| now.clone(), |object| object.created_at.clone());
341 if created {
342 tx.execute(
343 "INSERT INTO objects (service, external_id, size, sha256, content_type, name, \
344 blob_key, created_at, updated_at) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
345 (
346 new.service.clone(),
347 new.external_id.clone(),
348 new.size,
349 new.sha256.clone(),
350 new.content_type.clone(),
351 new.name.clone(),
352 blob_key.clone(),
353 created_at,
354 now.clone(),
355 ),
356 )
357 .await
358 .map_err(db_err)?;
359 } else {
360 tx.execute(
361 "UPDATE objects SET size = ?3, sha256 = ?4, content_type = ?5, name = ?6, \
362 blob_key = ?7, updated_at = ?8 WHERE service = ?1 AND external_id = ?2",
363 (
364 new.service.clone(),
365 new.external_id.clone(),
366 new.size,
367 new.sha256.clone(),
368 new.content_type.clone(),
369 new.name.clone(),
370 blob_key.clone(),
371 now.clone(),
372 ),
373 )
374 .await
375 .map_err(db_err)?;
376 }
377 tx.execute(
378 "UPDATE services SET used_bytes = ?2 WHERE key = ?1",
379 (new.service.clone(), used_after),
380 )
381 .await
382 .map_err(db_err)?;
383 let object = object_row(&tx, &new.service, &new.external_id)
384 .await?
385 .ok_or_else(missing_row)?;
386 let replaced_blob = old
387 .map(|object| object.blob_key)
388 .filter(|key| *key != blob_key);
389 Ok(PutOutcome::Stored {
390 object: Box::new(object),
391 created,
392 replaced_blob,
393 })
394 }
395 .await;
396 finish(tx, outcome).await
397 }
398
399 /// Removes an object of `service` and gives its bytes back to the quota. Returns the removed row, so the
400 /// caller can retire its blob, or `None` when there was no such object (the caller still answers `204`).
401 pub async fn delete_object(&self, service: &str, id: &str) -> Result<Option<Object>> {
402 let conn = self.inner.conn.lock().await;
403 let tx = conn.unchecked_transaction().await.map_err(db_err)?;
404 let outcome: Result<Option<Object>> = async {
405 let Some(old) = object_row(&tx, service, id).await? else {
406 return Ok(None);
407 };
408 tx.execute(
409 "DELETE FROM objects WHERE service = ?1 AND external_id = ?2",
410 (service.to_owned(), id.to_owned()),
411 )
412 .await
413 .map_err(db_err)?;
414 tx.execute(
415 "UPDATE services SET used_bytes = used_bytes - ?2 WHERE key = ?1",
416 (service.to_owned(), old.size),
417 )
418 .await
419 .map_err(db_err)?;
420 Ok(Some(old))
421 }
422 .await;
423 finish(tx, outcome).await
424 }
425
426 /// Claims `key` for a write that is about to put bytes there. Waits for any removal in progress, so
427 /// the bytes cannot be removed between the put and the row. The claim lasts until the returned guard is
428 /// dropped, which the caller does once the row has committed (or the write has been refused).
429 pub async fn hold_blob(&self, key: &str) -> BlobHold {
430 let _gate = self.inner.blobs.retire.lock().await;
431 let mut held = self
432 .inner
433 .blobs
434 .held
435 .lock()
436 .unwrap_or_else(PoisonError::into_inner);
437 *held.entry(key.to_owned()).or_insert(0) += 1;
438 BlobHold {
439 inner: Arc::clone(&self.inner),
440 key: key.to_owned(),
441 }
442 }
443
444 /// Removes the blob at `key` when it is safe: no open claim holds it and no row names it. Returns
445 /// `true` when the blob was deleted. `false` means it is still in use, or in the middle of a write; the
446 /// sweeper finds it later if it is still unreferenced.
447 pub async fn retire_blob(&self, key: &str, blobs: &dyn BlobStore) -> Result<bool> {
448 let _gate = self.inner.blobs.retire.lock().await;
449 let claimed = self
450 .inner
451 .blobs
452 .held
453 .lock()
454 .unwrap_or_else(PoisonError::into_inner)
455 .contains_key(key);
456 if claimed || self.blob_is_named(key).await? {
457 return Ok(false);
458 }
459 blobs.delete(key).await?;
460 Ok(true)
461 }
462
463 /// Whether an object row names this blob key.
464 async fn blob_is_named(&self, key: &str) -> Result<bool> {
465 let conn = self.read_conn().await;
466 Ok(fetch_opt(
467 &conn,
468 "SELECT 1 FROM objects WHERE blob_key = ?1 LIMIT 1",
469 (key.to_owned(),),
470 |_| Ok(()),
471 )
472 .await?
473 .is_some())
474 }
475}
476
477#[cfg(test)]
478mod tests {
479 use super::*;
480 use crate::blob::local::LocalBlobs;
481 use crate::staging::StagedFile;
482
483 const SERVICE: &str = "iz";
484 const OTHER: &str = "im";
485
486 /// A store with two services (`iz` and `im`) at `quota`, and a blob tree in the same temp dir.
487 async fn setup(quota: i64) -> (tempfile::TempDir, Store, LocalBlobs) {
488 let dir = tempfile::tempdir().unwrap();
489 let store = Store::open(&dir.path().join("in.db")).await.unwrap();
490 store.ensure_service(SERVICE, quota).await.unwrap();
491 store.ensure_service(OTHER, quota).await.unwrap();
492 let blobs = LocalBlobs::new(dir.path().join("blobs")).unwrap();
493 (dir, store, blobs)
494 }
495
496 /// Stages `bytes`, puts them at their hash key as the API does, and returns the row input for them.
497 async fn stage(
498 dir: &tempfile::TempDir,
499 blobs: &LocalBlobs,
500 service: &str,
501 id: &str,
502 bytes: &[u8],
503 ) -> NewObject {
504 let mut staged = StagedFile::create(dir.path(), 1 << 20).await.unwrap();
505 staged.write(bytes).await.unwrap();
506 let staged = staged.finish().await.unwrap();
507 let key = object_blob_key(service, &staged.sha256);
508 blobs.put_file(&key, &staged.path).await.unwrap();
509 NewObject {
510 service: service.into(),
511 external_id: id.into(),
512 size: staged.size as i64,
513 sha256: staged.sha256,
514 content_type: "application/octet-stream".into(),
515 name: None,
516 create_only: false,
517 }
518 }
519
520 #[test]
521 fn external_ids_follow_the_contract_charset_and_length() {
522 assert!(check_external_id("task-1_a.b").is_ok());
523 assert!(check_external_id(&"a".repeat(128)).is_ok());
524 for bad in ["", "../x", "a/b", "a b", "ü", &"a".repeat(129)] {
525 assert!(check_external_id(bad).is_err(), "{bad:?}");
526 }
527 }
528
529 /// The same id in two services is two objects, each with its own bytes.
530 #[tokio::test]
531 async fn the_same_id_in_two_services_is_two_objects() {
532 let (dir, store, blobs) = setup(1 << 20).await;
533 let a = stage(&dir, &blobs, SERVICE, "same", b"alpha").await;
534 let b = stage(&dir, &blobs, OTHER, "same", b"beta!!").await;
535 store.put_object(a).await.unwrap();
536 store.put_object(b).await.unwrap();
537 let mine = store
538 .service_object(SERVICE, "same")
539 .await
540 .unwrap()
541 .unwrap();
542 let theirs = store.service_object(OTHER, "same").await.unwrap().unwrap();
543 assert_eq!(mine.size, 5);
544 assert_eq!(theirs.size, 6);
545 assert!(
546 store
547 .service_object(SERVICE, "missing")
548 .await
549 .unwrap()
550 .is_none()
551 );
552 }
553
554 /// A replace keeps one row, moves the quota by the difference, and names the old blob for retiring.
555 /// Retiring it removes the old bytes, because nothing else names them.
556 #[tokio::test]
557 async fn a_replace_keeps_one_row_and_the_old_bytes_go_when_unreferenced() {
558 let (dir, store, blobs) = setup(1 << 20).await;
559 let first = stage(&dir, &blobs, SERVICE, "doc", b"first version").await;
560 let old_key = object_blob_key(SERVICE, &first.sha256);
561 store.put_object(first).await.unwrap();
562
563 let second = stage(&dir, &blobs, SERVICE, "doc", b"second").await;
564 let new_key = object_blob_key(SERVICE, &second.sha256);
565 let PutOutcome::Stored {
566 created,
567 replaced_blob,
568 ..
569 } = store.put_object(second).await.unwrap()
570 else {
571 panic!("the replace must be stored");
572 };
573 assert!(!created);
574 assert_eq!(replaced_blob.as_deref(), Some(old_key.as_str()));
575 assert!(store.retire_blob(&old_key, &blobs).await.unwrap());
576
577 let usage = store.service_usage(SERVICE).await.unwrap();
578 assert_eq!(usage.objects, 1);
579 assert_eq!(usage.used_bytes, 6);
580 assert_eq!(blobs.size(&old_key).await.unwrap(), None);
581 assert_eq!(blobs.size(&new_key).await.unwrap(), Some(6));
582 }
583
584 /// Two objects with the same bytes share one blob. Deleting one keeps the bytes for the other.
585 #[tokio::test]
586 async fn identical_content_shares_a_blob_until_the_last_object_goes() {
587 let (dir, store, blobs) = setup(1 << 20).await;
588 let a = stage(&dir, &blobs, SERVICE, "a", b"same bytes").await;
589 let b = stage(&dir, &blobs, SERVICE, "b", b"same bytes").await;
590 let key = object_blob_key(SERVICE, &a.sha256);
591 store.put_object(a).await.unwrap();
592 store.put_object(b).await.unwrap();
593
594 let removed = store.delete_object(SERVICE, "a").await.unwrap().unwrap();
595 assert_eq!(removed.blob_key, key);
596 assert!(!store.retire_blob(&key, &blobs).await.unwrap());
597 assert_eq!(blobs.size(&key).await.unwrap(), Some(10));
598 assert!(store.service_object(SERVICE, "b").await.unwrap().is_some());
599
600 store.delete_object(SERVICE, "b").await.unwrap();
601 assert!(store.retire_blob(&key, &blobs).await.unwrap());
602 assert_eq!(blobs.size(&key).await.unwrap(), None);
603 assert_eq!(store.service_usage(SERVICE).await.unwrap().used_bytes, 0);
604 }
605
606 /// A put that would pass the quota is refused and changes nothing. A replace gives back its old size
607 /// first, so it may grow only as far as the quota allows.
608 #[tokio::test]
609 async fn the_quota_is_checked_inside_the_write() {
610 let (dir, store, blobs) = setup(10).await;
611 store
612 .put_object(stage(&dir, &blobs, SERVICE, "one", b"123456").await)
613 .await
614 .unwrap();
615 let outcome = store
616 .put_object(stage(&dir, &blobs, SERVICE, "two", b"12345").await)
617 .await
618 .unwrap();
619 assert_eq!(outcome, PutOutcome::QuotaExceeded);
620 assert!(
621 store
622 .service_object(SERVICE, "two")
623 .await
624 .unwrap()
625 .is_none()
626 );
627 assert_eq!(store.service_usage(SERVICE).await.unwrap().used_bytes, 6);
628
629 let grow = store
630 .put_object(stage(&dir, &blobs, SERVICE, "one", b"1234567890").await)
631 .await
632 .unwrap();
633 assert!(matches!(grow, PutOutcome::Stored { created: false, .. }));
634 assert_eq!(store.service_usage(SERVICE).await.unwrap().used_bytes, 10);
635 }
636
637 /// A blob that a write holds is not removed, even when no row names it yet.
638 #[tokio::test]
639 async fn a_held_blob_is_not_retired() {
640 let (dir, store, blobs) = setup(1 << 20).await;
641 let object = stage(&dir, &blobs, SERVICE, "x", b"pending").await;
642 let key = object_blob_key(SERVICE, &object.sha256);
643 let hold = store.hold_blob(&key).await;
644 assert!(!store.retire_blob(&key, &blobs).await.unwrap());
645 drop(hold);
646 assert!(store.retire_blob(&key, &blobs).await.unwrap());
647 }
648}