Skip to main content

shardline_rebuild/
lib.rs

1#![deny(unsafe_code)]
2#![cfg_attr(
3    test,
4    allow(
5        clippy::unwrap_used,
6        clippy::expect_used,
7        clippy::indexing_slicing,
8        clippy::shadow_unrelated,
9        clippy::let_underscore_must_use,
10        clippy::format_push_string
11    )
12)]
13
14//! Index rebuild logic for the Shardline server ecosystem.
15//!
16//! This crate provides pure rebuild functions that operate on explicit
17//! store parameters rather than server configuration.
18//!
19//! # Quick start
20//!
21//! The issue and report types are pure data that describe what a rebuild
22//! found and fixed:
23//!
24//! ```
25//! use shardline_rebuild::{
26//!     IndexRebuildIssue, IndexRebuildIssueDetail, IndexRebuildIssueKind,
27//!     IndexRebuildReport,
28//! };
29//!
30//! let issue = IndexRebuildIssue {
31//!     kind: IndexRebuildIssueKind::InvalidVersionRecordJson,
32//!     location: "records/latest/acme-assets.json".to_owned(),
33//!     detail: IndexRebuildIssueDetail::RecordJsonInvalid,
34//! };
35//! assert_eq!(issue.kind.as_str(), "invalid_version_record_json");
36//!
37//! let report = IndexRebuildReport {
38//!     scanned_version_records: 120,
39//!     scanned_retained_shards: 4,
40//!     rebuilt_latest_records: 1,
41//!     unchanged_latest_records: 119,
42//!     removed_stale_latest_records: 0,
43//!     scanned_reconstructions: 4,
44//!     unchanged_reconstructions: 4,
45//!     removed_stale_reconstructions: 0,
46//!     rebuilt_dedupe_shard_mappings: 0,
47//!     unchanged_dedupe_shard_mappings: 0,
48//!     removed_stale_dedupe_shard_mappings: 0,
49//!     preserved_latest_records_unreadable_version: Vec::new(),
50//!     issues: vec![issue],
51//! };
52//! assert!(!report.is_clean());
53//! assert_eq!(report.issue_count(), 1);
54//! ```
55//!
56//! To run a real rebuild, use [`run_index_rebuild_with_stores`] with explicit
57//! record, index, and object-store adapters.
58
59mod candidates;
60mod error;
61mod report;
62mod runner;
63mod types;
64
65// Crate-internal re-exports needed by sibling production modules.
66pub(crate) use candidates::{VersionCandidate, collect_candidate};
67pub(crate) use report::push_issue;
68
69// Re-exports needed only by integration tests (these are pub(super) in their
70// original modules and are brought into crate-root scope for `use super::*`).
71#[cfg(test)]
72pub(crate) use runner::{
73    desired_reconstruction_file_ids, prune_stale_reconstructions, rebuild_dedupe_shard_mappings,
74};
75
76// Public API re-exports.
77pub use error::RebuildError;
78pub use report::IndexRebuildReport;
79pub use runner::run_index_rebuild_with_stores;
80pub use types::{
81    IndexRebuildIssue, IndexRebuildIssueDetail, IndexRebuildIssueKind,
82    IndexRebuildReconstructionPlanDetail, LocalIndexRebuildIssue, LocalIndexRebuildIssueKind,
83    LocalIndexRebuildReport,
84};
85
86#[cfg(test)]
87mod tests;