mirror of
https://github.com/block/buzz.git
synced 2026-11-26 11:12:22 +00:00
fix(media): verify legacy cleanup bytes
Co-authored-by: Brad Seiler <seiler@squareup.com> Signed-off-by: Brad Seiler <seiler@squareup.com>
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
//! Idempotently copy legacy media payloads into the sharded layout.
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use buzz_media::migration::{
|
||||
objects_for_sidecar, parse_sidecar_key, MigrationObject, RequestPacer,
|
||||
};
|
||||
use buzz_media::MediaStorage;
|
||||
use buzz_media::migration::{objects_for_sidecar, parse_sidecar_key, RequestPacer};
|
||||
use clap::Parser;
|
||||
|
||||
mod media_layout_common;
|
||||
use media_layout_common::CommonArgs;
|
||||
use media_layout_common::{verify_destination, CommonArgs};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "buzz-media-layout-backfill")]
|
||||
@@ -20,34 +17,6 @@ struct Args {
|
||||
dry_run: bool,
|
||||
}
|
||||
|
||||
async fn verify_destination(
|
||||
storage: &MediaStorage,
|
||||
pacer: &mut RequestPacer,
|
||||
object: &MigrationObject,
|
||||
) -> Result<bool> {
|
||||
pacer.wait().await;
|
||||
let source = storage
|
||||
.get(&object.legacy)
|
||||
.await
|
||||
.with_context(|| format!("read legacy source for verification: {}", object.legacy))?;
|
||||
|
||||
pacer.wait().await;
|
||||
let destination = match storage.get(&object.sharded).await {
|
||||
Ok(bytes) => bytes,
|
||||
Err(buzz_media::MediaError::NotFound) => return Ok(false),
|
||||
Err(error) => {
|
||||
return Err(error).with_context(|| {
|
||||
format!(
|
||||
"read sharded destination for verification: {}",
|
||||
object.sharded
|
||||
)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Ok(destination == source)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
tracing_subscriber::fmt().with_target(false).init();
|
||||
|
||||
@@ -6,7 +6,7 @@ use buzz_media::MediaStorage;
|
||||
use clap::Parser;
|
||||
|
||||
mod media_layout_common;
|
||||
use media_layout_common::CommonArgs;
|
||||
use media_layout_common::{verify_destination, CommonArgs};
|
||||
|
||||
const CONFIRMATION: &str = "delete-verified-legacy-media";
|
||||
|
||||
@@ -61,14 +61,14 @@ async fn scan(
|
||||
.context("read media sidecar")?;
|
||||
let meta = serde_json::from_slice(&bytes).context("parse media sidecar")?;
|
||||
for object in objects_for_sidecar(community, sha, &meta)? {
|
||||
pacer.wait().await;
|
||||
if !storage.head(&object.sharded).await? {
|
||||
anyhow::bail!(
|
||||
"refusing deletion: sharded destination missing: {} (checkpoint: {sidecar_key})",
|
||||
object.sharded
|
||||
);
|
||||
}
|
||||
if !delete {
|
||||
pacer.wait().await;
|
||||
if !storage.head(&object.sharded).await? {
|
||||
anyhow::bail!(
|
||||
"refusing deletion: sharded destination missing: {} (checkpoint: {sidecar_key})",
|
||||
object.sharded
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
pacer.wait().await;
|
||||
@@ -79,6 +79,12 @@ async fn scan(
|
||||
if dry_run {
|
||||
tracing::info!(key = %object.legacy, "would delete verified legacy object");
|
||||
} else {
|
||||
if !verify_destination(storage, pacer, &object).await? {
|
||||
anyhow::bail!(
|
||||
"refusing deletion: sharded destination bytes do not match legacy source: {} (checkpoint: {sidecar_key})",
|
||||
object.sharded
|
||||
);
|
||||
}
|
||||
pacer.wait().await;
|
||||
storage.delete(&object.legacy).await?;
|
||||
changed += 1;
|
||||
@@ -108,7 +114,7 @@ async fn main() -> Result<()> {
|
||||
let mut pacer = RequestPacer::new(args.common.requests_per_second);
|
||||
let (_, _, verified_checkpoint) =
|
||||
scan(&storage, &args.common, &mut pacer, false, args.dry_run).await?;
|
||||
tracing::info!(checkpoint = ?verified_checkpoint, "all selected sharded destinations verified; beginning deletion pass");
|
||||
tracing::info!(checkpoint = ?verified_checkpoint, "all selected sharded destinations exist; beginning deletion pass");
|
||||
let (deleted, skipped, checkpoint) =
|
||||
scan(&storage, &args.common, &mut pacer, true, args.dry_run).await?;
|
||||
tracing::info!(deleted, skipped, dry_run = args.dry_run, checkpoint = ?checkpoint, "legacy deletion complete");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use anyhow::{bail, Context, Result};
|
||||
use buzz_media::{MediaConfig, MediaMigrationPhase, MediaStorage, S3AddressingStyle};
|
||||
use buzz_media::migration::{MigrationObject, RequestPacer};
|
||||
use buzz_media::{MediaConfig, MediaError, MediaMigrationPhase, MediaStorage, S3AddressingStyle};
|
||||
use clap::Args;
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
@@ -30,6 +31,34 @@ pub struct CommonArgs {
|
||||
pub page_size: usize,
|
||||
}
|
||||
|
||||
pub async fn verify_destination(
|
||||
storage: &MediaStorage,
|
||||
pacer: &mut RequestPacer,
|
||||
object: &MigrationObject,
|
||||
) -> Result<bool> {
|
||||
pacer.wait().await;
|
||||
let source = storage
|
||||
.get(&object.legacy)
|
||||
.await
|
||||
.with_context(|| format!("read legacy source for verification: {}", object.legacy))?;
|
||||
|
||||
pacer.wait().await;
|
||||
let destination = match storage.get(&object.sharded).await {
|
||||
Ok(bytes) => bytes,
|
||||
Err(MediaError::NotFound) => return Ok(false),
|
||||
Err(error) => {
|
||||
return Err(error).with_context(|| {
|
||||
format!(
|
||||
"read sharded destination for verification: {}",
|
||||
object.sharded
|
||||
)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Ok(destination == source)
|
||||
}
|
||||
|
||||
impl CommonArgs {
|
||||
pub fn storage(&self) -> Result<MediaStorage> {
|
||||
if self.requests_per_second == 0 {
|
||||
|
||||
Reference in New Issue
Block a user