mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-02 22:26:21 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ecc80c137 | |||
| c7d828fe6a | |||
| 3a778c620f | |||
| c6b3cf8675 | |||
| 74615e94d3 | |||
| 5757f554ee |
@@ -32,14 +32,16 @@ use super::replication_storage_boundary::{
|
||||
pub struct ReplicationObjectBridge;
|
||||
|
||||
impl ReplicationObjectBridge {
|
||||
/// Builds a decision snapshot using the replication-request flag from the
|
||||
/// caller's authorized storage options.
|
||||
pub fn must_replicate_options(
|
||||
user_defined: &HashMap<String, String>,
|
||||
user_tags: String,
|
||||
status: ReplicationStatusType,
|
||||
op_type: ReplicationType,
|
||||
opts: ObjectOptions,
|
||||
replication_request: bool,
|
||||
) -> MustReplicateOptions {
|
||||
get_must_replicate_options(user_defined, user_tags, status, op_type, opts)
|
||||
get_must_replicate_options(user_defined, user_tags, status, op_type, replication_request)
|
||||
}
|
||||
|
||||
pub async fn must_replicate(bucket: &str, object: &str, options: MustReplicateOptions) -> ReplicateDecision {
|
||||
@@ -204,7 +206,7 @@ mod tests {
|
||||
String::new(),
|
||||
ReplicationStatusType::Empty,
|
||||
ReplicationType::Metadata,
|
||||
ObjectOptions::default(),
|
||||
false,
|
||||
);
|
||||
assert!(metadata.is_metadata_replication());
|
||||
assert!(!metadata.is_existing_object_replication());
|
||||
@@ -214,7 +216,7 @@ mod tests {
|
||||
String::new(),
|
||||
ReplicationStatusType::Empty,
|
||||
ReplicationType::ExistingObject,
|
||||
ObjectOptions::default(),
|
||||
false,
|
||||
);
|
||||
assert!(existing.is_existing_object_replication());
|
||||
assert!(!existing.is_metadata_replication());
|
||||
|
||||
@@ -396,9 +396,9 @@ pub(crate) fn get_must_replicate_options(
|
||||
user_tags: String,
|
||||
status: ReplicationStatusType,
|
||||
op_type: ReplicationType,
|
||||
opts: ObjectOptions,
|
||||
replication_request: bool,
|
||||
) -> MustReplicateOptions {
|
||||
MustReplicateOptions::new(user_defined, user_tags, op_type, opts.replication_request).with_replication_status(status)
|
||||
MustReplicateOptions::new(user_defined, user_tags, op_type, replication_request).with_replication_status(status)
|
||||
}
|
||||
|
||||
pub(crate) async fn check_replicate_delete(
|
||||
@@ -716,10 +716,7 @@ mod tests {
|
||||
"env=prod".to_string(),
|
||||
ReplicationStatusType::Empty,
|
||||
ReplicationType::Metadata,
|
||||
ObjectOptions {
|
||||
replication_request: true,
|
||||
..Default::default()
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
assert!(options.is_metadata_replication());
|
||||
|
||||
@@ -110,6 +110,18 @@ fn small_ingest_capacity(erasure: &Erasure, size_hint: usize) -> usize {
|
||||
}
|
||||
}
|
||||
|
||||
fn inline_ingest_capacity(erasure: &Erasure, size_hint: usize) -> std::io::Result<usize> {
|
||||
let capacity = small_ingest_capacity(erasure, size_hint);
|
||||
if capacity == 0 {
|
||||
return Ok(0);
|
||||
}
|
||||
erasure
|
||||
.total_shard_count()
|
||||
.checked_mul(HashAlgorithm::HighwayHash256S.size())
|
||||
.and_then(|hash_bytes| capacity.checked_add(hash_bytes))
|
||||
.ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidInput, "inline ingest capacity exceeds usize"))
|
||||
}
|
||||
|
||||
/// Keeps the encoder producer scoped to its parent future. Tokio detaches a
|
||||
/// task when its `JoinHandle` is dropped, so the producer must be aborted when
|
||||
/// an upload is cancelled before the encode pipeline finishes.
|
||||
@@ -930,25 +942,27 @@ impl Erasure {
|
||||
{
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
let mut buf = Vec::with_capacity(small_ingest_capacity(&self, size_hint));
|
||||
let total = reader.read_to_end(&mut buf).await?;
|
||||
// Match read_to_end's minimum allocation; a zero-capacity BytesMut
|
||||
// otherwise grows to 64 bytes even when its first read reaches EOF.
|
||||
let mut buf = BytesMut::with_capacity(inline_ingest_capacity(&self, size_hint)?.max(32));
|
||||
loop {
|
||||
match reader.read_buf(&mut buf).await {
|
||||
Ok(0) => break,
|
||||
Ok(_) => {}
|
||||
Err(err) if err.kind() == std::io::ErrorKind::Interrupted => continue,
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
let total = buf.len();
|
||||
if total == 0 {
|
||||
return Ok((reader, 0, Vec::new()));
|
||||
}
|
||||
|
||||
let block = self.encode_data_owned_block(buf)?;
|
||||
let block = self.encode_buffer_mut(buf, total)?;
|
||||
if let Some(integrity) = integrity {
|
||||
integrity.push(block.shards()).await?;
|
||||
}
|
||||
let shard_count = block.shards().len();
|
||||
let mut encoded = BytesMut::with_capacity(shard_count * 32 + block.queued_bytes());
|
||||
let mut inline_shards = Vec::with_capacity(shard_count);
|
||||
for shard in block.shards() {
|
||||
let hash = HashAlgorithm::HighwayHash256S.hash_encode(shard);
|
||||
encoded.extend_from_slice(hash.as_ref());
|
||||
encoded.extend_from_slice(shard);
|
||||
inline_shards.push(encoded.split().freeze());
|
||||
}
|
||||
let inline_shards = block.into_inline_shards()?;
|
||||
|
||||
Ok((reader, total, inline_shards))
|
||||
}
|
||||
@@ -3380,34 +3394,151 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn encode_inline_shards_matches_writer_bitrot_layout() {
|
||||
const DATA_SHARDS: usize = 2;
|
||||
const PARITY_SHARDS: usize = 2;
|
||||
const BLOCK_SIZE: usize = 64;
|
||||
let checksum_algo = HashAlgorithm::HighwayHash256S;
|
||||
for uses_legacy in [false, true] {
|
||||
let erasure = Arc::new(Erasure::new_with_options(DATA_SHARDS, PARITY_SHARDS, BLOCK_SIZE, uses_legacy));
|
||||
for payload in [Vec::new(), vec![0xA5], vec![0x5A; BLOCK_SIZE - 1], vec![0xC3; BLOCK_SIZE]] {
|
||||
let reader = tokio::io::BufReader::new(Cursor::new(payload.clone()));
|
||||
let (_reader, total, inline_shards) = erasure
|
||||
.clone()
|
||||
.encode_inline_shards_with_size_hint(reader, payload.len())
|
||||
.await
|
||||
.expect("inline shards should encode");
|
||||
for (data_shards, parity_shards) in [(1, 0), (2, 2), (4, 2), (12, 4)] {
|
||||
let erasure = Arc::new(Erasure::new_with_options(data_shards, parity_shards, BLOCK_SIZE, uses_legacy));
|
||||
for payload in [
|
||||
Vec::new(),
|
||||
vec![0xA5],
|
||||
(0_u8..63).collect(),
|
||||
(0_u8..64).collect(),
|
||||
vec![0x5A; BLOCK_SIZE - 1],
|
||||
vec![0xC3; BLOCK_SIZE],
|
||||
] {
|
||||
for hint in [0, payload.len(), BLOCK_SIZE * 2] {
|
||||
let reader = tokio::io::BufReader::new(Cursor::new(payload.clone()));
|
||||
let (_reader, total, inline_shards) = erasure
|
||||
.clone()
|
||||
.encode_inline_shards_with_size_hint(reader, hint)
|
||||
.await
|
||||
.expect("inline shards should encode");
|
||||
|
||||
assert_eq!(total, payload.len());
|
||||
if payload.is_empty() {
|
||||
assert!(inline_shards.is_empty());
|
||||
continue;
|
||||
assert_eq!(total, payload.len());
|
||||
if payload.is_empty() {
|
||||
assert!(inline_shards.is_empty());
|
||||
continue;
|
||||
}
|
||||
|
||||
let raw_shards = erasure.encode_data(&payload).expect("reference shards should encode");
|
||||
assert_eq!(inline_shards.len(), data_shards + parity_shards);
|
||||
for (inline, raw) in inline_shards.iter().zip(raw_shards) {
|
||||
let mut writer =
|
||||
BitrotWriterWrapper::new(CustomWriter::new_inline_buffer(), raw.len(), checksum_algo.clone());
|
||||
writer.write(&raw).await.expect("reference writer should accept shard");
|
||||
writer.shutdown().await.expect("reference writer should shutdown");
|
||||
assert_eq!(inline.as_ref(), writer.into_inline_data().expect("reference writer should retain bytes"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let raw_shards = erasure.encode_data(&payload).expect("reference shards should encode");
|
||||
assert_eq!(inline_shards.len(), DATA_SHARDS + PARITY_SHARDS);
|
||||
for (inline, raw) in inline_shards.iter().zip(raw_shards) {
|
||||
let mut writer =
|
||||
BitrotWriterWrapper::new(CustomWriter::new_inline_buffer(), raw.len(), checksum_algo.clone());
|
||||
writer.write(&raw).await.expect("reference writer should accept shard");
|
||||
writer.shutdown().await.expect("reference writer should shutdown");
|
||||
assert_eq!(inline.as_ref(), writer.into_inline_data().expect("reference writer should retain bytes"));
|
||||
#[tokio::test]
|
||||
async fn inline_framing_keeps_integrity_over_raw_shards() {
|
||||
use rustfs_filemeta::shard_integrity::IntegrityLayout;
|
||||
|
||||
for uses_legacy in [false, true] {
|
||||
let erasure = Arc::new(Erasure::new_with_options(2, 2, 128 * 1024, uses_legacy));
|
||||
let payload: Vec<_> = (0_u8..=250).cycle().take(128 * 1024).collect();
|
||||
let raw_shards = erasure.encode_data(&payload).expect("reference data must encode");
|
||||
let layout = IntegrityLayout::new(2, 2, erasure.block_size, uses_legacy).expect("valid layout");
|
||||
|
||||
let (_, total, inline, proof) = Arc::clone(&erasure)
|
||||
.encode_with_shard_integrity(
|
||||
Cursor::new(payload.clone()),
|
||||
&mut [],
|
||||
ShardWritePolicy::object(3),
|
||||
1,
|
||||
IntegrityEncodeMode::Inline(payload.len()),
|
||||
true,
|
||||
)
|
||||
.await
|
||||
.expect("protected inline data must encode");
|
||||
let proof = proof.expect("protected encode must retain its proof");
|
||||
|
||||
assert_eq!(total, payload.len());
|
||||
assert_eq!(inline.expect("inline payload").len(), 4);
|
||||
proof.part.validate().expect("the prepared part must be valid");
|
||||
assert_eq!(proof.part.layout, layout);
|
||||
assert_eq!(proof.part.size, u64::try_from(payload.len()).expect("payload length fits u64"));
|
||||
assert_eq!(proof.part.stripes, 1);
|
||||
let index = proof.inline_bytes().expect("inline proof");
|
||||
assert_eq!(index.len(), proof.part.index_size().expect("valid proof length"));
|
||||
assert!(index.starts_with(&proof.part.index_header()));
|
||||
let offset = proof.part.record_offset(0).expect("first stripe exists");
|
||||
let record = &index[offset..offset + proof.part.record_size()];
|
||||
for (coding_index, raw_shard) in raw_shards.iter().enumerate() {
|
||||
proof
|
||||
.part
|
||||
.verify_shard(0, coding_index, raw_shard, record)
|
||||
.expect("the authenticated proof must cover the raw shard without its bitrot prefix");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn inline_framing_preserves_eof_digest_validation() {
|
||||
use crate::io_support::rio::HashReader;
|
||||
|
||||
let erasure = Arc::new(Erasure::new(2, 2, 64));
|
||||
let payload = vec![0xA5; 64];
|
||||
for (md5, sha256) in [(Some("0".repeat(32)), None), (None, Some("0".repeat(64)))] {
|
||||
let reader = HashReader::from_stream(Cursor::new(payload.clone()), 64, 64, md5, sha256, false)
|
||||
.expect("valid digest input shape");
|
||||
let err = Arc::clone(&erasure)
|
||||
.encode_inline_shards_with_size_hint(reader, payload.len())
|
||||
.await
|
||||
.err()
|
||||
.expect("a failed EOF digest must prevent inline publication");
|
||||
assert_eq!(err.kind(), std::io::ErrorKind::InvalidData);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn inline_ingest_retries_interrupted_and_preserves_other_errors() {
|
||||
use std::task::{Context, Poll};
|
||||
use tokio::io::ReadBuf;
|
||||
|
||||
struct ErrorAfterPrefix {
|
||||
prefix: Cursor<Vec<u8>>,
|
||||
error: Option<std::io::ErrorKind>,
|
||||
}
|
||||
|
||||
impl AsyncRead for ErrorAfterPrefix {
|
||||
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<std::io::Result<()>> {
|
||||
if self.prefix.position() < u64::try_from(self.prefix.get_ref().len()).expect("small test reader length") {
|
||||
return Pin::new(&mut self.prefix).poll_read(cx, buf);
|
||||
}
|
||||
if let Some(kind) = self.error.take() {
|
||||
return Poll::Ready(Err(std::io::Error::new(kind, "inline reader failed")));
|
||||
}
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
let erasure = Arc::new(Erasure::new(2, 2, 64));
|
||||
for payload in [Vec::new(), (0_u8..7).collect()] {
|
||||
for kind in [
|
||||
std::io::ErrorKind::Interrupted,
|
||||
std::io::ErrorKind::InvalidData,
|
||||
std::io::ErrorKind::BrokenPipe,
|
||||
] {
|
||||
let reader = ErrorAfterPrefix {
|
||||
prefix: Cursor::new(payload.clone()),
|
||||
error: Some(kind),
|
||||
};
|
||||
let result = Arc::clone(&erasure).encode_inline_shards_with_size_hint(reader, 0).await;
|
||||
if kind == std::io::ErrorKind::Interrupted {
|
||||
let (_, total, shards) = result.expect("Interrupted must be retried through the final EOF");
|
||||
assert_eq!(total, payload.len());
|
||||
assert_eq!(shards.len(), if payload.is_empty() { 0 } else { 4 });
|
||||
} else {
|
||||
let err = result.err().expect("the original read error must prevent inline publication");
|
||||
assert_eq!(err.kind(), kind, "partial reads must preserve the error kind");
|
||||
assert_eq!(err.to_string(), "inline reader failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ use crate::erasure::codec::shard_buf::ShardBytes;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use reed_solomon_simd;
|
||||
use rustfs_erasure_codec::galois_8::ReedSolomon;
|
||||
use rustfs_utils::HashAlgorithm;
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
@@ -37,14 +38,12 @@ pub(crate) struct EncodedBlock {
|
||||
shard_size: usize,
|
||||
}
|
||||
|
||||
impl EncodedBlock {
|
||||
fn empty() -> Self {
|
||||
Self {
|
||||
data: Bytes::new(),
|
||||
shard_size: 0,
|
||||
}
|
||||
}
|
||||
pub(crate) struct MutableEncodedBlock {
|
||||
data: BytesMut,
|
||||
shard_size: usize,
|
||||
}
|
||||
|
||||
impl EncodedBlock {
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.data.is_empty()
|
||||
}
|
||||
@@ -79,6 +78,58 @@ impl EncodedBlock {
|
||||
}
|
||||
}
|
||||
|
||||
impl MutableEncodedBlock {
|
||||
fn freeze(self) -> EncodedBlock {
|
||||
EncodedBlock {
|
||||
data: self.data.freeze(),
|
||||
shard_size: self.shard_size,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn shards(&self) -> impl ExactSizeIterator<Item = &[u8]> {
|
||||
debug_assert!(self.shard_size > 0, "only non-empty encoded blocks reach shard writers");
|
||||
debug_assert_eq!(self.data.len() % self.shard_size, 0);
|
||||
self.data.chunks_exact(self.shard_size)
|
||||
}
|
||||
|
||||
pub(crate) fn into_inline_shards(self) -> io::Result<Vec<Bytes>> {
|
||||
if self.data.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
debug_assert!(self.shard_size > 0, "non-empty encoded blocks have a shard size");
|
||||
debug_assert_eq!(self.data.len() % self.shard_size, 0);
|
||||
let shard_count = self.data.len() / self.shard_size;
|
||||
let hash_algorithm = HashAlgorithm::HighwayHash256S;
|
||||
let hash_size = hash_algorithm.size();
|
||||
let frame_size = self
|
||||
.shard_size
|
||||
.checked_add(hash_size)
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "inline shard frame size overflows usize"))?;
|
||||
let framed_size = shard_count
|
||||
.checked_mul(frame_size)
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "inline shard frames exceed usize"))?;
|
||||
let mut data = self.data;
|
||||
data.resize(framed_size, 0);
|
||||
|
||||
// Expand from the last shard so each move only overwrites raw shards
|
||||
// whose payload has already reached its final, hash-prefixed location.
|
||||
for index in (0..shard_count).rev() {
|
||||
let source = index * self.shard_size;
|
||||
let frame = index * frame_size;
|
||||
data.copy_within(source..source + self.shard_size, frame + hash_size);
|
||||
let (hash, payload) = data[frame..frame + frame_size].split_at_mut(hash_size);
|
||||
hash.copy_from_slice(hash_algorithm.hash_encode(payload).as_ref());
|
||||
}
|
||||
|
||||
let mut shards = Vec::with_capacity(shard_count);
|
||||
for _ in 0..shard_count {
|
||||
shards.push(data.split_to(frame_size).freeze());
|
||||
}
|
||||
Ok(shards)
|
||||
}
|
||||
}
|
||||
|
||||
const MODERN_MAX_TOTAL_SHARDS: usize = <rustfs_erasure_codec::galois_8::Field as rustfs_erasure_codec::Field>::ORDER;
|
||||
const MODERN_REED_SOLOMON_CACHE_MAX_ENTRIES: usize = 64;
|
||||
const LEGACY_REED_SOLOMON_CACHE_MAX_ENTRIES: usize = 16;
|
||||
@@ -1077,7 +1128,12 @@ impl Erasure {
|
||||
self.encode_buffer(data_buffer, data_len)
|
||||
}
|
||||
|
||||
fn encode_buffer(&self, mut data_buffer: BytesMut, data_len: usize) -> io::Result<EncodedBlock> {
|
||||
fn encode_buffer(&self, data_buffer: BytesMut, data_len: usize) -> io::Result<EncodedBlock> {
|
||||
self.encode_buffer_mut(data_buffer, data_len).map(MutableEncodedBlock::freeze)
|
||||
}
|
||||
|
||||
#[hotpath::measure(impl_type = "Erasure")]
|
||||
pub(crate) fn encode_buffer_mut(&self, mut data_buffer: BytesMut, data_len: usize) -> io::Result<MutableEncodedBlock> {
|
||||
let shard_size_fn = if self.uses_legacy {
|
||||
calc_shard_size_legacy
|
||||
} else {
|
||||
@@ -1085,7 +1141,10 @@ impl Erasure {
|
||||
};
|
||||
let per_shard_size = shard_size_fn(data_len, self.data_shards);
|
||||
if per_shard_size == 0 {
|
||||
return Ok(EncodedBlock::empty());
|
||||
return Ok(MutableEncodedBlock {
|
||||
data: BytesMut::new(),
|
||||
shard_size: 0,
|
||||
});
|
||||
}
|
||||
let need_total_size = per_shard_size * self.total_shard_count();
|
||||
|
||||
@@ -1112,8 +1171,8 @@ impl Erasure {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(EncodedBlock {
|
||||
data: data_buffer.freeze(),
|
||||
Ok(MutableEncodedBlock {
|
||||
data: data_buffer,
|
||||
shard_size: per_shard_size,
|
||||
})
|
||||
}
|
||||
@@ -2043,6 +2102,27 @@ mod tests {
|
||||
assert!(err.to_string().contains("invalid shard count"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_shards_reuse_the_bytesmut_ingest_allocation() {
|
||||
for uses_legacy in [false, true] {
|
||||
let erasure = Erasure::new_with_options(2, 2, 128 * 1024, uses_legacy);
|
||||
let payload: Vec<_> = (0_u8..=250).cycle().take(128 * 1024).collect();
|
||||
let frame_size = erasure.encoded_capacity_for_data_len(payload.len())
|
||||
+ erasure.total_shard_count() * HashAlgorithm::HighwayHash256S.size();
|
||||
let mut buffer = BytesMut::with_capacity(frame_size);
|
||||
buffer.extend_from_slice(&payload);
|
||||
let allocation = buffer.as_ptr();
|
||||
let block = erasure
|
||||
.encode_buffer_mut(buffer, payload.len())
|
||||
.expect("preallocated data must encode");
|
||||
let shards = block.into_inline_shards().expect("inline framing must succeed");
|
||||
|
||||
assert_eq!(shards.len(), erasure.total_shard_count());
|
||||
assert_eq!(shards[0].as_ptr(), allocation, "inline framing must retain the encoded allocation");
|
||||
assert_eq!(shards.iter().map(Bytes::len).sum::<usize>(), frame_size);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encode_data_owned_matches_borrowed_path() {
|
||||
for uses_legacy in [false, true] {
|
||||
|
||||
@@ -4374,6 +4374,11 @@ mod tests {
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn targeted_heal_is_blocked_by_exact_fit_decommission_reservation() {
|
||||
use rustfs_common::mrf_channel::{
|
||||
MrfDurableRepairAnchor, MrfIngressResult, MrfIntent, MrfKind, MrfScope, release_mrf_intent,
|
||||
try_rearm_mrf_replay_intent,
|
||||
};
|
||||
|
||||
let (_temp_dirs, store, _other_store) = test_two_pool_stores(None).await;
|
||||
let bucket = format!("heal-capacity-{}", Uuid::new_v4().simple());
|
||||
let object = "targeted-heal.bin";
|
||||
@@ -4382,6 +4387,34 @@ mod tests {
|
||||
.await
|
||||
.expect("heal capacity bucket should be created");
|
||||
|
||||
let incarnation = store
|
||||
.bucket_incarnation_id_from_disk(&bucket)
|
||||
.await
|
||||
.expect("MRF probe bucket incarnation should be readable");
|
||||
let mut intent = MrfIntent {
|
||||
bucket: Arc::from(bucket.as_str()),
|
||||
object: Arc::from("absent-mrf-target.bin"),
|
||||
version_id: None,
|
||||
kind: MrfKind::PartialWrite,
|
||||
scope: Some(MrfScope {
|
||||
pool_index: 1,
|
||||
set_index: 0,
|
||||
}),
|
||||
lease: None,
|
||||
enqueued_at_ms: 0,
|
||||
attempts: 0,
|
||||
delete_marker_purge: None,
|
||||
};
|
||||
assert_eq!(try_rearm_mrf_replay_intent(&mut intent), MrfIngressResult::Enqueued);
|
||||
let anchor = MrfDurableRepairAnchor::from_intent(&intent, incarnation).expect("MRF probe anchor should be valid");
|
||||
assert!(
|
||||
tokio::time::timeout(std::time::Duration::from_secs(2), store.probe_mrf_unversioned_absence(&anchor))
|
||||
.await
|
||||
.expect("unreserved MRF probe should finish")
|
||||
.expect("unreserved MRF probe should be admitted"),
|
||||
"an absent target should be proven before the reservation"
|
||||
);
|
||||
|
||||
let target_set = store.pools[1].get_disks(0);
|
||||
let mut reader = PutObjReader::from_vec(b"targeted heal body".to_vec());
|
||||
target_set
|
||||
@@ -4432,6 +4465,15 @@ mod tests {
|
||||
assert_eq!(reservation.targets[0].reserved_physical_bytes, 60);
|
||||
}
|
||||
|
||||
let probe = tokio::time::timeout(std::time::Duration::from_secs(2), store.probe_mrf_unversioned_absence(&anchor))
|
||||
.await
|
||||
.expect("reserved-target MRF admission should finish");
|
||||
release_mrf_intent(&intent);
|
||||
assert!(
|
||||
matches!(probe, Err(Error::SlowDown)),
|
||||
"reserved-target MRF probe must remain capacity-blocked: {probe:?}"
|
||||
);
|
||||
|
||||
let (_, err) = store
|
||||
.handle_heal_object(
|
||||
&bucket,
|
||||
|
||||
@@ -544,7 +544,7 @@ impl DefaultMultipartUsecase {
|
||||
user_defined,
|
||||
"".to_string(),
|
||||
opts.delete_marker_replication_status(),
|
||||
opts.clone(),
|
||||
opts.replication_request,
|
||||
))
|
||||
.await;
|
||||
let mut completion_replication_metadata = HashMap::new();
|
||||
|
||||
@@ -431,9 +431,15 @@ impl DefaultMultipartUsecase {
|
||||
}
|
||||
|
||||
if !origin.is_managed() {
|
||||
let dsc =
|
||||
must_replicate_object(&bucket, &key, &mt2, "".to_string(), opts.delete_marker_replication_status(), opts.clone())
|
||||
.await;
|
||||
let dsc = must_replicate_object(
|
||||
&bucket,
|
||||
&key,
|
||||
&mt2,
|
||||
"".to_string(),
|
||||
opts.delete_marker_replication_status(),
|
||||
opts.replication_request,
|
||||
)
|
||||
.await;
|
||||
if dsc.replicate_any() {
|
||||
insert_str(&mut opts.user_defined, SUFFIX_REPLICATION_GENERATION, Uuid::new_v4().to_string());
|
||||
insert_str(
|
||||
|
||||
@@ -928,7 +928,7 @@ impl DefaultObjectUsecase {
|
||||
&user_defined,
|
||||
"".to_string(),
|
||||
dst_opts.delete_marker_replication_status(),
|
||||
dst_opts.clone(),
|
||||
dst_opts.replication_request,
|
||||
)
|
||||
})
|
||||
.await;
|
||||
|
||||
@@ -2692,7 +2692,7 @@ impl DefaultObjectUsecase {
|
||||
&opts.user_defined,
|
||||
"".to_string(),
|
||||
opts.delete_marker_replication_status(),
|
||||
opts.clone(),
|
||||
opts.replication_request,
|
||||
))
|
||||
.await;
|
||||
if replication.replicate_any() {
|
||||
|
||||
@@ -422,7 +422,7 @@ impl DefaultObjectUsecase {
|
||||
&mt2,
|
||||
"".to_string(),
|
||||
opts.delete_marker_replication_status(),
|
||||
opts.clone(),
|
||||
opts.replication_request,
|
||||
)
|
||||
.await;
|
||||
if dsc.replicate_any() {
|
||||
@@ -676,7 +676,7 @@ impl DefaultObjectUsecase {
|
||||
&completion_source_metadata,
|
||||
"".to_string(),
|
||||
opts.delete_marker_replication_status(),
|
||||
opts.clone(),
|
||||
opts.replication_request,
|
||||
)
|
||||
.await;
|
||||
let mut completion_replication_metadata = HashMap::new();
|
||||
@@ -1032,7 +1032,7 @@ mod tests {
|
||||
&stored.user_defined,
|
||||
"replicate=yes".to_string(),
|
||||
stored.replication_status.clone(),
|
||||
ObjectOptions::default(),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
|
||||
@@ -1180,7 +1180,7 @@ mod tests {
|
||||
&stored.user_defined,
|
||||
"replicate=yes".to_string(),
|
||||
stored.replication_status.clone(),
|
||||
ObjectOptions::default(),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
|
||||
+138
-15
@@ -2493,9 +2493,15 @@ impl DefaultObjectUsecase {
|
||||
// replication-config hot update can no longer split the two phases
|
||||
// (https://github.com/rustfs/backlog/issues/1320).
|
||||
let replication_decision_stage_start = put_stage_metrics_enabled.then(Instant::now);
|
||||
let dsc =
|
||||
must_replicate_object(&bucket, &key, &mt2, "".to_string(), opts.delete_marker_replication_status(), opts.clone())
|
||||
.await;
|
||||
let dsc = must_replicate_object(
|
||||
&bucket,
|
||||
&key,
|
||||
&mt2,
|
||||
"".to_string(),
|
||||
opts.delete_marker_replication_status(),
|
||||
opts.replication_request,
|
||||
)
|
||||
.await;
|
||||
rustfs_io_metrics::record_put_object_stage_duration_from("app_replication_decision", replication_decision_stage_start);
|
||||
|
||||
if dsc.replicate_any() {
|
||||
@@ -2526,7 +2532,6 @@ impl DefaultObjectUsecase {
|
||||
let request_id = request_id.clone();
|
||||
let bucket = bucket.clone();
|
||||
let key = key.clone();
|
||||
let put_path = put_path.to_string();
|
||||
async move {
|
||||
tokio::select! {
|
||||
_ = store_put_watchdog.cancelled() => {}
|
||||
@@ -2560,19 +2565,17 @@ impl DefaultObjectUsecase {
|
||||
#[cfg(test)]
|
||||
let injected_commit_error = injected_put_storage_failure(PutStorageTestStage::Commit);
|
||||
let put_commit_future = {
|
||||
let store = Arc::clone(&store);
|
||||
let bucket = bucket.clone();
|
||||
let key = key.clone();
|
||||
let opts = opts.clone();
|
||||
let cache_adapter = cache_adapter.clone();
|
||||
let request_id = request_id.clone();
|
||||
let put_path = put_path.to_string();
|
||||
let put_admission = put_admission;
|
||||
let table_publication_guard = origin.take_table_publication_guard();
|
||||
let managed_lifecycle_guard = origin.take_managed_lifecycle_guard();
|
||||
let table_data_plane_publication_guards = origin.table_data_plane_publication_guards();
|
||||
// Keep the large commit future off the request stack when propagating task-local context.
|
||||
Box::pin(async move {
|
||||
// The response and usage delta describe this commit, even if the
|
||||
// bucket's versioning configuration changes after publication.
|
||||
let put_versioned = opts.versioned;
|
||||
let _table_publication_guard = table_publication_guard;
|
||||
let _managed_lifecycle_guard = managed_lifecycle_guard;
|
||||
let _table_data_plane_publication_guards = table_data_plane_publication_guards;
|
||||
@@ -2667,12 +2670,6 @@ impl DefaultObjectUsecase {
|
||||
cache_invalidate_stage_start,
|
||||
);
|
||||
|
||||
let versioning_lookup_stage_start = put_stage_metrics_enabled.then(Instant::now);
|
||||
let put_versioned = BucketVersioningSys::prefix_enabled(&bucket, &key).await;
|
||||
rustfs_io_metrics::record_put_object_stage_duration_from(
|
||||
"app_post_store_versioning_lookup",
|
||||
versioning_lookup_stage_start,
|
||||
);
|
||||
let quota_size_stage_start = put_stage_metrics_enabled.then(Instant::now);
|
||||
let committed_size = quota_accounting_object_size(&obj_info, quota_enabled)?;
|
||||
rustfs_io_metrics::record_put_object_stage_duration_from("app_post_store_quota_size", quota_size_stage_start);
|
||||
@@ -3540,6 +3537,132 @@ mod tests {
|
||||
assert!(!recovered.write_stalled);
|
||||
}
|
||||
|
||||
async fn assert_put_preserves_committed_versioning(initially_enabled: bool) {
|
||||
use crate::app::bucket_usecase::DefaultBucketUsecase;
|
||||
use crate::app::storage_api::test::contract::bucket::{BucketOperations as _, MakeBucketOptions};
|
||||
use crate::app::storage_api::test::data_usage::{get_bucket_usage_memory, seed_bucket_usage_memory_for_test};
|
||||
use rustfs_gateway_types::persistence::PersistedVersioningConfiguration;
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
let (store, context) = real_store_test_context().await;
|
||||
let bucket = format!("put-versioning-{}", Uuid::new_v4());
|
||||
let object = "object.bin";
|
||||
store
|
||||
.make_bucket(
|
||||
&bucket,
|
||||
&MakeBucketOptions {
|
||||
versioning_enabled: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("create versioning test bucket");
|
||||
let bucket_usecase = DefaultBucketUsecase::with_context(Some(Arc::clone(&context)));
|
||||
let initial_status = if initially_enabled { "Enabled" } else { "Suspended" };
|
||||
bucket_usecase
|
||||
.execute_put_bucket_versioning(
|
||||
method_only_put_envelope(),
|
||||
&bucket,
|
||||
Ok(PersistedVersioningConfiguration {
|
||||
status: Some(initial_status.to_owned()),
|
||||
..Default::default()
|
||||
}),
|
||||
)
|
||||
.await
|
||||
.expect("set initial bucket versioning");
|
||||
seed_bucket_usage_memory_for_test(&bucket, 0).await;
|
||||
let usecase = DefaultObjectUsecase::with_context(Some(Arc::clone(&context)));
|
||||
let old_body = Bytes::from_static(b"0123456789");
|
||||
let old = put_method_only(&usecase, put_bytes(bucket.clone(), object, old_body.clone()))
|
||||
.await
|
||||
.expect("write the original object");
|
||||
assert_eq!(old.version_id.is_some(), initially_enabled, "initial versioning state must reach the PUT");
|
||||
assert_eq!(get_bucket_usage_memory(&bucket).await, Some(10));
|
||||
|
||||
let entered = Arc::new(tokio::sync::Barrier::new(2));
|
||||
let resume = Arc::new(tokio::sync::Barrier::new(2));
|
||||
install_put_post_store_test_hook(bucket.clone(), Arc::clone(&entered), Arc::clone(&resume));
|
||||
let input = put_bytes(bucket.clone(), object, Bytes::from_static(b"01234567890123456789"));
|
||||
let put = tokio::spawn(async move { put_method_only(&usecase, input).await });
|
||||
tokio::time::timeout(Duration::from_secs(10), entered.wait())
|
||||
.await
|
||||
.expect("PUT must pause after committing its object");
|
||||
let committed = store
|
||||
.get_object_info(&bucket, object, &ObjectOptions::default())
|
||||
.await
|
||||
.expect("the paused PUT must already be readable");
|
||||
assert_eq!(committed.size, 20);
|
||||
let changed_status = if initially_enabled { "Suspended" } else { "Enabled" };
|
||||
tokio::time::timeout(
|
||||
Duration::from_secs(10),
|
||||
bucket_usecase.execute_put_bucket_versioning(
|
||||
method_only_put_envelope(),
|
||||
&bucket,
|
||||
Ok(PersistedVersioningConfiguration {
|
||||
status: Some(changed_status.to_owned()),
|
||||
..Default::default()
|
||||
}),
|
||||
),
|
||||
)
|
||||
.await
|
||||
.expect("versioning update must finish while the PUT is paused")
|
||||
.expect("change versioning after the object commit");
|
||||
tokio::time::timeout(Duration::from_secs(10), resume.wait())
|
||||
.await
|
||||
.expect("resume PUT post-commit processing");
|
||||
let response = tokio::time::timeout(Duration::from_secs(10), put)
|
||||
.await
|
||||
.expect("PUT must finish after resuming")
|
||||
.expect("PUT task must join")
|
||||
.expect("PUT must succeed");
|
||||
|
||||
if initially_enabled {
|
||||
let committed_version = committed.version_id.expect("enabled PUT must create a UUID version");
|
||||
assert!(!committed_version.is_nil());
|
||||
assert_eq!(response.version_id, Some(committed_version.to_string()));
|
||||
let mut previous = store
|
||||
.get_object_reader(
|
||||
&bucket,
|
||||
object,
|
||||
None,
|
||||
HeaderMap::new(),
|
||||
&ObjectOptions {
|
||||
version_id: old.version_id,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("the previous UUID version must remain readable");
|
||||
let mut bytes = Vec::new();
|
||||
previous
|
||||
.stream
|
||||
.read_to_end(&mut bytes)
|
||||
.await
|
||||
.expect("read the previous version");
|
||||
assert_eq!(bytes, old_body);
|
||||
} else {
|
||||
assert!(committed.version_id.is_none_or(|version| version.is_nil()));
|
||||
assert_eq!(response.version_id, None, "suspended PUT keeps its original null-version response");
|
||||
}
|
||||
assert_eq!(
|
||||
get_bucket_usage_memory(&bucket).await,
|
||||
Some(if initially_enabled { 30 } else { 20 }),
|
||||
"usage must follow the committed write's versioning state"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial(body_cache_hook)]
|
||||
async fn put_keeps_committed_version_after_bucket_versioning_is_suspended() {
|
||||
assert_put_preserves_committed_versioning(true).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial(body_cache_hook)]
|
||||
async fn put_keeps_committed_null_version_after_bucket_versioning_is_enabled() {
|
||||
assert_put_preserves_committed_versioning(false).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial(body_cache_hook)]
|
||||
async fn cancelled_put_request_completes_post_commit_publication() {
|
||||
|
||||
@@ -102,7 +102,7 @@ impl ObjectMetaUsecase {
|
||||
&info.user_defined,
|
||||
info.user_tags.as_ref().clone(),
|
||||
popts.delete_marker_replication_status(),
|
||||
popts.clone(),
|
||||
popts.replication_request,
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
|
||||
@@ -129,7 +129,7 @@ impl ObjectMetaUsecase {
|
||||
&info.user_defined,
|
||||
info.user_tags.as_ref().clone(),
|
||||
opts.delete_marker_replication_status(),
|
||||
opts.clone(),
|
||||
opts.replication_request,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ impl ObjectMetaUsecase {
|
||||
&existing.user_defined,
|
||||
tags.clone(),
|
||||
existing.replication_status,
|
||||
opts.clone(),
|
||||
opts.replication_request,
|
||||
)
|
||||
.await;
|
||||
if decision.replicate_any() {
|
||||
@@ -350,7 +350,7 @@ impl ObjectMetaUsecase {
|
||||
&existing_object_info.user_defined,
|
||||
String::new(),
|
||||
existing_object_info.replication_status.clone(),
|
||||
opts.clone(),
|
||||
opts.replication_request,
|
||||
)
|
||||
.await;
|
||||
if dsc.replicate_any() {
|
||||
|
||||
@@ -1202,7 +1202,7 @@ pub(crate) mod bucket {
|
||||
user_defined: &HashMap<String, String>,
|
||||
user_tags: String,
|
||||
status: ReplicationStatusType,
|
||||
opts: crate::storage::storage_api::StorageObjectOptions,
|
||||
replication_request: bool,
|
||||
) -> ReplicateDecision {
|
||||
must_replicate_with_type(
|
||||
bucket,
|
||||
@@ -1210,7 +1210,7 @@ pub(crate) mod bucket {
|
||||
user_defined,
|
||||
user_tags,
|
||||
status,
|
||||
opts,
|
||||
replication_request,
|
||||
replication_contracts::ReplicationType::Object,
|
||||
)
|
||||
.await
|
||||
@@ -1222,7 +1222,7 @@ pub(crate) mod bucket {
|
||||
user_defined: &HashMap<String, String>,
|
||||
user_tags: String,
|
||||
status: ReplicationStatusType,
|
||||
opts: crate::storage::storage_api::StorageObjectOptions,
|
||||
replication_request: bool,
|
||||
) -> ReplicateDecision {
|
||||
must_replicate_with_type(
|
||||
bucket,
|
||||
@@ -1230,7 +1230,7 @@ pub(crate) mod bucket {
|
||||
user_defined,
|
||||
user_tags,
|
||||
status,
|
||||
opts,
|
||||
replication_request,
|
||||
replication_contracts::ReplicationType::Metadata,
|
||||
)
|
||||
.await
|
||||
@@ -1242,12 +1242,13 @@ pub(crate) mod bucket {
|
||||
user_defined: &HashMap<String, String>,
|
||||
user_tags: String,
|
||||
status: ReplicationStatusType,
|
||||
opts: crate::storage::storage_api::StorageObjectOptions,
|
||||
replication_request: bool,
|
||||
op_type: replication_contracts::ReplicationType,
|
||||
) -> ReplicateDecision {
|
||||
#[cfg(test)]
|
||||
MUST_REPLICATE_OBJECT_CALLS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
let mopts = ReplicationObjectBridge::must_replicate_options(user_defined, user_tags, status, op_type, opts);
|
||||
let mopts =
|
||||
ReplicationObjectBridge::must_replicate_options(user_defined, user_tags, status, op_type, replication_request);
|
||||
ReplicationObjectBridge::must_replicate(bucket, object, mopts).await
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user