Skip to content

Commit

Permalink
fix cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
heqingpan committed Oct 7, 2024
1 parent fa2b93c commit cfb2b15
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 62 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ bcrypt = "0.15"

[target.'cfg(any(target_os = "linux", target_os = "macos", target_os="windows"))'.dependencies]
fs2 = "0.4.3"
dirs = "5.0"

[dependencies.uuid]
version = "1.2.1"
Expand Down
9 changes: 5 additions & 4 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::common::string_utils::StringUtils;
use std::env;
use std::sync::Arc;
use uuid::Uuid;

Expand Down Expand Up @@ -33,6 +32,8 @@ lazy_static! {
}
*/

const DEFAULT_DB_PATH: &str = "nacos_db";

#[derive(Default, Clone, Debug)]
pub struct NamingSysConfig {
pub once_time_check_size: usize,
Expand Down Expand Up @@ -233,17 +234,17 @@ impl AppSysConfig {
v
} else if run_in_docker {
// 运行在docker,默认值保持一致
"nacos_db".to_owned()
DEFAULT_DB_PATH.to_owned()
} else {
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
if let Some(mut home) = env::home_dir() {
if let Some(mut home) = dirs::home_dir() {
home.push(".local/share/r-nacos/nacos_db");
return home.to_string_lossy().to_string();
}
}
// windows系统默认值保持一致
"nacos_db".to_owned()
DEFAULT_DB_PATH.to_owned()
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/console/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ use std::sync::Arc;

use crate::common::appdata::AppShareData;
use crate::common::string_utils::StringUtils;
use crate::config::core::ConfigActor;
use actix::prelude::*;
use actix_web::{http::header, web, HttpResponse, Responder};
use uuid::Uuid;

use crate::naming::ops::ops_api::query_opt_service_list;
use crate::openapi::naming::instance::{del_instance, get_instance, update_instance};
use crate::openapi::naming::service::{query_service, remove_service, update_service};
//use crate::console::raft_api::{raft_add_learner, raft_change_membership, raft_init, raft_metrics, raft_read, raft_write};

use super::cluster_api::query_cluster_info;
use super::config_api::query_config_list;
Expand Down
2 changes: 1 addition & 1 deletion src/console/config_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn zip_file(mut zip: ZipWriter<&mut File>, list: Vec<ConfigInfoDto>) -> anyhow::
.compression_method(zip::CompressionMethod::Stored)
.unix_permissions(0o755);
zip.start_file(
&format!("{}/{}", &item.group.as_str(), &item.data_id.as_str()),
format!("{}/{}", &item.group.as_str(), &item.data_id.as_str()),
options,
)?;
zip.write_all(item.content.as_ref().unwrap().as_bytes())?;
Expand Down
6 changes: 1 addition & 5 deletions src/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ impl NamespaceUtilsOld {
if namespace_str.is_empty() {
return vec![];
}
if let Ok(namespaces) = serde_json::from_str::<Vec<NamespaceInfo>>(&namespace_str) {
namespaces
} else {
vec![]
}
serde_json::from_str::<Vec<NamespaceInfo>>(&namespace_str).unwrap_or_default()
}

pub async fn save_namespace(
Expand Down
5 changes: 2 additions & 3 deletions src/console/transfer_api.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::common::appdata::AppShareData;
use crate::config::ConfigUtils;
use crate::console::config_api::UploadForm;
use crate::now_millis;
use crate::transfer::model::{
TransferBackupParam, TransferImportParam, TransferImportRequest, TransferImportResponse,
TransferBackupParam, TransferImportParam, TransferImportResponse,
TransferManagerAsyncRequest, TransferManagerResponse,
};
use actix_multipart::form::MultipartForm;
Expand Down Expand Up @@ -34,7 +33,7 @@ pub async fn download_transfer_file(
let mut buf = vec![];
tmpfile.read_to_end(&mut buf).await.ok();

let filename = format!("rnacos_export_{}.bak", now_millis());
let filename = format!("rnacos_export_{}.data", now_millis());
HttpResponse::Ok()
.insert_header(header::ContentType::octet_stream())
.insert_header(header::ContentDisposition::attachment(filename))
Expand Down
2 changes: 0 additions & 2 deletions src/console/v2/namespace_api.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::common::appdata::AppShareData;
use crate::common::model::ApiResult;
use crate::common::string_utils::StringUtils;
use crate::config::core::ConfigActor;
use crate::console::model::NamespaceInfo;
use crate::console::NamespaceUtils;
//use actix::Addr;
use actix_web::{web, HttpResponse, Responder};
use std::sync::Arc;
use uuid::Uuid;
Expand Down
11 changes: 5 additions & 6 deletions src/namespace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
pub mod model;

use crate::common::byte_utils::id_to_bin;
use crate::common::constant::{
CONFIG_TREE_NAME, EMPTY_ARC_STRING, NAMESPACE_TREE_NAME, SEQUENCE_TREE_NAME, SEQ_KEY_CONFIG,
EMPTY_ARC_STRING, NAMESPACE_TREE_NAME,
};
use crate::common::string_utils::StringUtils;
use crate::config::core::ConfigActor;
use crate::config::model::ConfigValueDO;
use crate::console::model::NamespaceInfo;
use crate::console::NamespaceUtilsOld;
use crate::namespace::model::{
Namespace, NamespaceDO, NamespaceParam, NamespaceQueryReq, NamespaceQueryResult,
Expand Down Expand Up @@ -113,8 +110,10 @@ impl NamespaceActor {
if only_add {
return;
}
let mut value = Namespace::default();
value.namespace_id = param.namespace_id;
let mut value = Namespace{
namespace_id: param.namespace_id,
..Namespace::default()
};
value.namespace_name = if let Some(name) = param.namespace_name {
name
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/openapi/config/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cmp::{max, min};
use std::collections::HashMap;
use std::sync::Arc;

Expand Down Expand Up @@ -389,7 +388,7 @@ pub(super) async fn listener_config(
if let Some(_timeout) = _req.headers().get("Long-Pulling-Timeout") {
match _timeout.to_str().unwrap().parse::<i64>() {
Ok(v) => {
time_out = current_time + min(max(10000, v), 120000) - 500;
time_out = current_time + v.clamp(10000, 120000) - 500;
}
Err(_) => {
time_out = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/raft/db/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};

use actix::prelude::*;

use crate::common::constant::{CACHE_TREE_NAME, NAMESPACE_TREE_NAME, USER_TREE_NAME};
use crate::common::constant::{CACHE_TREE_NAME, USER_TREE_NAME};
use crate::common::sequence_utils::SimpleSequence;
use crate::raft::filestore::model::SnapshotRecordDto;
use crate::raft::filestore::raftsnapshot::{SnapshotWriterActor, SnapshotWriterRequest};
Expand Down
3 changes: 1 addition & 2 deletions src/raft/filestore/raftapply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
log::SnapshotRange,
model::{ApplyRequestDto, LogRecordLoader, MemberShip, SnapshotHeaderDto},
raftindex::{RaftIndexManager, RaftIndexRequest, RaftIndexResponse},
raftlog::{RaftLogManager, RaftLogManagerAsyncRequest, RaftLogManagerRequest},
raftlog::{RaftLogManager, RaftLogManagerAsyncRequest},
raftsnapshot::{
RaftSnapshotManager, RaftSnapshotRequest, RaftSnapshotResponse, SnapshotReader,
},
Expand All @@ -18,7 +18,6 @@ use crate::common::constant::{
};
use crate::config::core::{ConfigCmd, ConfigKey, ConfigValue};
use crate::config::model::{ConfigRaftCmd, ConfigValueDO};
use crate::namespace::model::{NamespaceParam, NamespaceRaftReq};
use crate::raft::db::table::{TableManagerInnerReq, TableManagerReq};
use crate::raft::filestore::model::SnapshotRecordDto;
use crate::raft::filestore::raftdata::RaftDataWrap;
Expand Down
8 changes: 1 addition & 7 deletions src/raft/filestore/raftindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,7 @@ impl RaftIndexManager {
#[cfg(all(not(miri), any(windows, target_os = "linux", target_os = "macos")))]
{
use fs2::FileExt;

let try_lock = if cfg!(any(feature = "testing", feature = "light_testing")) {
file.lock_exclusive()
} else {
file.try_lock_exclusive()
};
if try_lock.is_err() {
if file.try_lock_exclusive().is_err() {
log::error!("try lock db error,path:{}", &path);
return Err(anyhow::anyhow!("try lock db error,path:{}", &path));
}
Expand Down
1 change: 0 additions & 1 deletion src/raft/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::sync::Arc;

use super::db::table::TableManagerReq;
use crate::config::core::{ConfigKey, ConfigValue};
use crate::namespace::model::NamespaceRaftReq;
use async_raft_ext::AppData;
use async_raft_ext::AppDataResponse;
Expand Down
47 changes: 25 additions & 22 deletions src/transfer/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@ use crate::common::constant::{
use crate::common::pb::transfer::{TransferHeader, TransferItem};
use crate::common::protobuf_utils::MessageBufReader;
use crate::common::sequence_utils::CacheSequence;
use crate::config::core::{ConfigActor, ConfigCmd, ConfigKey, ConfigResult, ConfigValue};
use crate::config::core::{ConfigActor, ConfigCmd, ConfigResult, ConfigValue};
use crate::config::model::ConfigValueDO;
use crate::namespace::model::{Namespace, NamespaceDO, NamespaceParam, NamespaceRaftReq};
use crate::now_millis_i64;
use crate::raft::db::table::TableManagerReq;
use crate::raft::filestore::raftdata::RaftDataWrap;
use crate::raft::store::ClientRequest;
use crate::raft::NacosRaft;
use crate::transfer::model::{
TransferHeaderDto, TransferImportParam, TransferImportRequest, TransferImportResponse,
TransferPrefix, TransferRecordDto, TransferRecordRef,
TransferPrefix, TransferRecordRef,
};
use actix::prelude::*;
use anyhow::anyhow;
use async_raft_ext::raft::ClientWriteRequest;
use bean_factory::{bean, BeanFactory, FactoryData, Inject};
use binrw::BinReaderExt;
use quick_protobuf::BytesReader;
use std::io::{BufReader, Cursor};
use std::sync::{Arc, Weak};
use std::io::Cursor;
use std::sync::Arc;

pub struct TransferReader {
message_reader: MessageBufReader,
prefix: TransferPrefix,
//prefix: TransferPrefix,
header: TransferHeaderDto,
}

Expand All @@ -48,7 +46,7 @@ impl TransferReader {
};
Ok(Self {
message_reader,
prefix,
//prefix,
header,
})
}
Expand Down Expand Up @@ -102,8 +100,7 @@ impl ConfigCacheSequence {
pub async fn next_state(&mut self) -> anyhow::Result<(u64, Option<u64>)> {
if let Some(next_id) = self.seq.next_id() {
Ok((next_id, None))
} else {
if let ConfigResult::SequenceSection { start, end } = self
} else if let ConfigResult::SequenceSection { start, end } = self
.config
.send(ConfigCmd::GetSequenceSection(100))
.await??
Expand All @@ -113,7 +110,7 @@ impl ConfigCacheSequence {
} else {
Err(anyhow::anyhow!("config result is error"))
}
}

}
}

Expand All @@ -124,6 +121,13 @@ pub struct TransferImportManager {
importing: bool,
}

impl Default for TransferImportManager {
fn default() -> Self {
Self::new()
}
}


impl TransferImportManager {
pub fn new() -> Self {
Self {
Expand All @@ -139,22 +143,21 @@ impl TransferImportManager {
raft: Option<Arc<NacosRaft>>,
data_wrap: Option<Arc<RaftDataWrap>>,
) -> anyhow::Result<()> {
if let (Some(raft), Some(data_wrap)) = (raft, data_wrap) {
if let (Some(raft), Some(data_wrap)) = (&raft, data_wrap) {
let mut count = 0;
let mut ignore = 0;
let mut reader = TransferReader::new(data)?;
let mut config_seq = ConfigCacheSequence::new(data_wrap.config.clone());
while let Ok(Some(record)) = reader.read_record() {
count += 1;
if param.config && record.table_name.as_str() == CONFIG_TREE_NAME.as_str() {
Self::apply_config(&raft, &mut config_seq, record).await?;
Self::apply_config(raft, &mut config_seq, record).await?;
} else if param.config && record.table_name.as_str() == NAMESPACE_TREE_NAME.as_str()
{
Self::apply_namespace(&raft, record).await?;
} else if param.user && record.table_name.as_str() == USER_TREE_NAME.as_str() {
Self::apply_table(&raft, record).await?;
} else if param.cache && record.table_name.as_str() == CACHE_TREE_NAME.as_str() {
Self::apply_table(&raft, record).await?;
Self::apply_namespace(raft, record).await?;
} else if ( param.user && record.table_name.as_str() == USER_TREE_NAME.as_str() ) ||
(param.cache && record.table_name.as_str() == CACHE_TREE_NAME.as_str()) {
Self::apply_table(raft, record).await?;
} else {
ignore += 1;
}
Expand All @@ -175,7 +178,7 @@ impl TransferImportManager {
last_seq_id: None,
};
let req = ClientRequest::TableManagerReq(table_req);
Self::send_raft_request(&raft, req).await?;
Self::send_raft_request(raft, req).await?;
Ok(())
}

Expand All @@ -191,7 +194,7 @@ impl TransferImportManager {
r#type: Some(value.r#type),
};
let req = ClientRequest::NamespaceReq(NamespaceRaftReq::Update(param));
Self::send_raft_request(&raft, req).await?;
Self::send_raft_request(raft, req).await?;
Ok(())
}

Expand All @@ -216,7 +219,7 @@ impl TransferImportManager {
value: save_do.to_bytes()?,
last_seq_id: update_last_id,
};
Self::send_raft_request(&raft, req).await?;
Self::send_raft_request(raft, req).await?;
Ok(())
}

Expand Down Expand Up @@ -250,7 +253,7 @@ impl TransferImportManager {
impl Actor for TransferImportManager {
type Context = Context<Self>;

fn started(&mut self, ctx: &mut Self::Context) {
fn started(&mut self, _ctx: &mut Self::Context) {
log::info!("TransferReaderManager started");
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/transfer/writer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::suspicious_open_options)]
use crate::common::constant::{
CACHE_TREE_NAME, CONFIG_TREE_NAME, EMPTY_STR, NAMESPACE_TREE_NAME, SEQUENCE_TREE_NAME,
USER_TREE_NAME,
Expand Down Expand Up @@ -194,7 +195,7 @@ impl TransferWriterManager {

fn build_writer_actor(&self) -> Addr<TransferWriterActor> {
let mut path = self.tmp_dir.clone();
path.push(format!("{}.bak", Uuid::new_v4().simple().to_string()));
path.push(format!("{}.data", Uuid::new_v4().simple()));
let writer_actor = TransferWriterActor::new(path, self.version).start();
writer_actor.do_send(TransferWriterRequest::AddTableNameMap(
CONFIG_TREE_NAME.clone(),
Expand Down Expand Up @@ -258,7 +259,7 @@ impl TransferWriterManager {
impl Actor for TransferWriterManager {
type Context = Context<Self>;

fn started(&mut self, ctx: &mut Self::Context) {
fn started(&mut self, _ctx: &mut Self::Context) {
log::info!("TransferWriterManager started");
}
}
Expand Down Expand Up @@ -294,7 +295,7 @@ impl Handler<TransferManagerAsyncRequest> for TransferWriterManager {
}
}
.into_actor(self)
.map(|r, act, _ctx| {
.map(|r, _act, _ctx| {
let path = r?;
Ok(TransferManagerResponse::BackupFile(TempFile::new(path)))
});
Expand Down

0 comments on commit cfb2b15

Please sign in to comment.