Skip to content

Commit

Permalink
patch load single archive
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Dec 5, 2024
1 parent 65f530e commit 2144746
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
9 changes: 6 additions & 3 deletions src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
scan::{ArchiveMap, ManifestInfo},
};

use anyhow::{Context, Result};
use log::{info, warn};
use anyhow::{bail, Context, Result};
use log::{error, info, warn};
use neo4rs::Graph;

/// takes all the archives from a map, and tries to load them sequentially
Expand Down Expand Up @@ -74,7 +74,10 @@ pub async fn try_load_one_archive(
crate::scan::BundleContent::Unknown => todo!(),
crate::scan::BundleContent::StateSnapshot => {
let snaps = match man.version {
crate::scan::FrameworkVersion::Unknown => todo!(),
crate::scan::FrameworkVersion::Unknown => {
error!("no framework version detected");
bail!("could not load archive from manifest");
}
crate::scan::FrameworkVersion::V5 => extract_v5_snapshot(&man.archive_dir).await?,
crate::scan::FrameworkVersion::V6 => {
extract_current_snapshot(&man.archive_dir).await?
Expand Down
12 changes: 10 additions & 2 deletions src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ impl ManifestInfo {
match self.contents {
BundleContent::Unknown => return FrameworkVersion::Unknown,
BundleContent::StateSnapshot => {
let man_path = self.archive_dir.join(self.contents.filename());
dbg!(&man_path);

// first check if the v7 manifest will parse
if load_snapshot_manifest(&self.archive_dir).is_ok() {
if let Ok(_bak) = load_snapshot_manifest(&man_path) {
self.version = FrameworkVersion::V7;
}
};

if v5_read_from_snapshot_manifest(&self.archive_dir).is_ok() {
self.version = FrameworkVersion::V5;
Expand Down Expand Up @@ -98,22 +101,27 @@ pub fn scan_dir_archive(
) -> Result<ArchiveMap> {
let path = parent_dir.canonicalize()?;
let filename = content_opt.unwrap_or(BundleContent::Unknown).filename();
dbg!(&filename);
let pattern = format!(
"{}/**/{}",
path.to_str().context("cannot parse starting dir")?,
filename,
);

dbg!(&pattern);

let mut archive = BTreeMap::new();

for entry in glob(&pattern)? {
dbg!(&entry);
match entry {
Ok(manifest_path) => {
let dir = manifest_path
.parent()
.context("no parent dir found")?
.to_owned();
let contents = test_content(&manifest_path);
dbg!(&contents);
let archive_id = dir.file_name().unwrap().to_str().unwrap().to_owned();
let mut m = ManifestInfo {
archive_dir: dir.clone(),
Expand Down
34 changes: 15 additions & 19 deletions src/warehouse_cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Result};
use clap::{Parser, Subcommand};
use log::{info, warn};
use log::{error, info, warn};
use neo4rs::Graph;
use serde_json::json;
use std::path::PathBuf;
Expand Down Expand Up @@ -129,29 +129,25 @@ impl WarehouseCli {
Sub::LoadOne {
archive_dir,
batch_size,
} => match scan_dir_archive(archive_dir, None)?.0.get(archive_dir) {
Some(man) => {
} => {
let am = scan_dir_archive(archive_dir, None)?;
if am.0.is_empty() {
error!("cannot find .manifest file under {}", archive_dir.display());
}
for (_p, man) in am.0 {
let pool = try_db_connection_pool(self).await?;
neo4j_init::maybe_create_indexes(&pool).await?;

try_load_one_archive(man, &pool, batch_size.unwrap_or(250)).await?;
}
None => {
bail!(format!(
"ERROR: cannot find .manifest file under {}",
archive_dir.display()
));
try_load_one_archive(&man, &pool, batch_size.unwrap_or(250)).await?;
}
},
}
Sub::Check { archive_dir } => {
match scan_dir_archive(archive_dir, None)?.0.get(archive_dir) {
Some(_) => todo!(),
None => {
bail!(format!(
"ERROR: cannot find .manifest file under {}",
archive_dir.display()
));
}
let am = scan_dir_archive(archive_dir, None)?;
if am.0.is_empty() {
error!("cannot find .manifest file under {}", archive_dir.display());
}
for (p, man) in am.0 {
info!("manifest found at {} \n {:?}", p.display(), man);
}
}
Sub::EnrichExchange {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_load_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn test_snapshot_batch() -> anyhow::Result<()> {
libra_forensic_db::log_setup();
let archive_path = v7_state_manifest_fixtures_path();
assert!(archive_path.exists());
let vec_snap = extract_current_snapshot(&archive_path ).await?;
let vec_snap = extract_current_snapshot(&archive_path).await?;

let c = start_neo4j_container();
let port = c.get_host_port_ipv4(7687);
Expand Down

0 comments on commit 2144746

Please sign in to comment.