MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / repair

Method repair

libatomic/src/daemon/services_maintenance.rs:60–194  ·  view source on GitHub ↗
(
        &self,
        request: Request<RepairRequest>,
    )

Source from the content-addressed store, hash-verified

58 }
59
60 async fn repair(
61 &self,
62 request: Request<RepairRequest>,
63 ) -> Result<Response<RepairResponse>, Status> {
64 let request = request.into_inner();
65 let handle = self
66 .state
67 .resolve(request.repository.as_ref().unwrap_or(&default_ref()))?;
68 self.state.log_rpc("Repair", Some(&handle));
69 let action = repair_action(request.action)?;
70 let force = request.force;
71 let view = request.view;
72 let gate = handle.exclusive_owned().await;
73 let result = tokio::task::spawn_blocking(move || -> Result<RepairResponse, Status> {
74 let _gate = gate;
75 if action == RepairAction::RebuildNativeIndexes {
76 // Even opening a writable redb handle can truncate unused tail
77 // pages on close. Refuse missing/corrupt authority before that
78 // open, rather than treating "no committed repair" as read-only.
79 let report = handle
80 .native_index_repository(true)?
81 .verify_native_derived_indexes()
82 .map_err(repository_error)?;
83 if let Some(problem) = report.problems.iter().find(|problem| {
84 problem.kind == atomic_repository::NativeIndexProblemKind::Unrepairable
85 }) {
86 return Err(Status::failed_precondition(format!(
87 "Native derived indexes are unrepairable: {problem}"
88 )));
89 }
90 if report.is_healthy() {
91 return Ok(RepairResponse {
92 native_already_healthy: true,
93 native_rows_written: report.expected_rows as u64,
94 ..Default::default()
95 });
96 }
97 let repo = handle.native_index_repository(false)?;
98 let outcome = repo.repair_native_derived_indexes().map_err(|error| {
99 Status::failed_precondition(format!(
100 "Native derived indexes are unrepairable: {error}"
101 ))
102 })?;
103 return Ok(RepairResponse {
104 repaired: outcome.problems_repaired as u64,
105 native_already_healthy: outcome.already_healthy,
106 native_rows_written: outcome.rows_written as u64,
107 native_problems_repaired: outcome.problems_repaired as u64,
108 native_operation: outcome.operation.map(|operation| operation.to_string()),
109 ..Default::default()
110 });
111 }
112 let mut repo = handle.repository()?;
113 match action {
114 RepairAction::RebuildDependencyIndex => {
115 let (indexed, skipped, failed) = repo
116 .repair_change_dependency_index(force)
117 .map_err(repository_error)?;

Callers

nothing calls this directly

Calls 15

default_refFunction · 0.85
repair_actionFunction · 0.85
domain_statusFunction · 0.85
as_refMethod · 0.80
log_rpcMethod · 0.80
exclusive_ownedMethod · 0.80
repositoryMethod · 0.80

Tested by

no test coverage detected