mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 08:21:47 +00:00
Rapid command (run in fast but potentially unsafe LMDB syncing mode)
This commit is contained in:
parent
7aba4435b8
commit
a706fc6e3a
@ -25,7 +25,7 @@ impl Command {
|
||||
}
|
||||
}
|
||||
|
||||
const COMMANDS: [Command; 36] = [
|
||||
const COMMANDS: [Command; 37] = [
|
||||
Command {
|
||||
cmd: "oneshot",
|
||||
usage_params: "{depends}",
|
||||
@ -166,6 +166,11 @@ const COMMANDS: [Command; 36] = [
|
||||
usage_params: "<idhex>",
|
||||
desc: "print the relays the event was seen on",
|
||||
},
|
||||
Command {
|
||||
cmd: "rapid",
|
||||
usage_params: "",
|
||||
desc: "Use much faster disk access. A crash can corrupt your local data, unless your filesystem preserves write ordering",
|
||||
},
|
||||
Command {
|
||||
cmd: "rebuild_indices",
|
||||
usage_params: "",
|
||||
@ -209,7 +214,6 @@ const COMMANDS: [Command; 36] = [
|
||||
];
|
||||
|
||||
pub fn handle_command(mut args: env::Args, runtime: &Runtime) -> Result<bool, Error> {
|
||||
let _ = args.next(); // program name
|
||||
let command_string = args.next().unwrap(); // must be there or we would not have been called
|
||||
|
||||
let mut command: Option<Command> = None;
|
||||
@ -259,6 +263,7 @@ pub fn handle_command(mut args: env::Args, runtime: &Runtime) -> Result<bool, Er
|
||||
"print_relay" => print_relay(command, args)?,
|
||||
"print_relays" => print_relays(command)?,
|
||||
"print_seen_on" => print_seen_on(command, args)?,
|
||||
"rapid" => {} // is handled early in main.rs
|
||||
"rebuild_indices" => rebuild_indices()?,
|
||||
"rename_person_list" => rename_person_list(command, args)?,
|
||||
"reprocess_recent" => reprocess_recent(command, runtime)?,
|
||||
|
@ -43,8 +43,27 @@ fn main() -> Result<(), Error> {
|
||||
let about = about::About::new();
|
||||
println!("Gossip {}", about.version);
|
||||
|
||||
// Handle rapid command before initializing the lib
|
||||
let mut rapid: bool = false;
|
||||
{
|
||||
let mut args = env::args();
|
||||
let _ = args.next(); // program name
|
||||
if let Some(cmd) = args.next() {
|
||||
if &*cmd == "rapid" {
|
||||
rapid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// restart args
|
||||
let mut args = env::args();
|
||||
let _ = args.next(); // program name
|
||||
if rapid {
|
||||
let _ = args.next(); // rapid param
|
||||
}
|
||||
|
||||
// Initialize the lib
|
||||
gossip_lib::init()?;
|
||||
gossip_lib::init(rapid)?;
|
||||
|
||||
// Setup async
|
||||
// We create and enter the runtime on the main thread so that
|
||||
@ -54,8 +73,7 @@ fn main() -> Result<(), Error> {
|
||||
let _main_rt = rt.enter(); // <-- this allows it.
|
||||
|
||||
// If we were handed a command, execute the command and return
|
||||
let args = env::args();
|
||||
if args.len() > 1 {
|
||||
if args.len() > 0 {
|
||||
match commands::handle_command(args, &rt) {
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
|
@ -198,11 +198,11 @@ impl std::convert::TryFrom<u8> for RunState {
|
||||
}
|
||||
|
||||
/// Initialize gossip-lib
|
||||
pub fn init() -> Result<(), Error> {
|
||||
pub fn init(rapid: bool) -> Result<(), Error> {
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
// Initialize storage
|
||||
GLOBALS.storage.init()?;
|
||||
GLOBALS.storage.init(rapid)?;
|
||||
|
||||
// Load signer from settings
|
||||
GLOBALS.identity.load()?;
|
||||
|
@ -94,13 +94,26 @@ impl Storage {
|
||||
|
||||
/// Run this after GLOBALS lazy static initialisation, so functions within storage can
|
||||
/// access GLOBALS without hanging.
|
||||
pub fn init(&self) -> Result<(), Error> {
|
||||
pub fn init(&self, rapid: bool) -> Result<(), Error> {
|
||||
let mut builder = EnvOpenOptions::new();
|
||||
|
||||
let flags = if rapid {
|
||||
tracing::warn!("Storage using rapid config - data corruption is possible on crash");
|
||||
EnvFlags::NO_TLS
|
||||
| EnvFlags::NO_META_SYNC
|
||||
| EnvFlags::WRITE_MAP
|
||||
| EnvFlags::NO_SYNC
|
||||
| EnvFlags::MAP_ASYNC
|
||||
} else {
|
||||
EnvFlags::NO_TLS | EnvFlags::NO_META_SYNC
|
||||
};
|
||||
|
||||
unsafe {
|
||||
builder.flags(EnvFlags::NO_TLS | EnvFlags::NO_META_SYNC);
|
||||
builder.flags(flags);
|
||||
// See flats at http://www.lmdb.tech/doc/group__mdb__env.html
|
||||
// See flags at http://www.lmdb.tech/doc/group__mdb.html (more detail)
|
||||
}
|
||||
|
||||
// builder.max_readers(126); // this is the default
|
||||
builder.max_dbs(32);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user