Skip to content

Commit

Permalink
add migrate sub command (#121)
Browse files Browse the repository at this point in the history
* add migrate sub command

---------

Co-authored-by: Cyberaurora <[email protected]>
  • Loading branch information
kb1ns and kb1ns authored Nov 14, 2023
1 parent e876b7a commit 2faac59
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 236 deletions.
136 changes: 6 additions & 130 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ members = [
"sidecar",
"bin",
]
resolver = "2"
3 changes: 2 additions & 1 deletion bin/src/galois.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ fn main() {
env_logger::init();
let opts = config::GaloisCli::parse();
match opts.sub {
Some(config::SubCmd::EncryptConfig) => config::print_config(&opts.file).unwrap(),
Some(config::SubCmd::Encrypt) => config::print_config(&opts.file).unwrap(),
Some(config::SubCmd::Migrate(c)) => migration::migrate(c),
None => {
print_banner();
lazy_static::initialize(&C);
Expand Down
8 changes: 4 additions & 4 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ repository = "https://github.com/uinb/galois"
description = "High performance matching system"

[features]
v1-to-v2 = []
default = []
v1-to-v2 = ["sqlx"]

[dependencies]
rust_decimal = { version = "1.22", features = ["serde-bincode"] }
Expand All @@ -19,8 +20,7 @@ async-trait = "0.1.63"
serde_json = "1.0"
rocksdb = "0.21"
flate2 = { version = "1.0", features = ["zlib"], default-features = false }
# mysql = "23.0"
# redis = { version = "0.17", features = ["tls", "tokio-rt-core", "tokio-tls-comp", "native-tls","async-native-tls", "async-std-tls-comp"] }
sqlx = { version = "0.6.2", features = ["mysql", "decimal", "chrono"], optional = true }
toml = "0.5"
lazy_static = "1.4"
linked-hash-map = { version = "0.5.3", features = ["serde_impl"] }
Expand All @@ -30,7 +30,7 @@ chashmap = "2.2"
syn = "1.0.107"
lz4_flex = "0.10.0"
log = { version = "0.4", features = ["serde"] }
log4rs = { version = "1.0", features = ["json_encoder", "toml_format"] }
env_logger = "0.10.1"
chrono = "0.4"
magic-crypt = "3.1"
anyhow = "1"
Expand Down
63 changes: 35 additions & 28 deletions engine/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use clap::Parser;
use serde::{Deserialize, Serialize};

#[derive(Debug, Parser)]
#[command(author, version)]
#[command(author = "UINB Tech", version)]
pub struct GaloisCli {
#[arg(short('c'), long("config"), required = true, value_name = "FILE")]
pub file: std::path::PathBuf,
Expand All @@ -29,27 +29,56 @@ pub struct GaloisCli {
}

#[derive(Debug, clap::Subcommand)]
#[command(version)]
pub enum SubCmd {
EncryptConfig,
#[clap(
name = "encrypt",
about = "Encrypt config file using environment variable MAGIC_KEY as the key"
)]
Encrypt,
#[clap(
name = "migrate",
about = "Migrate coredump file and sequence storages"
)]
Migrate(MigrateCmd),
}

#[derive(Debug, clap::Args)]
#[command(version)]
pub struct RunCmd {
#[arg(
long,
value_name = "EVENT-ID",
help = "Run galois in `dry-run` mode, skipping all output."
value_name = "EVENT_ID",
help = "Run galois in `dry-run` mode, skipping all outputs."
)]
dry_run: Option<u64>,
}

#[derive(Debug, clap::Args)]
pub struct MigrateCmd {
#[arg(
long,
short = 'o',
value_name = "PATH",
help = "The new coredump file path"
)]
pub output_path: String,
#[arg(
long,
short = 'i',
value_name = "PATH",
help = "The old coredump file path"
)]
pub input_path: String,
#[arg(long, action=clap::ArgAction::SetFalse, help = "Migrate coredump file only if set")]
pub core_only: bool,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Config {
pub server: ServerConfig,
pub sequence: SequenceConfig,
pub fusotao: FusotaoConfig,
#[cfg(feature = "v1-to-v2")]
pub mysql: MysqlConfig,
#[serde(skip_serializing)]
pub dry_run: Option<u64>,
}
Expand Down Expand Up @@ -213,25 +242,3 @@ fn init_config(toml: &str, key: Option<String>) -> anyhow::Result<Config> {
}
Ok(cfg)
}

#[test]
pub fn test_config() {
let toml = r#"
[server]
bind_addr = "127.0.0.1:8097"
data_home = "/tmp/galois"
[sequence]
checkpoint = 100000
enable_from_genesis = true
[fusotao]
node_url = "ws://localhost:9944"
key_seed = "//Alice"
x25519_priv = "0xedcff0c69e4c0fa7e9a36e2e6d07f2cc355c8d25907a0ad2ab7e03b24f8e90f3"
proof_batch_limit = 20
claim_block = 1
"#;
let config = init_config(&toml, None);
assert!(config.is_ok());
}
Loading

0 comments on commit 2faac59

Please sign in to comment.