mirror of
https://github.com/urbit/ares.git
synced 2024-11-25 05:03:19 +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 std::convert::TryInto;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::result::Result as StdResult;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -48,8 +48,8 @@ impl Disk {
|
||||
let (_, high) = lmdb_gulf(&env);
|
||||
Disk {
|
||||
dir: log_dir,
|
||||
epoch: epoch,
|
||||
env: env,
|
||||
epoch,
|
||||
env,
|
||||
done: high,
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,7 @@ impl Disk {
|
||||
|
||||
/// 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.
|
||||
pub fn epoch_last(log_dir: &PathBuf) -> Result<u64> {
|
||||
pub fn epoch_last(log_dir: &Path) -> Result<u64> {
|
||||
if !log_dir.is_dir() {
|
||||
return Err(Error::InvalidPath);
|
||||
}
|
||||
@ -65,16 +65,14 @@ pub fn epoch_last(log_dir: &PathBuf) -> Result<u64> {
|
||||
let mut some = false;
|
||||
let mut last = 0;
|
||||
|
||||
if let Ok(entries) = fs::read_dir(log_dir.clone()) {
|
||||
for entry in entries {
|
||||
if let Ok(entry) = entry {
|
||||
if let Some(name) = entry.file_name().to_str() {
|
||||
if let Some(epoch) = name.strip_prefix("0i") {
|
||||
if let Ok(n) = epoch.parse::<u64>() {
|
||||
some = true;
|
||||
if n > last {
|
||||
last = n;
|
||||
}
|
||||
if let Ok(entries) = fs::read_dir(log_dir) {
|
||||
for entry in entries.flatten() {
|
||||
if let Some(name) = entry.file_name().to_str() {
|
||||
if let Some(epoch) = name.strip_prefix("0i") {
|
||||
if let Ok(n) = epoch.parse::<u64>() {
|
||||
some = true;
|
||||
if n > last {
|
||||
last = n;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,7 +89,7 @@ pub fn epoch_last(log_dir: &PathBuf) -> Result<u64> {
|
||||
|
||||
/// Read a value from the metadata database.
|
||||
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.
|
||||
|
@ -428,7 +428,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res
|
||||
|
||||
debug_assertions(stack, orig_subject);
|
||||
debug_assertions(stack, res);
|
||||
|
||||
|
||||
break Ok(res);
|
||||
}
|
||||
NockWork::Ret => {
|
||||
|
@ -28,7 +28,7 @@ pub fn lmdb_gulf(env: &Environment) -> (u64, u64) {
|
||||
let low = u64::from_le_bytes(first.try_into().unwrap());
|
||||
if let Some(last) = cursor.get(None, None, ffi::MDB_LAST).unwrap().0 {
|
||||
let high = u64::from_le_bytes(last.try_into().unwrap());
|
||||
return (low, high);
|
||||
(low, high)
|
||||
} else {
|
||||
panic!("Couldn't get last event from the database");
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use ares::jets::hot::URBIT_HOT_STATE;
|
||||
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 std::env;
|
||||
use std::io;
|
||||
@ -56,7 +56,7 @@ fn main() -> io::Result<()> {
|
||||
}
|
||||
let mut ctx = Context::load(load_path.clone(), trace_info, URBIT_HOT_STATE);
|
||||
ctx.ripe();
|
||||
|
||||
|
||||
let sent = ctx.event_num;
|
||||
let done = sent;
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
use std::{cmp::min, path::PathBuf};
|
||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||
use std::result::Result as StdResult;
|
||||
use std::{cmp::min, path::PathBuf};
|
||||
|
||||
use crate::disk::*;
|
||||
use crate::hamt::Hamt;
|
||||
use crate::jets::list::util::lent;
|
||||
use crate::lmdb::lmdb_gulf;
|
||||
use crate::noun::{D, Noun};
|
||||
use crate::noun::{Noun, D};
|
||||
use crate::persist::pma_close;
|
||||
use crate::serf::{clear_interrupt, play_life, work, Context};
|
||||
|
||||
@ -45,13 +45,12 @@ pub struct Mars {
|
||||
|
||||
/// Last event processed.
|
||||
pub done: u64,
|
||||
|
||||
}
|
||||
|
||||
/// Do a boot.
|
||||
fn mars_boot(mars: &mut Mars, eve: u64) -> Result<()> {
|
||||
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!("boot: 1-{}\r", lent(seq).unwrap());
|
||||
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;
|
||||
} else if eve <= mars.ctx.log.done {
|
||||
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;
|
||||
} else {
|
||||
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 {
|
||||
eprintln!("play: event {}\r", 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 {
|
||||
eprintln!("play: events {}-{}\r", (mars.done + 1), eve);
|
||||
}
|
||||
|
||||
let mut _past = mars.done; // XX last snapshot
|
||||
let mut _meme = 0; // XX last event to bail:meme
|
||||
let mut _shot = 0; // XX retry counter
|
||||
let mut _past = mars.done; // XX last snapshot
|
||||
let mut _meme = 0; // XX last event to bail:meme
|
||||
let mut _shot = 0; // XX retry counter
|
||||
|
||||
while mars.done < eve {
|
||||
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
|
||||
}
|
||||
|
||||
/// Play a batch of events.
|
||||
/// Play a batch of events.
|
||||
/// XX use `mug`, track time, and produce more errors.
|
||||
fn mars_play_batch(mars: &mut Mars, _mug: bool, bat: u64) -> Result<()> {
|
||||
let ctx = &mut mars.ctx;
|
||||
|
@ -187,7 +187,7 @@ impl Context {
|
||||
arvo,
|
||||
mug,
|
||||
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"))?;
|
||||
let pier_path = PathBuf::from(pier_path_string);
|
||||
let snap_path = pier_path.join(".urb/chk");
|
||||
create_dir_all(&snap_path)?;
|
||||
create_dir_all(snap_path)?;
|
||||
|
||||
let wag: u32 = std::env::args()
|
||||
.nth(4)
|
||||
|
Loading…
Reference in New Issue
Block a user