Upgrading clap version to 4.x for sky-migrate (#285)

next
Sanjay Sharma 2 years ago committed by GitHub
parent b3bc07fd49
commit 77b2b25322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

10
Cargo.lock generated

@ -263,9 +263,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.0.17"
version = "4.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06badb543e734a2d6568e19a40af66ed5364360b9226184926f89d229b4b4267"
checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b"
dependencies = [
"atty",
"bitflags",
@ -278,9 +278,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.0.13"
version = "4.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad"
checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3"
dependencies = [
"heck",
"proc-macro-error",
@ -1357,7 +1357,7 @@ name = "sky-migrate"
version = "0.8.0"
dependencies = [
"bincode",
"clap 2.34.0",
"clap 4.0.18",
"env_logger",
"log",
"skytable 0.8.0 (git+https://github.com/skytable/client-rust.git)",

@ -3,6 +3,7 @@ name = "sky-migrate"
version = "0.8.0"
authors = ["Sayan Nandan <nandansayan@outlook.com>"]
edition = "2021"
description = "The Skytable migration tool allows users coming from older versions (>=0.8.0) to upgrade their datasets to the latest Skytable version. This tool currently supports versions >= 0.8.0 and upgrading it to 0.7.0."
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -11,4 +12,4 @@ skytable = { git = "https://github.com/skytable/client-rust.git" }
env_logger = "0.9.1"
bincode = "1.3.3"
log = "0.4.17"
clap = { version = "2", features = ["yaml"] }
clap = { version = "4", features = ["derive"] }

@ -1,9 +1,24 @@
# Skytable migration tool
The Skytable migration tool can be used to perform migrations between database versions. The basic idea is:
"read all data from the older machine and send it over to the newer one."
## Introduction
For migrating versions from 0.6 to 0.7, the database administrator has to launch the tool in the old data directory of the old instance and then pass the new instance host/port information. The tool will then read the data from the directory (this was possible because 0.6 used a very simple disk format than newer versions). This approach however has the advantage of not having to start the database server for the migration to happen.
The Skytable migration tool can be used to perform migrations between database versions. The basic
idea is: "read all data from the older machine and send it over to the newer one".
For migrating versions from 0.6 to 0.7, the database administrator has to launch the tool in the
old data directory of the old instance and then pass the new instance host/port information. The
tool will then read the data from the directory (this was possible because 0.6 used a very simple
disk format than newer versions). This approach however has the advantage of not having to start
the database server for the migration to happen.
## How To Use
To upgrade, one needs to simply run:
```shell
# Here `<lastpath>` is the path to the last installation's data directory and
# `<host>` and `<port>` is the hostname and port for the new server instance
sky-migrate --prevdir <lastpath> --new <host>:<port>
```
## License

@ -0,0 +1,36 @@
use clap::Parser;
const HELP_TEMPLATE: &'static str = r#"
{before-help}{name} {version}
{author-with-newline}{about-with-newline}
{usage-heading} {usage}
{all-args}{after-help}
"#;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about=None, help_template=HELP_TEMPLATE)]
pub struct Cli {
#[arg(
short = 'n',
long = "new",
help = "The <host>:<port> combo for the new instance",
value_name = "HOST:PORT"
)]
pub new: String,
#[arg(
short = 'p',
long = "prevdir",
help = "Path to the previous installation location",
value_name = "PREVDIR"
)]
pub prevdir: String,
#[arg(
short = 's',
long,
help = "Transfer entries one-by-one instead of all at once to save memory"
)]
pub serial: bool,
}

@ -1,30 +0,0 @@
name: Skytable Migration Tool
version: 0.7.0
author: Sayan N. <ohsayan@outlook.com>
about: |
The Skytable migration tool allows users coming from older versions (>=0.8.0)
to upgrade their datasets to the latest Skytable version. This tool currently
supports versions >= 0.8.0 and upgrading it to 0.7.0. To upgrade, on needs
to simply run:
sky-migrate --prevdir <lastpath> --new <host>:<port>
Where `<lastpath>` is the path to the last installation's data directory and
`<host>` and `<port>` is the hostname and port for the new server instance
args:
- new:
long: new
takes_value: true
required: true
help: The <host>:<port> combo for the new instance
value_name: new
- prevdir:
long: prevdir
takes_value: true
required: true
help: Path to the previous installation location
value_name: prevdir
- serial:
long: serial
takes_value: false
required: false
help: |
Transfer entries one-by-one instead of all at once to save memory

@ -26,30 +26,27 @@
#![allow(clippy::unit_arg)]
mod cli;
use {
clap::{load_yaml, App},
core::hint::unreachable_unchecked,
crate::cli::Cli,
clap::Parser,
env_logger::Builder,
log::{error as err, info},
skytable::{query, sync::Connection, Element, Query, RespCode},
std::{collections::HashMap, env, fs, path::PathBuf, process},
std::{collections::HashMap, env, fs, process},
};
type Bytes = Vec<u8>;
fn main() {
// first evaluate config
let cfg_layout = load_yaml!("cli.yml");
let matches = App::from_yaml(cfg_layout).get_matches();
let cli = Cli::parse();
Builder::new()
.parse_filters(&env::var("SKY_LOG").unwrap_or_else(|_| "info".to_owned()))
.init();
let new_host = matches
.value_of("new")
.map(|v| v.to_string())
.unwrap_or_else(|| unsafe { unreachable_unchecked() });
let serial = matches.is_present("serial");
let hostsplit: Vec<&str> = new_host.split(':').collect();
let serial = cli.serial;
let hostsplit: Vec<&str> = cli.new.split(':').collect();
if hostsplit.len() != 2 {
err(err!("Bad value for --new"));
}
@ -58,11 +55,8 @@ fn main() {
Ok(p) => p,
Err(e) => err(err!("Bad value for port in --new: {}", e)),
};
let mut old_dir = matches
.value_of("prevdir")
.map(PathBuf::from)
.unwrap_or_else(|| unsafe { unreachable_unchecked() });
old_dir.push("data.bin");
let mut old_dir = cli.prevdir;
old_dir.push_str("data.bin");
// now connect
let mut con = match Connection::new(host, port) {
Ok(con) => con,

Loading…
Cancel
Save