chore(protos): update proto definitions, remove ns_scanner, fix codegen and formatting

Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
junxiang Mu
2025-07-21 18:16:29 +08:00
parent e7d0a8d4b9
commit 3d3c6e4e06
4 changed files with 43 additions and 90 deletions

View File

@@ -28,6 +28,12 @@
- Type-safe message definitions
- Code generation for multiple programming languages
## generate code
```
cargo run --bin gproto
```
## 📚 Documentation
For comprehensive documentation, examples, and usage guides, please visit the main [RustFS repository](https://github.com/rustfs/rustfs).

View File

@@ -604,26 +604,6 @@ pub struct DiskInfoResponse {
#[prost(message, optional, tag = "3")]
pub error: ::core::option::Option<Error>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct NsScannerRequest {
#[prost(string, tag = "1")]
pub disk: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub cache: ::prost::alloc::string::String,
#[prost(uint64, tag = "3")]
pub scan_mode: u64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct NsScannerResponse {
#[prost(bool, tag = "1")]
pub success: bool,
#[prost(string, tag = "2")]
pub update: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub data_usage_cache: ::prost::alloc::string::String,
#[prost(message, optional, tag = "4")]
pub error: ::core::option::Option<Error>,
}
/// lock api have same argument type
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerallyLockRequest {
@@ -1660,21 +1640,6 @@ pub mod node_service_client {
.insert(GrpcMethod::new("node_service.NodeService", "DiskInfo"));
self.inner.unary(req, path, codec).await
}
pub async fn ns_scanner(
&mut self,
request: impl tonic::IntoStreamingRequest<Message = super::NsScannerRequest>,
) -> std::result::Result<tonic::Response<tonic::codec::Streaming<super::NsScannerResponse>>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| tonic::Status::unknown(format!("Service was not ready: {}", e.into())))?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/node_service.NodeService/NsScanner");
let mut req = request.into_streaming_request();
req.extensions_mut()
.insert(GrpcMethod::new("node_service.NodeService", "NsScanner"));
self.inner.streaming(req, path, codec).await
}
pub async fn lock(
&mut self,
request: impl tonic::IntoRequest<super::GenerallyLockRequest>,
@@ -2466,14 +2431,6 @@ pub mod node_service_server {
&self,
request: tonic::Request<super::DiskInfoRequest>,
) -> std::result::Result<tonic::Response<super::DiskInfoResponse>, tonic::Status>;
/// Server streaming response type for the NsScanner method.
type NsScannerStream: tonic::codegen::tokio_stream::Stream<Item = std::result::Result<super::NsScannerResponse, tonic::Status>>
+ std::marker::Send
+ 'static;
async fn ns_scanner(
&self,
request: tonic::Request<tonic::Streaming<super::NsScannerRequest>>,
) -> std::result::Result<tonic::Response<Self::NsScannerStream>, tonic::Status>;
async fn lock(
&self,
request: tonic::Request<super::GenerallyLockRequest>,
@@ -3670,35 +3627,6 @@ pub mod node_service_server {
};
Box::pin(fut)
}
"/node_service.NodeService/NsScanner" => {
#[allow(non_camel_case_types)]
struct NsScannerSvc<T: NodeService>(pub Arc<T>);
impl<T: NodeService> tonic::server::StreamingService<super::NsScannerRequest> for NsScannerSvc<T> {
type Response = super::NsScannerResponse;
type ResponseStream = T::NsScannerStream;
type Future = BoxFuture<tonic::Response<Self::ResponseStream>, tonic::Status>;
fn call(&mut self, request: tonic::Request<tonic::Streaming<super::NsScannerRequest>>) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { <T as NodeService>::ns_scanner(&inner, request).await };
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = NsScannerSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(accept_compression_encodings, send_compression_encodings)
.apply_max_message_size_config(max_decoding_message_size, max_encoding_message_size);
let res = grpc.streaming(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/node_service.NodeService/Lock" => {
#[allow(non_camel_case_types)]
struct LockSvc<T: NodeService>(pub Arc<T>);

View File

@@ -16,7 +16,7 @@ use std::{cmp, env, fs, io::Write, path::Path, process::Command};
type AnyError = Box<dyn std::error::Error>;
const VERSION_PROTOBUF: Version = Version(30, 2, 0); // 30.2.0
const VERSION_PROTOBUF: Version = Version(27, 2, 0); // 27.2.0
const VERSION_FLATBUFFERS: Version = Version(24, 3, 25); // 24.3.25
/// Build protos if the major version of `flatc` or `protoc` is greater
/// or lesser than the expected version.
@@ -27,7 +27,7 @@ const ENV_FLATC_PATH: &str = "FLATC_PATH";
fn main() -> Result<(), AnyError> {
let version = protobuf_compiler_version()?;
let need_compile = match version.compare_ext(&VERSION_PROTOBUF) {
Ok(cmp::Ordering::Equal) => true,
Ok(cmp::Ordering::Greater) => true,
Ok(_) => {
let version_err = Version::build_error_message(&version, &VERSION_PROTOBUF).unwrap();
println!("cargo:warning=Tool `protoc` {version_err}, skip compiling.");
@@ -47,6 +47,7 @@ fn main() -> Result<(), AnyError> {
// path of proto file
let project_root_dir = env::current_dir()?.join("crates/protos/src");
let proto_dir = project_root_dir.clone();
println!("proto_dir: {proto_dir:?}");
let proto_files = &["node.proto"];
let proto_out_dir = project_root_dir.join("generated").join("proto_gen");
let flatbuffer_out_dir = project_root_dir.join("generated").join("flatbuffers_generated");
@@ -67,12 +68,44 @@ fn main() -> Result<(), AnyError> {
let mut generated_mod_rs = fs::File::create(generated_mod_rs_path)?;
writeln!(&mut generated_mod_rs, "pub mod node_service;")?;
writeln!(
&mut generated_mod_rs,
r#"// Copyright 2024 RustFS Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License."#
)?;
generated_mod_rs.flush()?;
let generated_mod_rs_path = project_root_dir.join("generated").join("mod.rs");
let mut generated_mod_rs = fs::File::create(generated_mod_rs_path)?;
writeln!(&mut generated_mod_rs, "#![allow(unused_imports)]")?;
writeln!(
&mut generated_mod_rs,
r#"// Copyright 2024 RustFS Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License."#
)?;
writeln!(&mut generated_mod_rs, "#![allow(clippy::all)]")?;
writeln!(&mut generated_mod_rs, "pub mod proto_gen;")?;
generated_mod_rs.flush()?;
@@ -107,7 +140,7 @@ fn compile_flatbuffers_models<P: AsRef<Path>, S: AsRef<str>>(
) -> Result<(), AnyError> {
let version = flatbuffers_compiler_version(flatc_path)?;
let need_compile = match version.compare_ext(&VERSION_FLATBUFFERS) {
Ok(cmp::Ordering::Equal) => true,
Ok(cmp::Ordering::Greater) => true,
Ok(_) => {
let version_err = Version::build_error_message(&version, &VERSION_FLATBUFFERS).unwrap();
println!("cargo:warning=Tool `{flatc_path}` {version_err}, skip compiling.");
@@ -217,7 +250,7 @@ impl Version {
Ok(self.compare_major_version(expected_version))
} else {
match self.compare_major_version(expected_version) {
cmp::Ordering::Equal => Ok(cmp::Ordering::Equal),
cmp::Ordering::Greater => Ok(cmp::Ordering::Greater),
_ => Err(Self::build_error_message(self, expected_version).unwrap()),
}
}

View File

@@ -423,19 +423,6 @@ message DiskInfoResponse {
optional Error error = 3;
}
message NsScannerRequest {
string disk = 1;
string cache = 2;
uint64 scan_mode = 3;
}
message NsScannerResponse {
bool success = 1;
string update = 2;
string data_usage_cache = 3;
optional Error error = 4;
}
// lock api have same argument type
message GenerallyLockRequest {
string args = 1;
@@ -805,7 +792,6 @@ service NodeService {
rpc ReadMultiple(ReadMultipleRequest) returns (ReadMultipleResponse) {};
rpc DeleteVolume(DeleteVolumeRequest) returns (DeleteVolumeResponse) {};
rpc DiskInfo(DiskInfoRequest) returns (DiskInfoResponse) {};
rpc NsScanner(stream NsScannerRequest) returns (stream NsScannerResponse) {};
/* -------------------------------lock service-------------------------- */