From 48d2285d36b76fadeea12826302e50c12f64514b Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Mon, 23 Sep 2024 15:32:48 +0800 Subject: [PATCH 01/10] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=B9=B6=E5=8F=91=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 1 + ecstore/Cargo.toml | 3 +- ecstore/src/sets.rs | 2 +- ecstore/src/store.rs | 150 +++++++++++++++++++++++++------------------ 4 files changed, 92 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22b19bba1..b8c76b3e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -447,6 +447,7 @@ dependencies = [ "http", "lazy_static", "netif", + "num_cpus", "openssl", "path-absolutize", "path-clean", diff --git a/ecstore/Cargo.toml b/ecstore/Cargo.toml index ada0fc7a5..75f503ef4 100644 --- a/ecstore/Cargo.toml +++ b/ecstore/Cargo.toml @@ -38,13 +38,14 @@ base64-simd = "0.8.0" sha2 = "0.10.8" hex-simd = "0.8.0" path-clean = "1.0.1" -tokio = { workspace = true, features = ["io-util"] } +tokio = { workspace = true, features = ["io-util", "sync"] } tokio-stream = "0.1.15" tonic.workspace = true tower.workspace = true rmp = "0.8.14" byteorder = "1.5.0" xxhash-rust = { version = "0.8.12", features = ["xxh64"] } +num_cpus = "1.16" [target.'cfg(not(windows))'.dependencies] openssl = "0.10.66" diff --git a/ecstore/src/sets.rs b/ecstore/src/sets.rs index 8698b2103..9bbe781a9 100644 --- a/ecstore/src/sets.rs +++ b/ecstore/src/sets.rs @@ -22,7 +22,7 @@ use crate::{ utils::hash, }; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Sets { pub id: Uuid, // pub sets: Vec, diff --git a/ecstore/src/store.rs b/ecstore/src/store.rs index 44473c3b0..74a4f0c45 100644 --- a/ecstore/src/store.rs +++ b/ecstore/src/store.rs @@ -24,7 +24,10 @@ use std::{ time::Duration, }; use time::OffsetDateTime; -use tokio::{fs, sync::RwLock}; +use tokio::{ + fs, + sync::{RwLock, Semaphore}, +}; use tracing::{debug, info, warn}; use uuid::Uuid; @@ -391,62 +394,71 @@ impl ECStore { object: &str, opts: &ObjectOptions, ) -> Result<(PoolObjInfo, Vec)> { - let mut futures = Vec::new(); - - for pool in self.pools.iter() { - futures.push(pool.get_object_info(bucket, object, opts)); - } - - let results = join_all(futures).await; - - let mut ress = Vec::new(); - - let mut i = 0; - - // join_all结果跟输入顺序一致 - for res in results { - let index = i; - - match res { - Ok(r) => { - ress.push(PoolObjInfo { - index, - object_info: r, - err: None, - }); - } - Err(e) => { - ress.push(PoolObjInfo { - index, - err: Some(e), - ..Default::default() - }); - } - } - i += 1; - } - - ress.sort_by(|a, b| { - let at = a.object_info.mod_time.unwrap_or(OffsetDateTime::UNIX_EPOCH); - let bt = b.object_info.mod_time.unwrap_or(OffsetDateTime::UNIX_EPOCH); - - at.cmp(&bt) - }); - - for res in ress { - // check - if res.err.is_none() { - // TODO: let errs = self.poolsWithObject() - return Ok((res, Vec::new())); - } - } - - let ret = PoolObjInfo::default(); - - Ok((ret, Vec::new())) + internal_get_pool_info_existing_with_opts(&self.pools, bucket, object, opts).await } } +async fn internal_get_pool_info_existing_with_opts( + pools: &[Sets], + bucket: &str, + object: &str, + opts: &ObjectOptions, +) -> Result<(PoolObjInfo, Vec)> { + let mut futures = Vec::new(); + + for pool in pools.iter() { + futures.push(pool.get_object_info(bucket, object, opts)); + } + + let results = join_all(futures).await; + + let mut ress = Vec::new(); + + let mut i = 0; + + // join_all结果跟输入顺序一致 + for res in results { + let index = i; + + match res { + Ok(r) => { + ress.push(PoolObjInfo { + index, + object_info: r, + err: None, + }); + } + Err(e) => { + ress.push(PoolObjInfo { + index, + err: Some(e), + ..Default::default() + }); + } + } + i += 1; + } + + ress.sort_by(|a, b| { + let at = a.object_info.mod_time.unwrap_or(OffsetDateTime::UNIX_EPOCH); + let bt = b.object_info.mod_time.unwrap_or(OffsetDateTime::UNIX_EPOCH); + + at.cmp(&bt) + }); + + for res in ress { + // check + if res.err.is_none() { + // TODO: let errs = self.poolsWithObject() + return Ok((res, Vec::new())); + } + } + + let ret = PoolObjInfo::default(); + + Ok((ret, Vec::new())) +} + #[derive(Debug, Default)] pub struct PoolObjInfo { pub index: usize, @@ -559,15 +571,29 @@ impl StorageAPI for ECStore { del_errs.push(None) } - // TODO: limte 限制并发数量 - let opt = ObjectOptions::default(); - // 取所有poolObjInfo - let mut futures = Vec::new(); - for obj in objects.iter() { - futures.push(self.get_pool_info_existing_with_opts(bucket, &obj.object_name, &opt)); - } + let mut jhs = Vec::new(); + let semaphore = Arc::new(Semaphore::new(num_cpus::get())); + let pools = Arc::new(self.pools.clone()); - let results = join_all(futures).await; + for obj in objects.iter() { + let (semaphore, pools, bucket, object_name, opt) = ( + semaphore.clone(), + pools.clone(), + bucket.to_string(), + obj.object_name.to_string(), + ObjectOptions::default(), + ); + + let jh = tokio::spawn(async move { + let _permit = semaphore.acquire().await.unwrap(); + internal_get_pool_info_existing_with_opts(pools.as_ref(), &bucket, &object_name, &opt).await + }); + jhs.push(jh); + } + let mut results = Vec::new(); + for jh in jhs { + results.push(jh.await.unwrap()); + } // 记录pool Index 对应的objects pool_idx -> objects idx let mut pool_index_objects = HashMap::new(); From 184d593d27ded9111822c1cf081f2db6d4653126 Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Mon, 23 Sep 2024 15:38:00 +0800 Subject: [PATCH 02/10] make clippy happy --- ecstore/src/sets.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/ecstore/src/sets.rs b/ecstore/src/sets.rs index 9bbe781a9..c9f77e8ee 100644 --- a/ecstore/src/sets.rs +++ b/ecstore/src/sets.rs @@ -205,10 +205,10 @@ impl StorageAPI for Sets { let mut set_obj_map = HashMap::new(); // hash key - let mut i = 0; - for obj in objects.iter() { + for (i, obj) in objects.iter().enumerate() { let idx = self.get_hashed_set_index(obj.object_name.as_str()); + #[allow(clippy::map_entry)] if !set_obj_map.contains_key(&idx) { set_obj_map.insert( idx, @@ -218,17 +218,13 @@ impl StorageAPI for Sets { obj: obj.clone(), }], ); - } else { - if let Some(val) = set_obj_map.get_mut(&idx) { - val.push(DelObj { - // set_idx: idx, - orig_idx: i, - obj: obj.clone(), - }); - } + } else if let Some(val) = set_obj_map.get_mut(&idx) { + val.push(DelObj { + // set_idx: idx, + orig_idx: i, + obj: obj.clone(), + }); } - - i += 1; } // TODO: 并发 @@ -237,15 +233,12 @@ impl StorageAPI for Sets { let objs: Vec = v.iter().map(|v| v.obj.clone()).collect(); let (dobjects, errs) = disks.delete_objects(bucket, objs, opts.clone()).await?; - let mut i = 0; - for err in errs { + for (i, err) in errs.into_iter().enumerate() { let obj = v.get(i).unwrap(); del_errs[obj.orig_idx] = err; del_objects[obj.orig_idx] = dobjects.get(i).unwrap().clone(); - - i += 1; } } From 3bc98eec161ce4359b5f23fd56d2094c838d38d2 Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Mon, 23 Sep 2024 16:07:02 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecstore/src/sets.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ecstore/src/sets.rs b/ecstore/src/sets.rs index c9f77e8ee..819cbd1e0 100644 --- a/ecstore/src/sets.rs +++ b/ecstore/src/sets.rs @@ -1,7 +1,8 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; use futures::future::join_all; use http::HeaderMap; +use tokio::sync::Semaphore; use tracing::warn; use uuid::Uuid; @@ -227,19 +228,31 @@ impl StorageAPI for Sets { } } - // TODO: 并发 + let semaphore = Arc::new(Semaphore::new(num_cpus::get())); + let mut jhs = Vec::with_capacity(semaphore.available_permits()); + for (k, v) in set_obj_map { let disks = self.get_disks(k); - let objs: Vec = v.iter().map(|v| v.obj.clone()).collect(); - let (dobjects, errs) = disks.delete_objects(bucket, objs, opts.clone()).await?; + let semaphore = semaphore.clone(); + let opts = opts.clone(); + let bucket = bucket.to_string(); - for (i, err) in errs.into_iter().enumerate() { - let obj = v.get(i).unwrap(); + let jh = tokio::spawn(async move { + let _permit = semaphore.acquire().await.unwrap(); + let objs: Vec = v.iter().map(|v| v.obj.clone()).collect(); + disks.delete_objects(&bucket, objs, opts).await + }); + jhs.push(jh); + } - del_errs[obj.orig_idx] = err; + let mut results = Vec::with_capacity(jhs.len()); + for jh in jhs { + results.push(jh.await?.unwrap()); + } - del_objects[obj.orig_idx] = dobjects.get(i).unwrap().clone(); - } + for (dobjects, errs) in results { + del_objects.extend(dobjects); + del_errs.extend(errs); } Ok((del_objects, del_errs)) From 20ba112bd854b88ea60b281f90a95c267acd01df Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Mon, 23 Sep 2024 16:27:33 +0800 Subject: [PATCH 04/10] make clippy happy --- ecstore/src/sets.rs | 2 +- ecstore/src/store.rs | 41 +++++++++++++---------------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/ecstore/src/sets.rs b/ecstore/src/sets.rs index 819cbd1e0..329d03f85 100644 --- a/ecstore/src/sets.rs +++ b/ecstore/src/sets.rs @@ -1,3 +1,4 @@ +#![allow(clippy::map_entry)] use std::{collections::HashMap, sync::Arc}; use futures::future::join_all; @@ -209,7 +210,6 @@ impl StorageAPI for Sets { for (i, obj) in objects.iter().enumerate() { let idx = self.get_hashed_set_index(obj.object_name.as_str()); - #[allow(clippy::map_entry)] if !set_obj_map.contains_key(&idx) { set_obj_map.insert( idx, diff --git a/ecstore/src/store.rs b/ecstore/src/store.rs index 74a4f0c45..5c270ba88 100644 --- a/ecstore/src/store.rs +++ b/ecstore/src/store.rs @@ -1,3 +1,4 @@ +#![allow(clippy::map_entry)] use crate::{ bucket_meta::BucketMetadata, disk::{ @@ -54,10 +55,11 @@ pub async fn update_erasure_type(setup_type: SetupType) { *is_erasure_sd = setup_type == SetupType::ErasureSD; } +type TypeLocalDiskSetDrives = Vec>>>; + lazy_static! { pub static ref GLOBAL_LOCAL_DISK_MAP: Arc>>> = Arc::new(RwLock::new(HashMap::new())); - pub static ref GLOBAL_LOCAL_DISK_SET_DRIVES: Arc>>>>> = - Arc::new(RwLock::new(Vec::new())); + pub static ref GLOBAL_LOCAL_DISK_SET_DRIVES: Arc> = Arc::new(RwLock::new(Vec::new())); } pub async fn find_local_disk(disk_path: &String) -> Option { @@ -79,7 +81,7 @@ pub async fn find_local_disk(disk_path: &String) -> Option { pub async fn all_local_disk_path() -> Vec { let disk_map = GLOBAL_LOCAL_DISK_MAP.read().await; - disk_map.keys().map(|v| v.clone()).collect() + disk_map.keys().cloned().collect() } pub async fn all_local_disk() -> Vec { @@ -159,6 +161,7 @@ pub struct ECStore { } impl ECStore { + #[allow(clippy::new_ret_no_self)] pub async fn new(_address: String, endpoint_pools: EndpointServerPools) -> Result<()> { // let layouts = DisksLayout::try_from(endpoints.as_slice())?; @@ -321,8 +324,8 @@ impl ECStore { if entry.is_object() { let fi = entry.to_fileinfo(&opts.bucket)?; - if fi.is_some() { - ress.push(fi.unwrap().into_object_info(&opts.bucket, &entry.name, false)); + if let Some(f) = fi { + ress.push(f.into_object_info(&opts.bucket, &entry.name, false)); } continue; } @@ -414,10 +417,8 @@ async fn internal_get_pool_info_existing_with_opts( let mut ress = Vec::new(); - let mut i = 0; - // join_all结果跟输入顺序一致 - for res in results { + for (i, res) in results.into_iter().enumerate() { let index = i; match res { @@ -436,7 +437,6 @@ async fn internal_get_pool_info_existing_with_opts( }); } } - i += 1; } ress.sort_by(|a, b| { @@ -598,8 +598,7 @@ impl StorageAPI for ECStore { // 记录pool Index 对应的objects pool_idx -> objects idx let mut pool_index_objects = HashMap::new(); - let mut i = 0; - for res in results { + for (i, res) in results.into_iter().enumerate() { match res { Ok((pinfo, _)) => { if pinfo.object_info.delete_marker && opts.version_id.is_empty() { @@ -627,8 +626,6 @@ impl StorageAPI for ECStore { del_errs[i] = Some(e) } } - - i += 1; } if !pool_index_objects.is_empty() { @@ -641,16 +638,7 @@ impl StorageAPI for ECStore { let obj_idxs = vals.unwrap(); // 取对应obj,理论上不会none - let objs: Vec = obj_idxs - .iter() - .filter_map(|&idx| { - if let Some(obj) = objects.get(idx) { - Some(obj.clone()) - } else { - None - } - }) - .collect(); + let objs: Vec = obj_idxs.iter().filter_map(|&idx| objects.get(idx).cloned()).collect(); if objs.is_empty() { continue; @@ -659,8 +647,7 @@ impl StorageAPI for ECStore { let (pdel_objs, perrs) = sets.delete_objects(bucket, objs, opts.clone()).await?; // perrs的顺序理论上跟obj_idxs顺序一致 - let mut i = 0; - for err in perrs { + for (i, err) in perrs.into_iter().enumerate() { let obj_idx = obj_idxs[i]; if err.is_some() { @@ -671,8 +658,6 @@ impl StorageAPI for ECStore { dobj.object_name = utils::path::decode_dir_object(&dobj.object_name); del_objects[obj_idx] = dobj; - - i += 1; } } } @@ -681,7 +666,7 @@ impl StorageAPI for ECStore { } async fn delete_object(&self, bucket: &str, object: &str, opts: ObjectOptions) -> Result { if opts.delete_prefix { - self.delete_prefix(bucket, &object).await?; + self.delete_prefix(bucket, object).await?; return Ok(ObjectInfo::default()); } From ef8995006d48296ee52348bbc9c954220cc67b44 Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Fri, 20 Sep 2024 16:11:49 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 39 +++++++++++++++++++++++++++++++++++++++ Makefile | 18 ++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..2208355a5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +FROM m.daocloud.io/docker.io/library/ubuntu:22.04 + +ENV LANG C.UTF-8 + +RUN sed -i s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g /etc/apt/sources.list + +RUN apt-get clean && apt-get update && apt-get install wget git curl unzip gcc pkg-config libssl-dev -y + +# install protoc +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protoc-27.0-linux-x86_64.zip \ + && unzip protoc-27.0-linux-x86_64.zip -d protoc3 \ + && mv protoc3/bin/* /usr/local/bin/ && chmod +x /usr/local/bin/protoc && mv protoc3/include/* /usr/local/include/ && rm -rf protoc-27.0-linux-x86_64.zip protoc3 + +# install flatc +RUN wget https://github.com/google/flatbuffers/releases/download/v24.3.25/Linux.flatc.binary.g++-13.zip \ + && unzip Linux.flatc.binary.g++-13.zip \ + && mv flatc /usr/local/bin/ && chmod +x /usr/local/bin/flatc && rm -rf Linux.flatc.binary.g++-13.zip + +# install rust +ENV RUSTUP_DIST_SERVER="https://rsproxy.cn" +ENV RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" +RUN curl -o rustup-init.sh --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh \ + && sh rustup-init.sh -y && rm -rf rustup-init.sh + +RUN echo "[source.crates-io]" > /root/.cargo/config.toml \ +&& echo "registry = \"https://github.com/rust-lang/crates.io-index\"" >> /root/.cargo/config.toml \ +&& echo "replace-with = \"rsproxy-sparse\"" >> /root/.cargo/config.toml \ +&& echo "[source.rsproxy]" >> /root/.cargo/config.toml \ +&& echo "registry = \"https://rsproxy.cn/crates.io-index\"" >> /root/.cargo/config.toml \ +&& echo "[source.rsproxy-sparse]" >> /root/.cargo/config.toml \ +&& echo "registry = \"sparse+https://rsproxy.cn/index/\"" >> /root/.cargo/config.toml \ +&& echo "[registries.rsproxy]" >> /root/.cargo/config.toml \ +&& echo "index = \"https://rsproxy.cn/crates.io-index\"" >> /root/.cargo/config.toml \ +&& echo "[net]" >> /root/.cargo/config.toml \ +&& echo "git-fetch-with-cli = true" >> /root/.cargo/config.toml + +WORKDIR /root/s3-rustfs + +CMD [ "bash", "-c", "while true; do sleep 1; done" ] diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..d96c37069 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +########### +# 远程开发,需要 VSCode 安装 Dev Containers, Remote SSH, Remote Explorer +# https://code.visualstudio.com/docs/remote/containers +########### +DOCKER_CLI ?= docker +IMAGE_NAME ?= rustfs:v1.0.0 +CONTAINER_NAME ?= rustfs-dev + +.PHONY: init +init: + $(DOCKER_CLI) build -t $(IMAGE_NAME) . + $(DOCKER_CLI) stop $(CONTAINER_NAME) + $(DOCKER_CLI) rm $(CONTAINER_NAME) + $(DOCKER_CLI) run -d --name $(CONTAINER_NAME) -p 9010:9010 -v $(shell pwd):/root/s3-rustfs -it $(IMAGE_NAME) + +.PHONY: start +start: + $(DOCKER_CLI) start $(CONTAINER_NAME) From f6be1cecfe62945e5d2044d4dab0a623213ae09a Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Fri, 20 Sep 2024 16:29:11 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d96c37069..6b3ef8eac 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ init: $(DOCKER_CLI) build -t $(IMAGE_NAME) . $(DOCKER_CLI) stop $(CONTAINER_NAME) $(DOCKER_CLI) rm $(CONTAINER_NAME) - $(DOCKER_CLI) run -d --name $(CONTAINER_NAME) -p 9010:9010 -v $(shell pwd):/root/s3-rustfs -it $(IMAGE_NAME) + $(DOCKER_CLI) run -d --name $(CONTAINER_NAME) -p 9010:9010 -p 9000:9000 -v $(shell pwd):/root/s3-rustfs -it $(IMAGE_NAME) .PHONY: start start: From 8381eb96d5e223d133855b86f1ed9788291e9c37 Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Mon, 23 Sep 2024 16:48:53 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E8=AE=BE=E7=BD=AEci=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile => .docker/Dockerfile.devenv | 12 +----- .docker/cargo.config.toml | 13 +++++++ .github/workflows/rust.yml | 50 +++++++++++++++++++++---- Makefile | 11 ++++-- 4 files changed, 65 insertions(+), 21 deletions(-) rename Dockerfile => .docker/Dockerfile.devenv (60%) create mode 100644 .docker/cargo.config.toml diff --git a/Dockerfile b/.docker/Dockerfile.devenv similarity index 60% rename from Dockerfile rename to .docker/Dockerfile.devenv index 2208355a5..e95027d2e 100644 --- a/Dockerfile +++ b/.docker/Dockerfile.devenv @@ -22,17 +22,7 @@ ENV RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" RUN curl -o rustup-init.sh --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh \ && sh rustup-init.sh -y && rm -rf rustup-init.sh -RUN echo "[source.crates-io]" > /root/.cargo/config.toml \ -&& echo "registry = \"https://github.com/rust-lang/crates.io-index\"" >> /root/.cargo/config.toml \ -&& echo "replace-with = \"rsproxy-sparse\"" >> /root/.cargo/config.toml \ -&& echo "[source.rsproxy]" >> /root/.cargo/config.toml \ -&& echo "registry = \"https://rsproxy.cn/crates.io-index\"" >> /root/.cargo/config.toml \ -&& echo "[source.rsproxy-sparse]" >> /root/.cargo/config.toml \ -&& echo "registry = \"sparse+https://rsproxy.cn/index/\"" >> /root/.cargo/config.toml \ -&& echo "[registries.rsproxy]" >> /root/.cargo/config.toml \ -&& echo "index = \"https://rsproxy.cn/crates.io-index\"" >> /root/.cargo/config.toml \ -&& echo "[net]" >> /root/.cargo/config.toml \ -&& echo "git-fetch-with-cli = true" >> /root/.cargo/config.toml +COPY .docker/cargo.config.toml /root/.cargo/config.toml WORKDIR /root/s3-rustfs diff --git a/.docker/cargo.config.toml b/.docker/cargo.config.toml new file mode 100644 index 000000000..ef2fa863f --- /dev/null +++ b/.docker/cargo.config.toml @@ -0,0 +1,13 @@ +[source.crates-io] +registry = "https://github.com/rust-lang/crates.io-index" +replace-with = 'rsproxy-sparse' + +[source.rsproxy] +registry = "https://rsproxy.cn/crates.io-index" +[registries.rsproxy] +index = "https://rsproxy.cn/crates.io-index" +[source.rsproxy-sparse] +registry = "sparse+https://rsproxy.cn/index/" + +[net] +git-fetch-with-cli = true diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e090..aa949c986 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,8 +1,8 @@ name: Rust on: + workflow_dispatch: push: - branches: [ "main" ] pull_request: branches: [ "main" ] @@ -11,12 +11,48 @@ env: jobs: build: - runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - beta + - nightly steps: - - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - name: cache protoc bin + id: cache-protoc-action + uses: actions/cache@v3 + env: + cache-name: cache-protoc-action-bin + with: + path: /usr/local/bin/protoc + key: ${{ runner.os }}-build-${{ env.cache-name }}-v0.0.1 + + - name: install protoc + if: steps.cache-protoc-action.outputs.cache-hit != 'true' + run: | + wget https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protoc-27.0-linux-x86_64.zip + unzip protoc-27.0-linux-x86_64.zip -d protoc3 + mv protoc3/bin/* /usr/local/bin/ + chmod +x /usr/local/bin/protoc + rm -rf protoc-27.0-linux-x86_64.zip protoc3 + + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + components: rustfmt, clippy + + - uses: actions-rs/cargo@v1 + with: + command: build + args: --verbose + + - uses: actions-rs/cargo@v1 + with: + command: test + args: --all --verbose diff --git a/Makefile b/Makefile index 6b3ef8eac..6f05e92b5 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,11 @@ DOCKER_CLI ?= docker IMAGE_NAME ?= rustfs:v1.0.0 CONTAINER_NAME ?= rustfs-dev +DOCKERFILE ?= $(shell pwd)/.docker/Dockerfile.devenv -.PHONY: init -init: - $(DOCKER_CLI) build -t $(IMAGE_NAME) . +.PHONY: init-devenv +init-devenv: + $(DOCKER_CLI) build -t $(IMAGE_NAME) -f $(DOCKERFILE) . $(DOCKER_CLI) stop $(CONTAINER_NAME) $(DOCKER_CLI) rm $(CONTAINER_NAME) $(DOCKER_CLI) run -d --name $(CONTAINER_NAME) -p 9010:9010 -p 9000:9000 -v $(shell pwd):/root/s3-rustfs -it $(IMAGE_NAME) @@ -16,3 +17,7 @@ init: .PHONY: start start: $(DOCKER_CLI) start $(CONTAINER_NAME) + +.PHONY: stop +stop: + $(DOCKER_CLI) stop $(CONTAINER_NAME) From ed6fde5e4d43bd44a55e9cd895a71b9383202e52 Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Mon, 23 Sep 2024 18:05:18 +0800 Subject: [PATCH 08/10] print protoc version --- .github/workflows/rust.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index aa949c986..cd5d532c4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -37,7 +37,10 @@ jobs: mv protoc3/bin/* /usr/local/bin/ chmod +x /usr/local/bin/protoc rm -rf protoc-27.0-linux-x86_64.zip protoc3 - + + - name: print protoc version + run: protoc --version + - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 From 54101378e3420c8f9f4483a4971f81d2557c3dba Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Mon, 23 Sep 2024 18:11:08 +0800 Subject: [PATCH 09/10] install flatc --- .github/workflows/rust.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cd5d532c4..83f4d280a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,7 +40,25 @@ jobs: - name: print protoc version run: protoc --version - + + - name: cache flatc bin + id: cache-flatc-action + uses: actions/cache@v3 + env: + cache-name: cache-flatc-action-bin + with: + path: /usr/local/bin/flatc + key: ${{ runner.os }}-build-${{ env.cache-name }}-v0.0.1 + + - name: install flatc + if: steps.cache-flatc-action.outputs.cache-hit != 'true' + run: | + wget https://github.com/google/flatbuffers/releases/download/v24.3.25/Linux.flatc.binary.g++-13.zip + unzip Linux.flatc.binary.g++-13.zip + mv flatc /usr/local/bin/ + chmod +x /usr/local/bin/flatc + rm -rf Linux.flatc.binary.g++-13.zip + - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 From 8cce210d640351585bab191482f3693813fd5d17 Mon Sep 17 00:00:00 2001 From: JimChenWYU Date: Mon, 23 Sep 2024 18:44:55 +0800 Subject: [PATCH 10/10] install flatc --- .github/workflows/rust.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 83f4d280a..6dd5d7024 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -71,9 +71,8 @@ jobs: - uses: actions-rs/cargo@v1 with: command: build - args: --verbose - uses: actions-rs/cargo@v1 with: command: test - args: --all --verbose + args: --all