···1use crate::db::types::TrimmedDid;
2-use crate::db::{self, deser_repo_state, ser_repo_state};
3use crate::state::AppState;
4use crate::types::{RepoStatus, ResyncState};
5use miette::{IntoDiagnostic, Result};
···28 // move back to pending
29 let mut batch = state.db.inner.batch();
30 batch.remove(&state.db.resync, key.clone());
31- batch.insert(
32- &state.db.pending,
33- crate::db::keys::pending_key(&did),
34- Vec::new(),
35- );
3637 // update repo state back to backfilling
38- let repo_key = crate::db::keys::repo_key(&did);
39- if let Some(state_bytes) = state.db.repos.get(&repo_key).into_diagnostic()? {
40 let mut repo_state = deser_repo_state(&state_bytes)?;
41 repo_state.status = RepoStatus::Backfilling;
42- batch.insert(&state.db.repos, &repo_key, ser_repo_state(&repo_state)?);
43 }
4445 state.db.update_count("resync", -1);
···9192 // move back to pending
93 state.db.update_count("pending", 1);
94- if let Err(e) = db
95- .pending
96- .insert(crate::db::keys::pending_key(&did), Vec::new())
97- {
98 error!("failed to move {did} to pending: {e}");
99 db::check_poisoned(&e);
100 continue;
···1use crate::db::types::TrimmedDid;
2+use crate::db::{self, deser_repo_state, keys, ser_repo_state};
3use crate::state::AppState;
4use crate::types::{RepoStatus, ResyncState};
5use miette::{IntoDiagnostic, Result};
···28 // move back to pending
29 let mut batch = state.db.inner.batch();
30 batch.remove(&state.db.resync, key.clone());
31+ batch.insert(&state.db.pending, key.clone(), Vec::new());
00003233 // update repo state back to backfilling
34+ if let Some(state_bytes) = state.db.repos.get(&key).into_diagnostic()? {
035 let mut repo_state = deser_repo_state(&state_bytes)?;
36 repo_state.status = RepoStatus::Backfilling;
37+ batch.insert(&state.db.repos, key, ser_repo_state(&repo_state)?);
38 }
3940 state.db.update_count("resync", -1);
···8687 // move back to pending
88 state.db.update_count("pending", 1);
89+ if let Err(e) = db.pending.insert(keys::repo_key(&did), Vec::new()) {
00090 error!("failed to move {did} to pending: {e}");
91 db::check_poisoned(&e);
92 continue;
+6-16
src/backfill/mod.rs
···126127 let mut spawned = 0;
128129- // limit the number of active tasks based on adaptive limit
130- // we iterate in reverse to prioritize newer items (LIFO)
131- // effective key comparison: {timestamp}|{did}
132- // older timestamps are smaller, newer are larger.
133- // rev() starts from largest (newest).
134- for guard in self.state.db.pending.iter().rev() {
135 if self.in_flight.len() >= limiter.current_limit {
136 break;
137 }
···145 }
146 };
147148- let did = if key.len() > 9 && key[8] == keys::SEP {
149- match TrimmedDid::try_from(&key[9..]) {
150- Ok(d) => d.to_did(),
151- Err(e) => {
152- error!("invalid did '{key:?}' in pending: {e}");
153- continue;
154- }
155 }
156- } else {
157- error!("invalid did '{key:?}' in pending");
158- continue;
159 };
160161 if self.in_flight.contains_sync(&did) {
···126127 let mut spawned = 0;
128129+ for guard in self.state.db.pending.iter() {
00000130 if self.in_flight.len() >= limiter.current_limit {
131 break;
132 }
···140 }
141 };
142143+ let did = match TrimmedDid::try_from(key.as_ref()) {
144+ Ok(d) => d.to_did(),
145+ Err(e) => {
146+ error!("invalid did '{key:?}' in pending: {e}");
147+ continue;
00148 }
000149 };
150151 if self.in_flight.contains_sync(&did) {