fix(admin): skip oversized blobs during migration instead of aborting

This commit is contained in:
rustmailer
2026-07-16 05:22:10 +08:00
parent a88b5c84f3
commit c468f8be41
2 changed files with 66 additions and 14 deletions
+50 -10
View File
@@ -469,15 +469,35 @@ impl NewIndexWriterV2 {
self.email_buf.dedup_by(|a, b| a.0 == b.0);
let count = self.email_buf.len();
let mut skipped = 0usize;
for (key, data) in &self.email_buf {
self.engine.put(*key, data, Codec::Zstd).map_err(|e| {
raise_error!(
if let Err(e) = self.engine.put(*key, data, Codec::Zstd) {
if matches!(e, bichon_blob::Error::ValueTooLarge { .. }) {
eprintln!(
"{}",
console::style(format!(
"WARN: skipping oversized email blob key={} ({} bytes)",
hex::encode(*key),
data.len()
))
.yellow()
);
skipped += 1;
continue;
}
return Err(raise_error!(
format!("blob engine put error: {e:#?}"),
ErrorCode::InternalError
)
})?;
));
}
}
println!("flushed {} email blobs to engine", count - skipped);
if skipped > 0 {
eprintln!(
"{}",
console::style(format!("skipped {} oversized email blobs", skipped)).yellow()
);
}
println!("flushed {} email blobs to engine", count);
self.email_buf.clear();
}
@@ -486,15 +506,35 @@ impl NewIndexWriterV2 {
self.attachment_buf.dedup_by(|a, b| a.0 == b.0);
let count = self.attachment_buf.len();
let mut skipped = 0usize;
for (key, data) in &self.attachment_buf {
self.engine.put(*key, data, Codec::Zstd).map_err(|e| {
raise_error!(
if let Err(e) = self.engine.put(*key, data, Codec::Zstd) {
if matches!(e, bichon_blob::Error::ValueTooLarge { .. }) {
eprintln!(
"{}",
console::style(format!(
"WARN: skipping oversized attachment blob key={} ({} bytes)",
hex::encode(*key),
data.len()
))
.yellow()
);
skipped += 1;
continue;
}
return Err(raise_error!(
format!("blob engine put error: {e:#?}"),
ErrorCode::InternalError
)
})?;
));
}
}
println!("flushed {} attachment blobs to engine", count - skipped);
if skipped > 0 {
eprintln!(
"{}",
console::style(format!("skipped {} oversized attachment blobs", skipped)).yellow()
);
}
println!("flushed {} attachment blobs to engine", count);
self.attachment_buf.clear();
}
+16 -4
View File
@@ -65,12 +65,24 @@ fn migrate_keyspace(
continue;
}
let raw_key = hex_key_to_raw(&key_bytes)?;
engine.put(raw_key, &value, Codec::Zstd).map_err(|e| {
raise_error!(
if let Err(e) = engine.put(raw_key, &value, Codec::Zstd) {
if matches!(e, bichon_blob::Error::ValueTooLarge { .. }) {
eprintln!(
"{}",
console::style(format!(
"WARN: skipping oversized blob key={} ({} bytes)",
hex::encode(raw_key),
value.len()
))
.yellow()
);
continue;
}
return Err(raise_error!(
format!("bichon-blob put error: {e:#?}"),
ErrorCode::InternalError
)
})?;
));
}
count += 1;
if count % 1000 == 0 {
pb.set_message(format!("{label}: {} blobs migrated...", count));