mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-03 06:36:35 +00:00
fix(ecstore): preserve drive health on metadata batch fallback
Keep Unimplemented as a typed RPC failure through drive health accounting. Resolve fallback after the batch attempt and its permit end. Borrow the original request and encode only after bulk admission. Co-Authored-By: heihutu <heihutu@gmail.com> Co-Authored-By: zhi22915 <qiuzgang@gmail.com> Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com> Signed-off-by: Hauser Zhi <housemecn@gmail.com>
This commit is contained in:
@@ -13,9 +13,9 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::cluster::rpc::client::{
|
||||
AuthenticatedChannel, MsgpackSendPolicy, TonicInterceptor, gen_tonic_signature_interceptor, is_network_like_disk_error,
|
||||
node_service_delete_recovery_client, node_service_time_out_client, node_service_time_out_client_for_class,
|
||||
node_service_time_out_client_for_class_with_msgpack_policy,
|
||||
AuthenticatedChannel, MsgpackSendPolicy, TonicInterceptor, embedded_tonic_status, gen_tonic_signature_interceptor,
|
||||
is_network_like_disk_error, node_service_delete_recovery_client, node_service_time_out_client,
|
||||
node_service_time_out_client_for_class, node_service_time_out_client_for_class_with_msgpack_policy,
|
||||
};
|
||||
use crate::cluster::rpc::http_auth::{current_rpc_background_request, with_rpc_background_request};
|
||||
use crate::cluster::rpc::internode_data_transport::{
|
||||
@@ -3946,6 +3946,148 @@ impl RemoteDisk {
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn batch_read_version_with_mode(
|
||||
&self,
|
||||
req: BatchReadVersionReq,
|
||||
mode: BatchMetadataRpcMode,
|
||||
) -> Result<Vec<BatchReadVersionResp>> {
|
||||
validate_batch_read_version_item_count(req.items.len())?;
|
||||
|
||||
if !mode.should_attempt() {
|
||||
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_OFF_UNARY);
|
||||
return batch_read_version_one_by_one(self, req).await;
|
||||
}
|
||||
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_ATTEMPT);
|
||||
|
||||
trace!(
|
||||
event = EVENT_REMOTE_DISK_RPC,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
|
||||
endpoint = %self.endpoint,
|
||||
item_count = req.items.len(),
|
||||
batch_metadata_rpc_mode = mode.as_str(),
|
||||
op = "batch_read_version",
|
||||
state = "started",
|
||||
"Remote disk RPC started"
|
||||
);
|
||||
let batch_result = {
|
||||
let _bulk_body = self.acquire_bulk_body().await?;
|
||||
let batch_read_version_attribution_enabled = rustfs_io_metrics::get_stage_metrics_enabled();
|
||||
let encode_started = read_version_stage_timer(batch_read_version_attribution_enabled);
|
||||
let batch_read_version_req_bin = Bytes::from(encode_msgpack(&req)?);
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_REQUEST_ENCODE, encode_started);
|
||||
self.execute_with_timeout_for_op(
|
||||
"batch_read_version",
|
||||
|| async {
|
||||
let disk = self.disk_ref().await;
|
||||
let disk_len = disk.len();
|
||||
let (mut client, mut policy) = self.get_bulk_client_with_msgpack_policy().await?;
|
||||
let mut retried_dual_write = false;
|
||||
let response = loop {
|
||||
let batch_read_version_req = compat_json(&req, &policy)?;
|
||||
let request_payload_bytes = batch_read_version_attribution_enabled.then(|| {
|
||||
batch_read_version_request_payload_len(&req, &batch_read_version_req, &batch_read_version_req_bin)
|
||||
});
|
||||
let mut request = Request::new(BatchReadVersionRequest {
|
||||
disk: disk.clone(),
|
||||
batch_read_version_req,
|
||||
batch_read_version_req_bin: batch_read_version_req_bin.clone(),
|
||||
});
|
||||
policy.guard_request(&mut request);
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_request(&req.opts);
|
||||
if let Some(request_payload_bytes) = request_payload_bytes {
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_sent_bytes(
|
||||
request_payload_bytes.saturating_add(disk_len),
|
||||
);
|
||||
}
|
||||
let rpc_started = read_version_stage_timer(batch_read_version_attribution_enabled);
|
||||
let response_result =
|
||||
measure_client_rpc(INTERNODE_OPERATION_GRPC_BATCH_READ_VERSION, client.batch_read_version(request))
|
||||
.await;
|
||||
match response_result {
|
||||
Ok(response) => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RPC_ROUNDTRIP, rpc_started);
|
||||
break response.into_inner();
|
||||
}
|
||||
Err(_) if !retried_dual_write && policy.retry_dual_write_after_local_rejection() => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RPC_ROUNDTRIP, rpc_started);
|
||||
retried_dual_write = true;
|
||||
}
|
||||
Err(status) => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RPC_ROUNDTRIP, rpc_started);
|
||||
if status.code() != Code::Unimplemented {
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_error();
|
||||
}
|
||||
return Err(Error::from(status));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if !response.success {
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_error();
|
||||
return Err(self.rejected_peer_read(response.error));
|
||||
}
|
||||
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_recv_bytes(
|
||||
batch_read_version_response_payload_len(&response),
|
||||
);
|
||||
let decode_started = read_version_stage_timer(batch_read_version_attribution_enabled);
|
||||
match decode_batch_read_version_response_items(response, &self.endpoint) {
|
||||
Ok(batch_read_version_resps) => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RESPONSE_DECODE, decode_started);
|
||||
Ok(batch_read_version_resps)
|
||||
}
|
||||
Err(err) => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RESPONSE_DECODE, decode_started);
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_error();
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
get_max_timeout_duration(),
|
||||
)
|
||||
.await
|
||||
};
|
||||
|
||||
match batch_result {
|
||||
Err(error)
|
||||
if matches!(&error, DiskError::Io(io_error) if embedded_tonic_status(io_error)
|
||||
.is_some_and(|status| status.code() == Code::Unimplemented)) =>
|
||||
{
|
||||
if mode.should_fallback_on_unimplemented() {
|
||||
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_FALLBACK_UNIMPLEMENTED);
|
||||
warn!(
|
||||
event = EVENT_REMOTE_DISK_RPC,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
|
||||
endpoint = %self.endpoint,
|
||||
batch_metadata_rpc_mode = mode.as_str(),
|
||||
op = "batch_read_version",
|
||||
state = "fallback_unimplemented",
|
||||
"Remote disk BatchReadVersion unsupported; falling back to unary read_version"
|
||||
);
|
||||
// Each unary request has its own deadline and drives its own health accounting.
|
||||
return batch_read_version_one_by_one(self, req).await;
|
||||
}
|
||||
|
||||
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_UNSUPPORTED_NO_FALLBACK);
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_error();
|
||||
warn!(
|
||||
event = EVENT_REMOTE_DISK_RPC,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
|
||||
endpoint = %self.endpoint,
|
||||
batch_metadata_rpc_mode = mode.as_str(),
|
||||
op = "batch_read_version",
|
||||
state = "unsupported_no_fallback",
|
||||
"Remote disk BatchReadVersion unsupported and explicit batch RPC mode forbids fallback"
|
||||
);
|
||||
Err(error)
|
||||
}
|
||||
result => result,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -4855,151 +4997,7 @@ impl DiskAPI for RemoteDisk {
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
async fn batch_read_version(&self, req: BatchReadVersionReq) -> Result<Vec<BatchReadVersionResp>> {
|
||||
validate_batch_read_version_item_count(req.items.len())?;
|
||||
|
||||
let mode = batch_metadata_rpc_mode();
|
||||
if !mode.should_attempt() {
|
||||
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_OFF_UNARY);
|
||||
return batch_read_version_one_by_one(self, req).await;
|
||||
}
|
||||
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_ATTEMPT);
|
||||
|
||||
trace!(
|
||||
event = EVENT_REMOTE_DISK_RPC,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
|
||||
endpoint = %self.endpoint,
|
||||
item_count = req.items.len(),
|
||||
batch_metadata_rpc_mode = mode.as_str(),
|
||||
op = "batch_read_version",
|
||||
state = "started",
|
||||
"Remote disk RPC started"
|
||||
);
|
||||
let req = Arc::new(req);
|
||||
let batch_read_version_attribution_enabled = rustfs_io_metrics::get_stage_metrics_enabled();
|
||||
let encode_started = read_version_stage_timer(batch_read_version_attribution_enabled);
|
||||
let batch_read_version_req_bin = Bytes::from(encode_msgpack(req.as_ref())?);
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_REQUEST_ENCODE, encode_started);
|
||||
let batch_rpc_req = Arc::clone(&req);
|
||||
let request_opts = batch_rpc_req.opts;
|
||||
let bulk_body = self.acquire_bulk_body().await?;
|
||||
let batch_result = self
|
||||
.execute_with_timeout_for_op(
|
||||
"batch_read_version",
|
||||
move || async move {
|
||||
let disk = self.disk_ref().await;
|
||||
let disk_len = disk.len();
|
||||
let (mut client, mut policy) = self.get_bulk_client_with_msgpack_policy().await?;
|
||||
let mut retried_dual_write = false;
|
||||
let response = loop {
|
||||
let batch_read_version_req = compat_json(batch_rpc_req.as_ref(), &policy)?;
|
||||
let request_payload_bytes = batch_read_version_attribution_enabled.then(|| {
|
||||
batch_read_version_request_payload_len(
|
||||
batch_rpc_req.as_ref(),
|
||||
&batch_read_version_req,
|
||||
&batch_read_version_req_bin,
|
||||
)
|
||||
});
|
||||
let mut request = Request::new(BatchReadVersionRequest {
|
||||
disk: disk.clone(),
|
||||
batch_read_version_req,
|
||||
batch_read_version_req_bin: batch_read_version_req_bin.clone(),
|
||||
});
|
||||
policy.guard_request(&mut request);
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_request(&request_opts);
|
||||
if let Some(request_payload_bytes) = request_payload_bytes {
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_sent_bytes(
|
||||
request_payload_bytes.saturating_add(disk_len),
|
||||
);
|
||||
}
|
||||
let rpc_started = read_version_stage_timer(batch_read_version_attribution_enabled);
|
||||
let response_result =
|
||||
measure_client_rpc(INTERNODE_OPERATION_GRPC_BATCH_READ_VERSION, client.batch_read_version(request))
|
||||
.await;
|
||||
match response_result {
|
||||
Ok(response) => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RPC_ROUNDTRIP, rpc_started);
|
||||
break response.into_inner();
|
||||
}
|
||||
Err(_) if !retried_dual_write && policy.retry_dual_write_after_local_rejection() => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RPC_ROUNDTRIP, rpc_started);
|
||||
retried_dual_write = true;
|
||||
}
|
||||
Err(status) if status.code() == Code::Unimplemented => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RPC_ROUNDTRIP, rpc_started);
|
||||
if mode.should_fallback_on_unimplemented() {
|
||||
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_FALLBACK_UNIMPLEMENTED);
|
||||
warn!(
|
||||
event = EVENT_REMOTE_DISK_RPC,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
|
||||
endpoint = %self.endpoint,
|
||||
batch_metadata_rpc_mode = mode.as_str(),
|
||||
op = "batch_read_version",
|
||||
state = "fallback_unimplemented",
|
||||
"Remote disk BatchReadVersion unsupported; falling back to unary read_version"
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_UNSUPPORTED_NO_FALLBACK);
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_error();
|
||||
warn!(
|
||||
event = EVENT_REMOTE_DISK_RPC,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
|
||||
endpoint = %self.endpoint,
|
||||
batch_metadata_rpc_mode = mode.as_str(),
|
||||
op = "batch_read_version",
|
||||
state = "unsupported_no_fallback",
|
||||
"Remote disk BatchReadVersion unsupported and explicit batch RPC mode forbids fallback"
|
||||
);
|
||||
return Err(Error::from(status));
|
||||
}
|
||||
Err(status) => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RPC_ROUNDTRIP, rpc_started);
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_error();
|
||||
return Err(Error::from(status));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if !response.success {
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_error();
|
||||
return Err(self.rejected_peer_read(response.error));
|
||||
}
|
||||
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_recv_bytes(
|
||||
batch_read_version_response_payload_len(&response),
|
||||
);
|
||||
let decode_started = read_version_stage_timer(batch_read_version_attribution_enabled);
|
||||
match decode_batch_read_version_response_items(response, &self.endpoint) {
|
||||
Ok(batch_read_version_resps) => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RESPONSE_DECODE, decode_started);
|
||||
Ok(Some(batch_read_version_resps))
|
||||
}
|
||||
Err(err) => {
|
||||
record_batch_read_version_stage(INTERNODE_STAGE_BATCH_READ_VERSION_RESPONSE_DECODE, decode_started);
|
||||
crate::cluster::rpc::runtime_sources::record_remote_disk_grpc_batch_read_version_error();
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
get_max_timeout_duration(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
match batch_result {
|
||||
Some(batch_read_version_resps) => Ok(batch_read_version_resps),
|
||||
// Run the unary fallback outside the batch RPC deadline so each
|
||||
// read_version keeps its own per-op timeout and health accounting
|
||||
// instead of racing the whole batch against one drive timeout.
|
||||
None => {
|
||||
drop(bulk_body);
|
||||
let req = Arc::try_unwrap(req).unwrap_or_else(|req| (*req).clone());
|
||||
batch_read_version_one_by_one(self, req).await
|
||||
}
|
||||
}
|
||||
self.batch_read_version_with_mode(req, batch_metadata_rpc_mode()).await
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
@@ -15144,6 +15142,38 @@ mod tests {
|
||||
"a negative reply does not prove drive recovery"
|
||||
);
|
||||
assert_eq!(disk.runtime_state(), RuntimeDriveHealthState::Suspect);
|
||||
let request = BatchReadVersionReq {
|
||||
items: vec![crate::disk::BatchReadVersionItem {
|
||||
org_volume: "bucket".to_string(),
|
||||
volume: "bucket".to_string(),
|
||||
path: "missing".to_string(),
|
||||
version_id: String::new(),
|
||||
}],
|
||||
opts: ReadOptions::default(),
|
||||
};
|
||||
let unsupported = disk
|
||||
.batch_read_version_with_mode(request.clone(), BatchMetadataRpcMode::On)
|
||||
.await
|
||||
.expect_err("explicit batch mode must surface the old peer's Unimplemented response");
|
||||
assert!(matches!(
|
||||
unsupported,
|
||||
DiskError::Io(ref io_error) if embedded_tonic_status(io_error)
|
||||
.is_some_and(|status| status.code() == Code::Unimplemented)
|
||||
));
|
||||
|
||||
let results = disk
|
||||
.batch_read_version_with_mode(request, BatchMetadataRpcMode::Auto)
|
||||
.await
|
||||
.expect("auto mode falls back to unary for an old peer");
|
||||
assert_eq!(results.len(), 1);
|
||||
assert_eq!(results[0].error_code, DiskError::FileNotFound.to_u32());
|
||||
assert_eq!(disk.health.completed_ops(), drive_before, "falling back is not drive I/O success");
|
||||
assert_eq!(disk.runtime_state(), RuntimeDriveHealthState::Suspect);
|
||||
assert_eq!(
|
||||
disk.host_completed_ops(),
|
||||
host_before + 2,
|
||||
"only the two decoded unary replies count as progress"
|
||||
);
|
||||
peer.stop().await;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user