mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-20 03:22:18 +00:00
feat(internode): harden p0 transport boundary and baseline tooling (#3017)
* feat(internode): p0 transport baseline and ci hardening * fix(internode): avoid double wrapping transport errors --------- Co-authored-by: Henry Guo <marshawcoco@users.noreply.github.com> Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -129,7 +129,7 @@ impl RemoteDisk {
|
||||
health_check: opt.health_check && env_health_check,
|
||||
health: Arc::new(DiskHealthTracker::new()),
|
||||
cancel_token: CancellationToken::new(),
|
||||
data_transport: build_internode_data_transport_from_env(),
|
||||
data_transport: build_internode_data_transport_from_env()?,
|
||||
};
|
||||
record_drive_runtime_state(ep, RuntimeDriveHealthState::Online);
|
||||
|
||||
@@ -1674,6 +1674,7 @@ impl DiskAPI for RemoteDisk {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rustfs_common::GLOBAL_CONN_MAP;
|
||||
use rustfs_config::ENV_RUSTFS_INTERNODE_DATA_TRANSPORT;
|
||||
use std::sync::Once;
|
||||
use tokio::io::duplex;
|
||||
use tokio::net::TcpListener;
|
||||
@@ -1694,6 +1695,13 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
async fn new_remote_disk_with_default_transport(ep: &Endpoint, opt: &DiskOption) -> Result<RemoteDisk> {
|
||||
temp_env::async_with_vars([(ENV_RUSTFS_INTERNODE_DATA_TRANSPORT, None::<&str>)], async {
|
||||
RemoteDisk::new(ep, opt).await
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_remote_disk_creation() {
|
||||
let url = url::Url::parse("http://example.com:9000/path").unwrap();
|
||||
@@ -1710,7 +1718,7 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
|
||||
assert!(!remote_disk.is_local());
|
||||
assert_eq!(remote_disk.endpoint.url, url);
|
||||
@@ -1720,6 +1728,55 @@ mod tests {
|
||||
assert_eq!(remote_disk.host_name(), "example.com:9000");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_remote_disk_creation_rejects_unknown_data_transport_backend() {
|
||||
let url = url::Url::parse("http://example.com:9000/path").unwrap();
|
||||
let endpoint = Endpoint {
|
||||
url,
|
||||
is_local: false,
|
||||
pool_idx: 0,
|
||||
set_idx: 1,
|
||||
disk_idx: 2,
|
||||
};
|
||||
let disk_option = DiskOption {
|
||||
cleanup: false,
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
temp_env::async_with_vars([(ENV_RUSTFS_INTERNODE_DATA_TRANSPORT, Some("rdma"))], async {
|
||||
let err = RemoteDisk::new(&endpoint, &disk_option)
|
||||
.await
|
||||
.expect_err("unknown backend should fail closed");
|
||||
assert!(err.to_string().contains(ENV_RUSTFS_INTERNODE_DATA_TRANSPORT));
|
||||
assert!(err.to_string().contains("rdma"));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_remote_disk_creation_accepts_tcp_alias_backend() {
|
||||
let url = url::Url::parse("http://example.com:9000/path").unwrap();
|
||||
let endpoint = Endpoint {
|
||||
url,
|
||||
is_local: false,
|
||||
pool_idx: 0,
|
||||
set_idx: 1,
|
||||
disk_idx: 2,
|
||||
};
|
||||
let disk_option = DiskOption {
|
||||
cleanup: false,
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
temp_env::async_with_vars([(ENV_RUSTFS_INTERNODE_DATA_TRANSPORT, Some("tcp"))], async {
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option)
|
||||
.await
|
||||
.expect("tcp alias should be accepted");
|
||||
assert_eq!(remote_disk.host_name(), "example.com:9000");
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_remote_disk_basic_properties() {
|
||||
let url = url::Url::parse("http://remote-server:9000").unwrap();
|
||||
@@ -1736,7 +1793,7 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
|
||||
// Test basic properties
|
||||
assert!(!remote_disk.is_local());
|
||||
@@ -1768,7 +1825,7 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
let path = remote_disk.path();
|
||||
|
||||
// Remote disk path should be based on the URL path
|
||||
@@ -1794,7 +1851,7 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
assert!(remote_disk.is_online().await);
|
||||
|
||||
drop(listener);
|
||||
@@ -1825,7 +1882,7 @@ mod tests {
|
||||
health_check: true,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
remote_disk.enable_health_check();
|
||||
|
||||
// wait for health check connect timeout
|
||||
@@ -1868,7 +1925,7 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
|
||||
// Initially, disk ID should be None
|
||||
let initial_id = remote_disk.get_disk_id().await.unwrap();
|
||||
@@ -1903,7 +1960,7 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
assert_eq!(remote_disk.disk_ref().await, endpoint.to_string());
|
||||
|
||||
let disk_id = Uuid::new_v4();
|
||||
@@ -1936,7 +1993,7 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
|
||||
assert!(!remote_disk.is_local());
|
||||
assert_eq!(remote_disk.host_name(), expected_hostname);
|
||||
@@ -1962,7 +2019,9 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&valid_endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&valid_endpoint, &disk_option)
|
||||
.await
|
||||
.unwrap();
|
||||
let location = remote_disk.get_disk_location();
|
||||
assert!(location.valid());
|
||||
assert_eq!(location.pool_idx, Some(0));
|
||||
@@ -1978,7 +2037,9 @@ mod tests {
|
||||
disk_idx: -1,
|
||||
};
|
||||
|
||||
let remote_disk_invalid = RemoteDisk::new(&invalid_endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk_invalid = new_remote_disk_with_default_transport(&invalid_endpoint, &disk_option)
|
||||
.await
|
||||
.unwrap();
|
||||
let invalid_location = remote_disk_invalid.get_disk_location();
|
||||
assert!(!invalid_location.valid());
|
||||
assert_eq!(invalid_location.pool_idx, None);
|
||||
@@ -2002,7 +2063,7 @@ mod tests {
|
||||
health_check: false,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(&endpoint, &disk_option).await.unwrap();
|
||||
let remote_disk = new_remote_disk_with_default_transport(&endpoint, &disk_option).await.unwrap();
|
||||
|
||||
// Test close operation (should succeed)
|
||||
let result = remote_disk.close().await;
|
||||
@@ -2020,7 +2081,7 @@ mod tests {
|
||||
disk_idx: 0,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(
|
||||
let remote_disk = new_remote_disk_with_default_transport(
|
||||
&endpoint,
|
||||
&DiskOption {
|
||||
cleanup: false,
|
||||
@@ -2056,7 +2117,7 @@ mod tests {
|
||||
disk_idx: 0,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(
|
||||
let remote_disk = new_remote_disk_with_default_transport(
|
||||
&endpoint,
|
||||
&DiskOption {
|
||||
cleanup: false,
|
||||
@@ -2094,7 +2155,7 @@ mod tests {
|
||||
disk_idx: 0,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(
|
||||
let remote_disk = new_remote_disk_with_default_transport(
|
||||
&endpoint,
|
||||
&DiskOption {
|
||||
cleanup: false,
|
||||
@@ -2133,7 +2194,7 @@ mod tests {
|
||||
disk_idx: 0,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(
|
||||
let remote_disk = new_remote_disk_with_default_transport(
|
||||
&endpoint,
|
||||
&DiskOption {
|
||||
cleanup: false,
|
||||
@@ -2176,7 +2237,7 @@ mod tests {
|
||||
disk_idx: 0,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(
|
||||
let remote_disk = new_remote_disk_with_default_transport(
|
||||
&endpoint,
|
||||
&DiskOption {
|
||||
cleanup: false,
|
||||
@@ -2223,7 +2284,7 @@ mod tests {
|
||||
disk_idx: 0,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(
|
||||
let remote_disk = new_remote_disk_with_default_transport(
|
||||
&endpoint,
|
||||
&DiskOption {
|
||||
cleanup: false,
|
||||
@@ -2275,7 +2336,7 @@ mod tests {
|
||||
disk_idx: 0,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(
|
||||
let remote_disk = new_remote_disk_with_default_transport(
|
||||
&endpoint,
|
||||
&DiskOption {
|
||||
cleanup: false,
|
||||
@@ -2327,7 +2388,7 @@ mod tests {
|
||||
disk_idx: 0,
|
||||
};
|
||||
|
||||
let remote_disk = RemoteDisk::new(
|
||||
let remote_disk = new_remote_disk_with_default_transport(
|
||||
&endpoint,
|
||||
&DiskOption {
|
||||
cleanup: false,
|
||||
|
||||
Reference in New Issue
Block a user