Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions crates/buzz-db/src/store/deletion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,18 @@ impl DeletionStore {
.unwrap_or(false)
}

/// Whether an indexing relay has ever maintained a search index against
/// this database.
pub async fn search_index_maintained(&self) -> Result<bool> {
crate::search_outbox::is_index_maintained(&self.pool).await
}

/// Take the next monotonic external version for OpenSearch document
/// deletes during community purge.
pub async fn next_search_index_version(&self) -> Result<i64> {
crate::search_outbox::next_index_version(&self.pool).await
}

/// Persist a request. Only active non-tombstone communities may be submitted.
///
/// `requested_by` is recorded on a new row and is also the convergence key
Expand Down
20 changes: 20 additions & 0 deletions crates/buzz-db/src/store/search_outbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ pub(crate) async fn index_maintained(conn: &mut sqlx::PgConnection) -> Result<bo
.await?)
}

/// Whether an indexing relay has ever run against this database.
///
/// Used by out-of-band processes such as community deletion to fail closed
/// when a search index is maintained but no OpenSearch address was configured.
pub async fn is_index_maintained(pool: &PgPool) -> Result<bool> {
let mut conn = pool.acquire().await?;
index_maintained(&mut conn).await
}

/// Take the next monotonic external version from `search_index_version`.
///
/// Used when writing or deleting documents outside a normal outbox batch
/// (such as whole-community purge) so late requests with older versions cannot
/// overwrite newer deletes.
pub async fn next_index_version(pool: &PgPool) -> Result<i64> {
Ok(sqlx::query_scalar("SELECT nextval('search_index_version')")
.fetch_one(pool)
.await?)
}

/// Queue the index change for an event this admitted transaction inserted,
/// soft-deleted or otherwise changed: the event itself when it is
/// searchable, or the message it edits when it is a message edit.
Expand Down
2 changes: 2 additions & 0 deletions crates/buzz-deletion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ buzz-core = { workspace = true }
buzz-db = { workspace = true }
buzz-media = { workspace = true }
buzz-pubsub = { workspace = true }
buzz-search = { workspace = true }
chrono = { workspace = true }
clap = { version = "4", features = ["derive"] }
hex = { workspace = true }
Expand All @@ -24,6 +25,7 @@ serde_json = { workspace = true }
sqlx = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }
tracing = { workspace = true }
uuid = { workspace = true }

fs2 = "0.4"
Expand Down
Loading
Loading