mirror of
https://github.com/urbit/ares.git
synced 2024-11-22 06:32:47 +03:00
cargo: clippy
This commit is contained in:
parent
14d8c138d7
commit
da1cf12ff0
@ -8,7 +8,7 @@ use lmdb::{Cursor, Environment, EnvironmentFlags, Error as LmdbError, Transactio
|
|||||||
use lmdb_sys as ffi;
|
use lmdb_sys as ffi;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::result::Result as StdResult;
|
use std::result::Result as StdResult;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -48,8 +48,8 @@ impl Disk {
|
|||||||
let (_, high) = lmdb_gulf(&env);
|
let (_, high) = lmdb_gulf(&env);
|
||||||
Disk {
|
Disk {
|
||||||
dir: log_dir,
|
dir: log_dir,
|
||||||
epoch: epoch,
|
epoch,
|
||||||
env: env,
|
env,
|
||||||
done: high,
|
done: high,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ impl Disk {
|
|||||||
|
|
||||||
/// Get the number of the latest epoch in the given directory, or return
|
/// Get the number of the latest epoch in the given directory, or return
|
||||||
/// an error if there are no epochs or the path specified isn't a directory.
|
/// an error if there are no epochs or the path specified isn't a directory.
|
||||||
pub fn epoch_last(log_dir: &PathBuf) -> Result<u64> {
|
pub fn epoch_last(log_dir: &Path) -> Result<u64> {
|
||||||
if !log_dir.is_dir() {
|
if !log_dir.is_dir() {
|
||||||
return Err(Error::InvalidPath);
|
return Err(Error::InvalidPath);
|
||||||
}
|
}
|
||||||
@ -65,16 +65,14 @@ pub fn epoch_last(log_dir: &PathBuf) -> Result<u64> {
|
|||||||
let mut some = false;
|
let mut some = false;
|
||||||
let mut last = 0;
|
let mut last = 0;
|
||||||
|
|
||||||
if let Ok(entries) = fs::read_dir(log_dir.clone()) {
|
if let Ok(entries) = fs::read_dir(log_dir) {
|
||||||
for entry in entries {
|
for entry in entries.flatten() {
|
||||||
if let Ok(entry) = entry {
|
if let Some(name) = entry.file_name().to_str() {
|
||||||
if let Some(name) = entry.file_name().to_str() {
|
if let Some(epoch) = name.strip_prefix("0i") {
|
||||||
if let Some(epoch) = name.strip_prefix("0i") {
|
if let Ok(n) = epoch.parse::<u64>() {
|
||||||
if let Ok(n) = epoch.parse::<u64>() {
|
some = true;
|
||||||
some = true;
|
if n > last {
|
||||||
if n > last {
|
last = n;
|
||||||
last = n;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +89,7 @@ pub fn epoch_last(log_dir: &PathBuf) -> Result<u64> {
|
|||||||
|
|
||||||
/// Read a value from the metadata database.
|
/// Read a value from the metadata database.
|
||||||
pub fn disk_read_meta(env: &Environment, key: &str) -> Result<u64> {
|
pub fn disk_read_meta(env: &Environment, key: &str) -> Result<u64> {
|
||||||
lmdb_read_meta(env, key).map_err(|e| Error::Lmdb(e))
|
lmdb_read_meta(env, key).map_err(Error::Lmdb)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a single event `eve` from the database.
|
/// Read a single event `eve` from the database.
|
||||||
|
@ -428,7 +428,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res
|
|||||||
|
|
||||||
debug_assertions(stack, orig_subject);
|
debug_assertions(stack, orig_subject);
|
||||||
debug_assertions(stack, res);
|
debug_assertions(stack, res);
|
||||||
|
|
||||||
break Ok(res);
|
break Ok(res);
|
||||||
}
|
}
|
||||||
NockWork::Ret => {
|
NockWork::Ret => {
|
||||||
|
@ -28,7 +28,7 @@ pub fn lmdb_gulf(env: &Environment) -> (u64, u64) {
|
|||||||
let low = u64::from_le_bytes(first.try_into().unwrap());
|
let low = u64::from_le_bytes(first.try_into().unwrap());
|
||||||
if let Some(last) = cursor.get(None, None, ffi::MDB_LAST).unwrap().0 {
|
if let Some(last) = cursor.get(None, None, ffi::MDB_LAST).unwrap().0 {
|
||||||
let high = u64::from_le_bytes(last.try_into().unwrap());
|
let high = u64::from_le_bytes(last.try_into().unwrap());
|
||||||
return (low, high);
|
(low, high)
|
||||||
} else {
|
} else {
|
||||||
panic!("Couldn't get last event from the database");
|
panic!("Couldn't get last event from the database");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use ares::jets::hot::URBIT_HOT_STATE;
|
use ares::jets::hot::URBIT_HOT_STATE;
|
||||||
use ares::mars::{mars_play, Mars};
|
use ares::mars::{mars_play, Mars};
|
||||||
use ares::serf::{Context, serf};
|
use ares::serf::{serf, Context};
|
||||||
use ares::trace::{create_trace_file, write_metadata};
|
use ares::trace::{create_trace_file, write_metadata};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -56,7 +56,7 @@ fn main() -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
let mut ctx = Context::load(load_path.clone(), trace_info, URBIT_HOT_STATE);
|
let mut ctx = Context::load(load_path.clone(), trace_info, URBIT_HOT_STATE);
|
||||||
ctx.ripe();
|
ctx.ripe();
|
||||||
|
|
||||||
let sent = ctx.event_num;
|
let sent = ctx.event_num;
|
||||||
let done = sent;
|
let done = sent;
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use std::{cmp::min, path::PathBuf};
|
|
||||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||||
use std::result::Result as StdResult;
|
use std::result::Result as StdResult;
|
||||||
|
use std::{cmp::min, path::PathBuf};
|
||||||
|
|
||||||
use crate::disk::*;
|
use crate::disk::*;
|
||||||
use crate::hamt::Hamt;
|
use crate::hamt::Hamt;
|
||||||
use crate::jets::list::util::lent;
|
use crate::jets::list::util::lent;
|
||||||
use crate::lmdb::lmdb_gulf;
|
use crate::lmdb::lmdb_gulf;
|
||||||
use crate::noun::{D, Noun};
|
use crate::noun::{Noun, D};
|
||||||
use crate::persist::pma_close;
|
use crate::persist::pma_close;
|
||||||
use crate::serf::{clear_interrupt, play_life, work, Context};
|
use crate::serf::{clear_interrupt, play_life, work, Context};
|
||||||
|
|
||||||
@ -45,13 +45,12 @@ pub struct Mars {
|
|||||||
|
|
||||||
/// Last event processed.
|
/// Last event processed.
|
||||||
pub done: u64,
|
pub done: u64,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Do a boot.
|
/// Do a boot.
|
||||||
fn mars_boot(mars: &mut Mars, eve: u64) -> Result<()> {
|
fn mars_boot(mars: &mut Mars, eve: u64) -> Result<()> {
|
||||||
let ctx = &mut mars.ctx;
|
let ctx = &mut mars.ctx;
|
||||||
let seq = disk_read_list(ctx, 1, eve).unwrap(); // boot sequence
|
let seq = disk_read_list(ctx, 1, eve).unwrap(); // boot sequence
|
||||||
eprintln!("--------------- bootstrap starting ----------------\r");
|
eprintln!("--------------- bootstrap starting ----------------\r");
|
||||||
eprintln!("boot: 1-{}\r", lent(seq).unwrap());
|
eprintln!("boot: 1-{}\r", lent(seq).unwrap());
|
||||||
play_life(ctx, seq);
|
play_life(ctx, seq);
|
||||||
@ -68,7 +67,10 @@ pub fn mars_play(mut mars: Mars, mut eve: u64, _sap: u64) -> u64 {
|
|||||||
eve = mars.ctx.log.done;
|
eve = mars.ctx.log.done;
|
||||||
} else if eve <= mars.ctx.log.done {
|
} else if eve <= mars.ctx.log.done {
|
||||||
eprintln!("mars: already computed {}\r", eve);
|
eprintln!("mars: already computed {}\r", eve);
|
||||||
eprintln!(" state={}, &mut mars.log={}\r", mars.done, mars.ctx.log.done);
|
eprintln!(
|
||||||
|
" state={}, &mut mars.log={}\r",
|
||||||
|
mars.done, mars.ctx.log.done
|
||||||
|
);
|
||||||
return played;
|
return played;
|
||||||
} else {
|
} else {
|
||||||
eve = min(eve, mars.ctx.log.done);
|
eve = min(eve, mars.ctx.log.done);
|
||||||
@ -96,14 +98,19 @@ pub fn mars_play(mut mars: Mars, mut eve: u64, _sap: u64) -> u64 {
|
|||||||
if (eve + 1) == mars.ctx.log.done {
|
if (eve + 1) == mars.ctx.log.done {
|
||||||
eprintln!("play: event {}\r", mars.ctx.log.done);
|
eprintln!("play: event {}\r", mars.ctx.log.done);
|
||||||
} else if eve != mars.ctx.log.done {
|
} else if eve != mars.ctx.log.done {
|
||||||
eprintln!("play: events {}-{} of {}\r", (mars.done + 1), eve, mars.ctx.log.done);
|
eprintln!(
|
||||||
|
"play: events {}-{} of {}\r",
|
||||||
|
(mars.done + 1),
|
||||||
|
eve,
|
||||||
|
mars.ctx.log.done
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("play: events {}-{}\r", (mars.done + 1), eve);
|
eprintln!("play: events {}-{}\r", (mars.done + 1), eve);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut _past = mars.done; // XX last snapshot
|
let mut _past = mars.done; // XX last snapshot
|
||||||
let mut _meme = 0; // XX last event to bail:meme
|
let mut _meme = 0; // XX last event to bail:meme
|
||||||
let mut _shot = 0; // XX retry counter
|
let mut _shot = 0; // XX retry counter
|
||||||
|
|
||||||
while mars.done < eve {
|
while mars.done < eve {
|
||||||
match mars_play_batch(&mut mars, false, 1024) {
|
match mars_play_batch(&mut mars, false, 1024) {
|
||||||
@ -142,7 +149,7 @@ pub fn mars_play(mut mars: Mars, mut eve: u64, _sap: u64) -> u64 {
|
|||||||
played
|
played
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Play a batch of events.
|
/// Play a batch of events.
|
||||||
/// XX use `mug`, track time, and produce more errors.
|
/// XX use `mug`, track time, and produce more errors.
|
||||||
fn mars_play_batch(mars: &mut Mars, _mug: bool, bat: u64) -> Result<()> {
|
fn mars_play_batch(mars: &mut Mars, _mug: bool, bat: u64) -> Result<()> {
|
||||||
let ctx = &mut mars.ctx;
|
let ctx = &mut mars.ctx;
|
||||||
|
@ -187,7 +187,7 @@ impl Context {
|
|||||||
arvo,
|
arvo,
|
||||||
mug,
|
mug,
|
||||||
nock_context,
|
nock_context,
|
||||||
log
|
log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,7 +319,7 @@ pub fn serf(constant_hot_state: &[HotEntry]) -> io::Result<()> {
|
|||||||
.ok_or(io::Error::new(io::ErrorKind::Other, "no pier path"))?;
|
.ok_or(io::Error::new(io::ErrorKind::Other, "no pier path"))?;
|
||||||
let pier_path = PathBuf::from(pier_path_string);
|
let pier_path = PathBuf::from(pier_path_string);
|
||||||
let snap_path = pier_path.join(".urb/chk");
|
let snap_path = pier_path.join(".urb/chk");
|
||||||
create_dir_all(&snap_path)?;
|
create_dir_all(snap_path)?;
|
||||||
|
|
||||||
let wag: u32 = std::env::args()
|
let wag: u32 = std::env::args()
|
||||||
.nth(4)
|
.nth(4)
|
||||||
|
Loading…
Reference in New Issue
Block a user