Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f9d06a7
fix: report Backfilling on a creating GSI and refuse its reads by phase
LeeroyHannigan Oct 29, 2026
493574a
test(storage-postgres): pin GSI creation under concurrent writers
LeeroyHannigan Oct 29, 2026
2d4794f
test(rust): wait for the hash-only GSI to be ACTIVE before querying it
LeeroyHannigan Oct 29, 2026
885242c
fix(storage-postgres): keep a GSI backfilling through a passing build…
LeeroyHannigan Oct 29, 2026
ef6d66a
fix(app): accept the per-table GSI phase hold in extenddb settings set
LeeroyHannigan Oct 29, 2026
504e920
fix(storage): read the GSI backfill set before the catalog row
LeeroyHannigan Oct 29, 2026
45e9f50
ci(mongodb): run the live GSI phase tests in the MongoDB rust job
LeeroyHannigan Oct 29, 2026
a0ae905
test: cover the Cassandra recovery claim and a resumed MongoDB backfill
LeeroyHannigan Oct 29, 2026
bafa608
fix(storage-cassandra): build a recovered GSI only in its own account…
LeeroyHannigan Oct 29, 2026
511cc79
fix(storage-sqlite): hold the second GSI phase between the build and …
LeeroyHannigan Oct 29, 2026
af36b96
test(storage-cassandra): keep table names out of a recovery test message
LeeroyHannigan Oct 29, 2026
a6479df
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Nov 4, 2026
9897697
test(storage-postgres): seed the settings rows the GSI tests set
LeeroyHannigan Nov 4, 2026
47b2d34
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Nov 6, 2026
7c69265
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Nov 9, 2026
3cb02a7
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Nov 14, 2026
9e4622d
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Nov 24, 2026
5b9bb18
test(rust): share wait_for_index_active between the GSI tests
LeeroyHannigan Nov 24, 2026
3b92408
fix(server): parse the GSI phase hold key with the table-scoped key h…
LeeroyHannigan Nov 24, 2026
de63ffc
refactor(storage): drop GsiBackfills::started
LeeroyHannigan Nov 24, 2026
15794eb
test(storage-postgres): fail the GSI tests when the job requires a se…
LeeroyHannigan Nov 24, 2026
b98387e
test(storage-cassandra): drop the two-account recovery test main covers
LeeroyHannigan Nov 24, 2026
c267735
fix(storage-cassandra): fail a GSI read whose status column does not …
LeeroyHannigan Nov 24, 2026
a505dc3
test(python): send ExecuteStatement in each GSI phase
LeeroyHannigan Nov 24, 2026
681ccbf
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Nov 24, 2026
14f7d01
test(storage-cassandra): read the data table's schema row as a system…
LeeroyHannigan Nov 24, 2026
3ab93e8
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Nov 24, 2026
832afe7
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Nov 24, 2026
ece2581
fix(sqlite): wait out the GSI phase hold in one function the wasm32 l…
LeeroyHannigan Nov 25, 2026
deda762
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Dec 3, 2026
f9831b5
fix(partiql): refuse a read of a backfilling GSI per statement in a b…
LeeroyHannigan Dec 3, 2026
c3d2973
docs(upgrade): name the GSI phase refusals in the v1.2.0 changes
LeeroyHannigan Dec 3, 2026
2a75a22
test(storage-postgres): pass built SQL to sqlx 0.9 in AssertSqlSafe
LeeroyHannigan Dec 3, 2026
d2bfa44
Merge origin/main into fix/pg-gsi-create-race
LeeroyHannigan Dec 4, 2026
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
60 changes: 42 additions & 18 deletions crates/app/src/cmd_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use extenddb_config::{self as config, MASK};

// Re-use validation constants from the ops layer.
use extenddb_server::management::ops_settings::{
KNOWN_KEYS, READONLY_KEYS, server_setting_default,
KNOWN_KEYS, READONLY_KEYS, server_setting_default, writable_key_validator,
};

#[derive(Args)]
Expand Down Expand Up @@ -180,13 +180,32 @@ async fn get(store: &dyn SettingsStore, key: &str, show_secret: bool) -> anyhow:
}

async fn set(store: &dyn SettingsStore, key: &str, value: &str) -> anyhow::Result<()> {
validate(key, value)?;

// Write under the canonical name so the deprecated alias updates the row the read
// path consults, rather than adding a second one that is silently ignored.
let key = extenddb_core::settings_keys::canonical_key(key);
store
.set_setting(key, value)
.await
.map_err(|e| anyhow::anyhow!("Failed to set setting: {e:?}"))?;

tracing::warn!(
target: "extenddb::audit::settings",
"settings-set: key={key}, value={value}",
);
println!("{key} = {value}");
Ok(())
}

/// Refuse a read-only or unknown key, or a value its validator rejects, with
/// the same lookup the management API uses.
fn validate(key: &str, value: &str) -> anyhow::Result<()> {
if READONLY_KEYS.contains(&key) {
anyhow::bail!("Setting '{key}' is read-only and cannot be changed via this command.");
}

// Validate against known keys.
let known = KNOWN_KEYS.iter().find(|(k, _)| *k == key);
if let Some((_, validator)) = known {
if let Some(validator) = writable_key_validator(key) {
validator(value)
.map_err(|reason| anyhow::anyhow!("Invalid value for '{key}': {reason}"))?;
} else {
Expand All @@ -200,20 +219,6 @@ async fn set(store: &dyn SettingsStore, key: &str, value: &str) -> anyhow::Resul
.join(", ")
);
}

// Write under the canonical name so the deprecated alias updates the row the read
// path consults, rather than adding a second one that is silently ignored.
let key = extenddb_core::settings_keys::canonical_key(key);
store
.set_setting(key, value)
.await
.map_err(|e| anyhow::anyhow!("Failed to set setting: {e:?}"))?;

tracing::warn!(
target: "extenddb::audit::settings",
"settings-set: key={key}, value={value}",
);
println!("{key} = {value}");
Ok(())
}

Expand Down Expand Up @@ -452,4 +457,23 @@ mod tests {
);
}
}

#[test]
fn a_table_gsi_phase_hold_is_writable_from_the_cli() {
// The admin guide lists `gsi_creating_phase_delay_ms:<table>` among the
// settings managed with `extenddb settings set`.
validate("gsi_creating_phase_delay_ms:orders", "1000").expect("a valid hold");
validate("gsi_creating_phase_delay_ms:orders", "0").expect("zero clears it");
let err =
validate("gsi_creating_phase_delay_ms:orders", "60001").expect_err("above the bound");
assert!(
err.to_string()
.starts_with("Invalid value for 'gsi_creating_phase_delay_ms:orders'"),
"{err}"
);
let err = validate("gsi_creating_phase_delay_ms:ab", "1000")
.expect_err("a table name the service would refuse");
assert!(err.to_string().starts_with("Unknown setting"), "{err}");
assert!(!config::should_redact("gsi_creating_phase_delay_ms:orders"));
}
}
22 changes: 22 additions & 0 deletions crates/core/src/settings_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ pub const VECTOR_INDEX_MIN_CREATING_MS: &str = "vector_index_min_creating_ms";
/// Unset, nothing waits and no branch is taken.
pub const VECTOR_ALLOCATION_PHASE_DELAY_MS: &str = "vector_allocation_phase_delay_ms";

/// Test-only hold on the two `CREATING` phases of a GSI that `UpdateTable` adds.
///
/// Keys take the form `gsi_creating_phase_delay_ms:<table-name>` (see
/// [`gsi_creating_phase_delay_key`]) and the value is milliseconds. While it is
/// set for a table, a GSI added to that table waits that long after its catalog
/// row commits and before its backfill starts (`Backfilling: false`), then that
/// long again after the backfill has started (`Backfilling: true`). The phases
/// come from the build itself; the hold only lengthens them. On a test-sized
/// table both phases otherwise last milliseconds, so a client polling
/// DescribeTable could not observe them, and the measured Query and Scan refusals
/// for each phase could not be tested at the wire.
///
/// Scoped to one table so a test that sets it does not slow the GSI builds of the
/// tests running beside it. Unset or zero, nothing waits.
pub const GSI_CREATING_PHASE_DELAY_MS: &str = "gsi_creating_phase_delay_ms";

/// The settings key holding [`GSI_CREATING_PHASE_DELAY_MS`] for one table.
#[must_use]
pub fn gsi_creating_phase_delay_key(table_name: &str) -> String {
format!("{GSI_CREATING_PHASE_DELAY_MS}:{table_name}")
}

/// The accounts whose SearchVectors requests accept the extended
/// `SearchConditionExpression` grammar: `all` (the default when the row is
/// absent or empty), `off`, or a comma-separated list of 12-digit account
Expand Down
19 changes: 18 additions & 1 deletion crates/core/src/types/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ pub struct GsiDescription {
pub projection: Projection,
#[serde(rename = "IndexStatus")]
pub index_status: String,
/// Whether a GSI added by `UpdateTable` is still being populated.
///
/// The same three states, in the same order, as
/// [`VectorIndexDescription::backfilling`], whose comment carries the
/// vector measurement. Measured for a GSI on 2026-10-26 (us-east-1): `false`
/// while the index is `CREATING` and its backfill has not started, `true`
/// while it runs, absent once the index is `ACTIVE`. ExtendDB reports the
/// member only for a GSI that `UpdateTable` added, and `None` serialises as
/// an absent member.
#[serde(
rename = "Backfilling",
skip_serializing_if = "Option::is_none",
default
)]
pub backfilling: Option<bool>,
#[serde(
rename = "ProvisionedThroughput",
skip_serializing_if = "Option::is_none"
Expand Down Expand Up @@ -751,7 +766,9 @@ pub const VECTOR_INDEX_SCAN_NOT_SUPPORTED: &str = "Scan operation not supported

/// Prefix of the Scan refusal while a vector index is still backfilling;
/// continues with the index name. The service reuses the GSI wording even
/// though the index is a vector index. Measured 2026-08-20.
/// though the index is a vector index. Measured 2026-08-20. A GSI that
/// `UpdateTable` is backfilling refuses both Query and Scan with this sentence
/// (measured 2026-10-26).
pub const VECTOR_INDEX_BACKFILLING_SCAN_PREFIX: &str =
"Cannot read from backfilling global secondary index: ";

Expand Down
2 changes: 2 additions & 0 deletions crates/engine/src/backup/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4160,6 +4160,7 @@ fn described(request: &RestoreRequest) -> TableDescription {
key_schema: g.key_schema.clone(),
projection: g.projection.clone(),
index_status: "ACTIVE".to_owned(),
backfilling: None,
provisioned_throughput: Some(ProvisionedThroughputDescription {
read_capacity_units: 9,
write_capacity_units: 9,
Expand Down Expand Up @@ -12016,6 +12017,7 @@ fn music_table() -> TableDescription {
non_key_attributes: None,
},
index_status: "ACTIVE".to_owned(),
backfilling: None,
provisioned_throughput: Some(ProvisionedThroughputDescription {
read_capacity_units: 1,
write_capacity_units: 1,
Expand Down
7 changes: 4 additions & 3 deletions crates/engine/src/partiql/authorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ async fn each_disjunct(

/// The key schema of what `stmt` reads or writes: the index's for a read of
/// an index, the table's otherwise. `None` when the table is missing, when
/// the index is missing or a vector index, so that the condition keys read
/// from the key are absent.
/// the index is missing, a vector index or a GSI whose backfill has started,
/// so that the condition keys read from the key are absent.
///
/// # Errors
///
/// A failed read of the index other than a missing index.
/// A failed read of the index other than a missing or backfilling index.
async fn target_schema(
ctx: &OperationContext,
stmt: &Statement,
Expand Down Expand Up @@ -279,6 +279,7 @@ async fn target_schema(
{
Ok(info) => Ok(Some(info.key_schema)),
Err(StorageError::IndexNotFound(_)) => Ok(None),
Err(e) if extenddb_storage::gsi_backfill::is_backfilling_refusal(&e) => Ok(None),
Err(e) => Err(storage_err_to_dynamo(e)),
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/engine/src/partiql/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ async fn check_read(
"The table does not have the specified index".to_owned(),
));
}
// A GSI whose backfill has started is refused per statement
// too, with the sentence `ExecuteStatement` gets.
Err(e) if extenddb_storage::gsi_backfill::is_backfilling_refusal(&e) => {
return untranslated(storage_err_to_dynamo(e));
}
Err(e) => return Err(storage_err_to_dynamo(e)),
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/engine/src/update_table_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn projected_total_counts_kept_indexes_and_created_ones() {
key_schema: Vec::new(),
projection: include(30),
index_status: "ACTIVE".to_owned(),
backfilling: None,
provisioned_throughput: None,
index_size_bytes: 0,
item_count: 0,
Expand All @@ -112,6 +113,7 @@ fn projected_total_counts_kept_indexes_and_created_ones() {
key_schema: Vec::new(),
projection: include(50),
index_status: "ACTIVE".to_owned(),
backfilling: None,
provisioned_throughput: None,
index_size_bytes: 0,
item_count: 0,
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/warm_throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ mod tests {
projection_type: ProjectionType::All,
non_key_attributes: None,
},
backfilling: None,
index_status: "ACTIVE".to_owned(),
provisioned_throughput: Some(ProvisionedThroughputDescription::default()),
index_size_bytes: 0,
Expand Down
68 changes: 62 additions & 6 deletions crates/server/src/management/ops_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ fn validate_unknown_commit_test_gate(value: &str) -> Result<(), &'static str> {
}
}

#[cfg(feature = "mongodb-test-hooks")]
/// The table name of a `<prefix>:<table-name>` key, when the name is one the
/// service would accept for a table: 3 to 255 characters from `a-z`, `A-Z`,
/// `0-9`, `.`, `_` and `-`.
fn table_scoped_gate_table_name<'a>(key: &'a str, prefix: &str) -> Option<&'a str> {
let table_name = key.strip_prefix(prefix)?.strip_prefix(':')?;
let valid = !table_name.is_empty()
let valid = (3..=255).contains(&table_name.len())
&& table_name
.bytes()
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'_' | b'-'));
Expand All @@ -137,6 +139,16 @@ fn is_table_scoped_unknown_commit_gate_key(key: &str) -> bool {
.is_some()
}

/// `gsi_creating_phase_delay_ms:<table-name>`, with a name the service would
/// accept for a table.
fn is_gsi_creating_phase_delay_key(key: &str) -> bool {
table_scoped_gate_table_name(
key,
extenddb_core::settings_keys::GSI_CREATING_PHASE_DELAY_MS,
)
.is_some()
}

fn validate_bool(value: &str) -> Result<(), &'static str> {
match value {
"true" | "false" => Ok(()),
Expand All @@ -160,6 +172,26 @@ fn validate_index_propagation_delay_ms(value: &str) -> Result<(), &'static str>
}
}

/// The validator for a writable key: one of [`KNOWN_KEYS`], or a table's
/// `gsi_creating_phase_delay_ms:<table-name>` hold. The management API and
/// `extenddb settings set` both look keys up here, so they accept the same
/// keys.
#[must_use]
pub fn writable_key_validator(key: &str) -> Option<Validator> {
KNOWN_KEYS
.iter()
.find(|(k, _)| *k == key)
.map(|(_, validator)| *validator)
// A test lever for the same reason as the vector ones above: the two
// CREATING phases of a GSI build last milliseconds on a test-sized table,
// so the measured refusal for each cannot be observed from a client unless
// a test can lengthen them. Scoped to one table; same bound and validator.
.or_else(|| {
is_gsi_creating_phase_delay_key(key)
.then_some(validate_backfill_batch_delay_ms as Validator)
})
}

/// Set a runtime setting with validation.
///
/// Validates the key and value, then delegates the write to the
Expand All @@ -179,10 +211,7 @@ pub async fn set_setting(
return Err(OpError::Validation(format!("Setting '{key}' is read-only")));
}

let known = KNOWN_KEYS
.iter()
.find(|(k, _)| *k == key)
.map(|(_, validator)| *validator);
let known = writable_key_validator(key);
#[cfg(feature = "mongodb-test-hooks")]
let known = known
.or_else(|| {
Expand Down Expand Up @@ -225,6 +254,33 @@ pub async fn set_setting(
Ok(())
}

#[cfg(test)]
mod tests {
use super::is_gsi_creating_phase_delay_key;

#[test]
fn a_gsi_phase_hold_is_writable_for_one_valid_table_name() {
assert!(is_gsi_creating_phase_delay_key(
"gsi_creating_phase_delay_ms:orders-2026.v1_x"
));
assert!(!is_gsi_creating_phase_delay_key(
"gsi_creating_phase_delay_ms"
));
assert!(!is_gsi_creating_phase_delay_key(
"gsi_creating_phase_delay_ms:"
));
assert!(!is_gsi_creating_phase_delay_key(
"gsi_creating_phase_delay_ms:ab"
));
assert!(!is_gsi_creating_phase_delay_key(
"gsi_creating_phase_delay_ms:has space"
));
assert!(!is_gsi_creating_phase_delay_key(
"gsi_creating_phase_delay_msx:orders"
));
}
}

#[cfg(all(test, feature = "search-inequality-filters"))]
#[path = "ops_settings_search_tests.rs"]
mod search_tests;
1 change: 1 addition & 0 deletions crates/storage-cassandra/src/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ impl CassandraEngine {
key_schema: g.key_schema.clone(),
projection: g.projection.clone(),
index_status: "ACTIVE".to_owned(),
backfilling: None,
provisioned_throughput: Some(ProvisionedThroughputDescription {
read_capacity_units: g
.provisioned_throughput
Expand Down
18 changes: 17 additions & 1 deletion crates/storage-cassandra/src/data/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,21 @@ pub async fn fetch_indexes_for_table(
/// Fetch a single index by `table_id` and `index_name` (hot path for query routing).
///
/// Uses the `PRIMARY KEY ((table_id), index_name)` for efficient single-row lookup.
///
/// A GSI still being built is not readable: its table is partial. The service
/// refuses a Query or Scan naming one in two ways, by phase (see
/// `extenddb_storage::gsi_backfill`). The recovery worker writes
/// `backfill_heartbeat` when it takes the index up for its backfill (see
/// `crate::gsi_backfill_phase`), so a heartbeat means the backfill has started.
pub async fn fetch_index_by_name(
table_id: &str,
index_name: &str,
session: &Arc<CassandraSession>,
catalog_keyspace: &str,
) -> Result<IndexMeta, StorageError> {
let query = format!(
"SELECT index_id, index_type, key_schema, projection, propagation_delay_ms \
"SELECT index_id, index_type, key_schema, projection, propagation_delay_ms, \
index_status, backfill_heartbeat \
FROM {catalog_keyspace}.indexes WHERE table_id = ? AND index_name = ?"
);

Expand All @@ -130,6 +137,15 @@ pub async fn fetch_index_by_name(
.next()
.ok_or_else(|| StorageError::IndexNotFound(index_name.to_owned()))?;

let index_status: String = get_column(&row, "index_status", "fetch_index_by_name")?;
if index_status == "CREATING" {
let heartbeat: Option<i64> = row.get_by_name("backfill_heartbeat").ok().flatten();
return Err(extenddb_storage::gsi_backfill::creating_read_refusal(
index_name,
heartbeat.is_some(),
));
}

let index_id: String = get_column(&row, "index_id", "fetch_index_by_name")?;
let index_type: String = get_column(&row, "index_type", "fetch_index_by_name")?;
let key_schema_text: String = get_column(&row, "key_schema", "fetch_index_by_name")?;
Expand Down
Loading
Loading