20260723 修复 explorer 新发布对象 parsed 不可用(#128 M8):repo-bytes.db 只读打开冻结于启动时刻,watch 模式改用 rocksdb secondary 并在 watcher 循环周期 catch-up;blob_store 新增 open_as_secondary/try_catch_up_with_primary 及 live primary 场景单测

This commit is contained in:
2026-07-24 11:15:16 +08:00
parent b5c033426e
commit 001f13209f
2 changed files with 111 additions and 3 deletions

View File

@@ -150,9 +150,20 @@ fn real_main() -> Result<(), String> {
let db = Arc::new(open_query_db_for_service(&args).map_err(|e| e.to_string())?);
let export_jobs = Arc::new(Mutex::new(BTreeMap::new()));
let repo_bytes = match args.repo_bytes_db.as_ref() {
Some(path) => Some(Arc::new(
ExternalRepoBytesDb::open_read_only(path).map_err(|e| e.to_string())?,
)),
Some(path) => {
let opened = if args.watch_run_root.is_some() {
// Watch mode tracks a live soak that keeps writing new object
// bytes. A plain read-only open is frozen at open time (new
// manifests/CRLs/objects become unparsable until restart), so
// use a secondary instance and catch up in the watcher loop.
let secondary_path = args.query_db.with_extension("repo-bytes.secondary");
ExternalRepoBytesDb::open_as_secondary(path, &secondary_path)
.map_err(|e| e.to_string())?
} else {
ExternalRepoBytesDb::open_read_only(path).map_err(|e| e.to_string())?
};
Some(Arc::new(opened))
}
None => None,
};
if let Some(run_root) = args.watch_run_root.clone() {
@@ -163,6 +174,7 @@ fn real_main() -> Result<(), String> {
)?;
spawn_indexer_watcher(
Arc::clone(&db),
repo_bytes.clone(),
args.query_db.clone(),
resolve_indexer_bin(args.indexer_bin.clone())?,
run_root,
@@ -229,6 +241,7 @@ fn resolve_effective_watch_min_run_seq(
fn spawn_indexer_watcher(
db: Arc<QueryDb>,
repo_bytes: Option<Arc<ExternalRepoBytesDb>>,
query_db_path: PathBuf,
indexer_bin: PathBuf,
run_root: PathBuf,
@@ -250,6 +263,9 @@ fn spawn_indexer_watcher(
) {
Ok(message) => {
let _ = db.try_catch_up_with_primary();
if let Some(repo_bytes) = repo_bytes.as_ref() {
let _ = repo_bytes.try_catch_up_with_primary();
}
eprintln!("query watcher indexed {}: {message}", run_dir.display());
}
Err(err) => eprintln!(
@@ -260,6 +276,9 @@ fn spawn_indexer_watcher(
}
Ok(None) => {
let _ = db.try_catch_up_with_primary();
if let Some(repo_bytes) = repo_bytes.as_ref() {
let _ = repo_bytes.try_catch_up_with_primary();
}
}
Err(err) => eprintln!("query watcher index failed: {err}"),
}