From 6a4f86340d9e9c4cffbd9a1204004035b572d6d6 Mon Sep 17 00:00:00 2001 From: JohnsonLee <53596783+J0HN50N133@users.noreply.github.com> Date: Mon, 15 Apr 2024 19:50:09 +0800 Subject: [PATCH] chore: remove redundant code in `roxy` and refine ci with `paths` filter (#8) * refactor: remove redundant code and inappropriate name in roxy * ci: use path filter to avoid unneccessary run of workflow --- .github/workflows/build_and_test.yml | 5 ++++ src/roxy/src/lib.rs | 1 - src/roxy/src/storage.rs | 8 +++--- src/roxy/src/write_batch.rs | 38 ---------------------------- 4 files changed, 9 insertions(+), 43 deletions(-) delete mode 100644 src/roxy/src/write_batch.rs diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 1b9c5e6..5b7a52a 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -5,6 +5,11 @@ on: branches: [ "*" ] pull_request: branches: [ "main" ] + paths: + # Run the workflow on every push to the main branch + - 'src/**' + - 'Cargo.toml' + - '.github/workflows/**' env: CARGO_TERM_COLOR: always diff --git a/src/roxy/src/lib.rs b/src/roxy/src/lib.rs index 306c340..e4de413 100644 --- a/src/roxy/src/lib.rs +++ b/src/roxy/src/lib.rs @@ -20,4 +20,3 @@ pub mod datatypes; pub mod error; pub mod metadata; pub mod storage; -pub mod write_batch; diff --git a/src/roxy/src/storage.rs b/src/roxy/src/storage.rs index d97cd1a..b3502eb 100644 --- a/src/roxy/src/storage.rs +++ b/src/roxy/src/storage.rs @@ -49,9 +49,9 @@ pub struct StorageConfig { #[serde(default)] secondary_path: String, #[serde(default)] - _open_mode: OpenMode, + open_mode: OpenMode, #[serde(default)] - _backup_path: Option, + backup_path: Option, rocksdb: RocksDBConfig, } @@ -284,8 +284,8 @@ pub fn setup_test_storage_for_ut() -> Storage { let storage_config = StorageConfig { dbpath, secondary_path, - _open_mode: OpenMode::Default, - _backup_path: None, + open_mode: OpenMode::Default, + backup_path: None, rocksdb: RocksDBConfig { block_size: 4096 }, }; let mut storage = Storage::try_new(storage_config).unwrap(); diff --git a/src/roxy/src/write_batch.rs b/src/roxy/src/write_batch.rs deleted file mode 100644 index 92fa793..0000000 --- a/src/roxy/src/write_batch.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2024 Rudeus 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. - -/// Scan the the puts and deletes of a [write batch](`rocksdb::WriteBatch`). -/// -/// The application must provide an implementation of this trait when -/// scanning the operations within a `WriteBatch` -pub trait WriteBatchScanner { - /// Called with a key and value that were `put` into the batch. - fn put(&mut self, key: Box<[u8]>, value: Box<[u8]>); - /// Called with a key that was `delete`d from the batch. - fn delete(&mut self, key: Box<[u8]>); -} - -pub struct RocksDBWriteBatchIterator<'a> { - scanner: &'a mut dyn WriteBatchScanner, -} - -impl<'a> rocksdb::WriteBatchIterator for RocksDBWriteBatchIterator<'a> { - fn put(&mut self, key: Box<[u8]>, value: Box<[u8]>) { - self.scanner.put(key, value) - } - - fn delete(&mut self, key: Box<[u8]>) { - self.scanner.delete(key) - } -}