mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
fix(admin): skip oversized blobs during migration instead of aborting
This commit is contained in:
@@ -469,15 +469,35 @@ impl NewIndexWriterV2 {
|
|||||||
self.email_buf.dedup_by(|a, b| a.0 == b.0);
|
self.email_buf.dedup_by(|a, b| a.0 == b.0);
|
||||||
|
|
||||||
let count = self.email_buf.len();
|
let count = self.email_buf.len();
|
||||||
|
let mut skipped = 0usize;
|
||||||
for (key, data) in &self.email_buf {
|
for (key, data) in &self.email_buf {
|
||||||
self.engine.put(*key, data, Codec::Zstd).map_err(|e| {
|
if let Err(e) = self.engine.put(*key, data, Codec::Zstd) {
|
||||||
raise_error!(
|
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:#?}"),
|
format!("blob engine put error: {e:#?}"),
|
||||||
ErrorCode::InternalError
|
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();
|
self.email_buf.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,15 +506,35 @@ impl NewIndexWriterV2 {
|
|||||||
self.attachment_buf.dedup_by(|a, b| a.0 == b.0);
|
self.attachment_buf.dedup_by(|a, b| a.0 == b.0);
|
||||||
|
|
||||||
let count = self.attachment_buf.len();
|
let count = self.attachment_buf.len();
|
||||||
|
let mut skipped = 0usize;
|
||||||
for (key, data) in &self.attachment_buf {
|
for (key, data) in &self.attachment_buf {
|
||||||
self.engine.put(*key, data, Codec::Zstd).map_err(|e| {
|
if let Err(e) = self.engine.put(*key, data, Codec::Zstd) {
|
||||||
raise_error!(
|
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:#?}"),
|
format!("blob engine put error: {e:#?}"),
|
||||||
ErrorCode::InternalError
|
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();
|
self.attachment_buf.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,12 +65,24 @@ fn migrate_keyspace(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let raw_key = hex_key_to_raw(&key_bytes)?;
|
let raw_key = hex_key_to_raw(&key_bytes)?;
|
||||||
engine.put(raw_key, &value, Codec::Zstd).map_err(|e| {
|
if let Err(e) = engine.put(raw_key, &value, Codec::Zstd) {
|
||||||
raise_error!(
|
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:#?}"),
|
format!("bichon-blob put error: {e:#?}"),
|
||||||
ErrorCode::InternalError
|
ErrorCode::InternalError
|
||||||
)
|
));
|
||||||
})?;
|
}
|
||||||
count += 1;
|
count += 1;
|
||||||
if count % 1000 == 0 {
|
if count % 1000 == 0 {
|
||||||
pb.set_message(format!("{label}: {} blobs migrated...", count));
|
pb.set_message(format!("{label}: {} blobs migrated...", count));
|
||||||
|
|||||||
Reference in New Issue
Block a user