Skip to content

Commit 6ec3433

Browse files
Preslav LeConvex, Inc.
Preslav Le
authored and
Convex, Inc.
committed
Clean up after migration BackfillIndexState migration (#24073)
Clean up old migrations + make index_state_lower_bound required. GitOrigin-RevId: 07f255858a32c9919748eb019f6cff96f6e58ae2
1 parent 37942e0 commit 6ec3433

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

crates/common/src/bootstrap_model/index/database_index/backfill_state.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ pub struct DatabaseIndexBackfillState {
1515
// before the index was committed because we don't know the commit timestamp.
1616
// We need to run retention from this timestamp, because live writes write to
1717
// the index the moment the index committed.
18-
pub index_created_lower_bound: Option<Timestamp>,
18+
pub index_created_lower_bound: Timestamp,
1919
// We have done the backfill and the only step left is catch up retention.
2020
pub retention_started: bool,
2121
}
2222

2323
#[derive(Serialize, Deserialize)]
2424
#[serde(rename_all = "camelCase")]
2525
pub struct SerializedDatabaseIndexBackfillState {
26-
// TODO: Backfill and remove optional.
26+
// NOTE: Those fields should be populated for all latest indexes. We keep them
27+
// as option if we ever need to parse historical documents.
2728
index_created_lower_bound: Option<i64>,
2829
retention_started: Option<bool>,
2930
}
@@ -33,7 +34,7 @@ impl TryFrom<DatabaseIndexBackfillState> for SerializedDatabaseIndexBackfillStat
3334

3435
fn try_from(config: DatabaseIndexBackfillState) -> anyhow::Result<Self> {
3536
Ok(Self {
36-
index_created_lower_bound: config.index_created_lower_bound.map(|ts| ts.into()),
37+
index_created_lower_bound: Some(config.index_created_lower_bound.into()),
3738
retention_started: Some(config.retention_started),
3839
})
3940
}
@@ -47,8 +48,8 @@ impl TryFrom<SerializedDatabaseIndexBackfillState> for DatabaseIndexBackfillStat
4748
index_created_lower_bound: config
4849
.index_created_lower_bound
4950
.map(|ts| ts.try_into())
50-
.transpose()?,
51-
// Treat legacy records as retention not started.
51+
.transpose()?
52+
.unwrap_or(Timestamp::MIN),
5253
retention_started: config.retention_started.unwrap_or(false),
5354
})
5455
}

crates/common/src/bootstrap_model/index/database_index/index_state.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use serde::{
44
Deserialize,
55
Serialize,
66
};
7+
use sync_types::Timestamp;
78
use value::codegen_convex_serialization;
89

910
use super::{
@@ -67,10 +68,10 @@ impl TryFrom<SerializedDatabaseIndexState> for DatabaseIndexState {
6768
},
6869
SerializedDatabaseIndexState::Backfilled2 => DatabaseIndexState::Backfilled,
6970
SerializedDatabaseIndexState::Enabled => DatabaseIndexState::Enabled,
70-
// TODO(Presley): Backfill and delete Disabled state.
71+
// None of the latest index documents should be in this state.
7172
SerializedDatabaseIndexState::Disabled => {
7273
DatabaseIndexState::Backfilling(DatabaseIndexBackfillState {
73-
index_created_lower_bound: None,
74+
index_created_lower_bound: Timestamp::MIN,
7475
retention_started: false,
7576
})
7677
},

crates/common/src/bootstrap_model/index/index_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<T: TableIdentifier> IndexMetadata<T> {
7272
config: IndexConfig::Database {
7373
developer_config: DeveloperDatabaseIndexConfig { fields },
7474
on_disk_state: DatabaseIndexState::Backfilling(DatabaseIndexBackfillState {
75-
index_created_lower_bound: Some(index_created_lower_bound),
75+
index_created_lower_bound,
7676
retention_started: false,
7777
}),
7878
},

crates/database/src/index_worker.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ use common::{
6868
RepeatableTimestamp,
6969
TabletIndexName,
7070
Timestamp,
71-
WriteTimestamp,
7271
},
7372
value::{
7473
ResolvedDocumentId,
@@ -424,8 +423,8 @@ impl<RT: Runtime> IndexWorker<RT> {
424423
let mut tx = self.database.begin(Identity::system()).await?;
425424
let index_table_id = tx.bootstrap_tables().index_id;
426425

427-
let (index_doc, index_ts) = tx
428-
.get_with_ts(ResolvedDocumentId::new(index_table_id, index_id))
426+
let index_doc = tx
427+
.get(ResolvedDocumentId::new(index_table_id, index_id))
429428
.await?
430429
.ok_or_else(|| anyhow::anyhow!("Index {index_id:?} no longer exists"))?;
431430
let mut index_metadata = TabletIndexMetadata::from_document(index_doc)?;
@@ -447,13 +446,10 @@ impl<RT: Runtime> IndexWorker<RT> {
447446
};
448447

449448
state.retention_started = true;
450-
451-
// TODO(presley): Remove the fallback to commit_ts.
452-
let WriteTimestamp::Committed(committed_ts) = index_ts else {
453-
anyhow::bail!("index {index_id} is pending write");
454-
};
455-
let index_created = state.index_created_lower_bound.unwrap_or(committed_ts);
456-
(index_created, developer_config.fields.clone())
449+
(
450+
state.index_created_lower_bound,
451+
developer_config.fields.clone(),
452+
)
457453
},
458454
_ => anyhow::bail!(
459455
"IndexWorker attempted to backfill an index {index_metadata:?} which wasn't a \

0 commit comments

Comments
 (0)