Skip to content
Open
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
4 changes: 4 additions & 0 deletions crates/engine/src/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ pub fn storage_err_to_dynamo(e: extenddb_storage::error::StorageError) -> Dynamo
StorageError::IndexNotFound(name) => DynamoDbError::ValidationException(format!(
"The table does not have the specified index: {name}"
)),
StorageError::IndexBackfilling(name) => DynamoDbError::ValidationException(format!(
"{}{name}",
extenddb_core::types::VECTOR_INDEX_BACKFILLING_SCAN_PREFIX
)),
StorageError::IndexAlreadyExists(name) => DynamoDbError::ValidationException(format!(
"One or more parameter values were invalid: Index already exists: {name}"
)),
Expand Down
20 changes: 6 additions & 14 deletions crates/engine/src/partiql/authorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ use extenddb_core::partiql::plan::{KeyNames, KeyRead, WhereAnalysis, read_order}
use extenddb_core::types::{
AttributeValue, KeySchemaElement, TableKeyInfo, is_multipart_key_schema,
};
use extenddb_storage::error::StorageError;

use super::SingleRequest;
use super::common::{self, bound_value};
use super::select::MAX_DECOMPOSED_READS;
use crate::create_table::storage_err_to_dynamo;
use crate::{ItemAccess, ItemAuthorizer, OperationContext};

pub(super) use access::written_value;
Expand Down Expand Up @@ -244,12 +242,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, backfilling or a vector index, 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 All @@ -272,15 +270,9 @@ async fn target_schema(
{
return Ok(None);
}
match ctx
.storage
.index_info_by_table_id(&key_info.table_id, index)
.await
{
Ok(info) => Ok(Some(info.key_schema)),
Err(StorageError::IndexNotFound(_)) => Ok(None),
Err(e) => Err(storage_err_to_dynamo(e)),
}
Ok(common::statement_index(ctx, &key_info.table_id, index)
.await?
.map(|info| info.key_schema))
}

/// The key names of a key schema with one partition key and at most one sort
Expand Down
22 changes: 6 additions & 16 deletions crates/engine/src/partiql/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,9 @@ async fn projected_call_error(
};
let schema = match &from.index {
None => key_info.key_schema,
Some(index) => match ctx
.storage
.index_info_by_table_id(&key_info.table_id, index)
.await
{
Ok(info) => info.key_schema,
Err(StorageError::IndexNotFound(_)) => return Ok(message),
Err(e) => return Err(storage_err_to_dynamo(e)),
Some(index) => match common::statement_index(ctx, &key_info.table_id, index).await? {
Some(info) => info.key_schema,
None => return Ok(message),
},
};
Ok(match common::ensure_single_attribute_keys(&schema) {
Expand Down Expand Up @@ -366,22 +361,17 @@ async fn check_read(
.iter()
.any(|v| &v.index_name == index_name);
if !is_vector {
match ctx
.storage
.index_info_by_table_id(&key_info.table_id, index_name)
.await
{
Ok(info) => {
match common::statement_index(ctx, &key_info.table_id, index_name).await? {
Some(info) => {
if let Err(e) = common::ensure_single_attribute_keys(&info.key_schema) {
return untranslated(e);
}
}
Err(StorageError::IndexNotFound(_)) => {
None => {
return untranslated(DynamoDbError::ValidationException(
"The table does not have the specified index".to_owned(),
));
}
Err(e) => return Err(storage_err_to_dynamo(e)),
}
}
return primary_key_required();
Expand Down
25 changes: 24 additions & 1 deletion crates/engine/src/partiql/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ use extenddb_core::partiql::plan::{
key_equality, path_tested_against_values, same_value,
};
use extenddb_core::types::{
AttributeValue, CancellationReason, KeySchemaElement, KeyType, ScalarAttributeType,
AttributeValue, CancellationReason, IndexInfo, KeySchemaElement, KeyType, ScalarAttributeType,
TableKeyInfo, is_multipart_key_schema,
};
use extenddb_storage::error::StorageError;

use super::write::{resolve_av, to_json_value};
use crate::OperationContext;
use crate::create_table::storage_err_to_dynamo;

/// The service's refusal for any PartiQL statement whose target (table or
/// index) has more than one HASH or more than one RANGE key attribute.
Expand Down Expand Up @@ -55,6 +58,26 @@ pub(super) fn ensure_single_attribute_keys(
Ok(())
}

/// The index `index` of the table `table_id`, or `None` when the table has no
/// index of that name or the index is a GSI still backfilling. The service's
/// answer to a PartiQL read of a backfilling index is not measured, so a
/// statement naming one gets the answers for a missing index.
///
/// # Errors
///
/// A failed read of the catalog.
pub(super) async fn statement_index(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A PartiQL read of a CREATING index answers as if the index did not exist, and every UpdateTable now opens that window. On the service in the backfilling phase, ExecuteStatement SELECT with WHERE on the index key, on pk or with no WHERE answers Cannot read from backfilling global secondary index: gsi1, with ConsistentRead true Strongly consistent read is not supported on Global Secondary Indexes, and inside BatchExecuteStatement Select statements within BatchExecuteStatement must specify the primary key in the where clause. as for an ACTIVE index; this head and main give The table does not have the specified index on all 20 shapes, twice. The comment, design section 6.2 and the body say this was not measured. Treating a backfilling index as existing for these checks and refusing at the read would match; otherwise a differences row would say it.

ctx: &OperationContext,
table_id: &str,
index: &str,
) -> Result<Option<IndexInfo>, DynamoDbError> {
match ctx.storage.index_info_by_table_id(table_id, index).await {
Ok(info) => Ok(Some(info)),
Err(StorageError::IndexNotFound(_) | StorageError::IndexBackfilling(_)) => Ok(None),
Err(e) => Err(storage_err_to_dynamo(e)),
}
}

/// The refusal of a key value whose type is not the one the table defines for
/// that key attribute, naming the attribute (measured 2026-11-02 for an INSERT
/// key, for SELECT, UPDATE and DELETE key conditions, and for a
Expand Down
11 changes: 3 additions & 8 deletions crates/engine/src/partiql/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,20 @@ pub(super) async fn run(
"Scan operation not supported on this index type".to_owned(),
));
}
match ctx
.storage
.index_info_by_table_id(&key_info.table_id, index_name)
.await
{
Ok(info) => {
match common::statement_index(ctx, &key_info.table_id, index_name).await? {
Some(info) => {
common::ensure_single_attribute_keys(&info.key_schema)?;
(info.key_schema.clone(), Some(info))
}
// A projected call (`COUNT(*)`) is refused ahead of the index
// lookup (measured 2026-11-02, with and without a WHERE).
Err(StorageError::IndexNotFound(_)) => {
None => {
return Err(DynamoDbError::ValidationException(
stmt.projection_error.clone().unwrap_or_else(|| {
"The table does not have the specified index".to_owned()
}),
));
}
Err(e) => return Err(storage_err_to_dynamo(e)),
}
} else {
common::ensure_single_attribute_keys(&key_info.key_schema)?;
Expand Down
26 changes: 19 additions & 7 deletions crates/storage-postgres/src/data/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,22 +566,34 @@ impl PostgresEngine {
index_name: &str,
) -> Result<IndexInfo, StorageError> {
// A GSI still being built is not readable: its table is partial, or not
// there yet. The service answers a Query or Scan naming one with "The
// table does not have the specified index", the same as for no index at
// all, which is what `IndexNotFound` becomes on the wire.
let idx_row: Option<(String, String, serde_json::Value, serde_json::Value)> =
// there yet. In its backfilling phase the service refuses a Query or
// Scan naming one with "Cannot read from backfilling global secondary
// index: <name>". Measured 2026-10-30 on six index builds on four
// tables: DescribeTable reported `Backfilling` true 16 to 39 s after
// UpdateTable. On two tables the first Query and Scan sent after that,
// about two minutes after UpdateTable, got the backfilling text. On a
// third, Queries 0 and 2 s after `Backfilling` turned true still got
// "The table does not have the specified index", the answer before it
// turned true, and Queries about 45 s after it got the backfilling
// text. This backend has no allocation phase, so every CREATING index
// gets the backfilling refusal, which the engine answers with that text
// for a Query or Scan and as a missing index for a PartiQL statement.
let idx_row: Option<(String, String, String, serde_json::Value, serde_json::Value)> =
sqlx::query_as(
"SELECT index_type, index_id, key_schema, projection FROM indexes \
WHERE table_id = $1 AND index_name = $2 AND index_status <> 'CREATING'",
"SELECT index_type, index_id, index_status, key_schema, projection \
FROM indexes WHERE table_id = $1 AND index_name = $2",
)
.bind(table_id)
.bind(index_name)
.fetch_optional(&self.pool)
.await
.map_err(|e| StorageError::Internal(e.to_string()))?;

let (idx_type_str, idx_id, ks_json, proj_json) =
let (idx_type_str, idx_id, idx_status, ks_json, proj_json) =
idx_row.ok_or_else(|| StorageError::IndexNotFound(index_name.to_owned()))?;
if idx_status == "CREATING" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refusal also reaches the PartiQL callers of index_info_by_table_id, which treat only IndexNotFound as an expected answer and pass any other error up as a request failure. A BatchExecuteStatement naming a CREATING index now fails as a whole call, and its other statements get no answer.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced this through dispatch on PostgreSQL with the build held: your two-statement batch failed as a whole call with the backfilling ValidationException. With a caller allowed on the table, the base-table statement lost its item.

Fixed in 5b70d1f282 (engine) and 49fc116934 (PostgreSQL).

The refusal is now its own variant, StorageError::IndexBackfilling, and Query and Scan still answer it with the backfilling text. The four PartiQL lookups (target_schema, check_read, projected_call_error and the single SELECT) now call one helper, common::statement_index, which reads a backfilling index as a missing one. So a PartiQL read of a CREATING index gets the answers main gives for an index the table does not have. The batch stays 200, with a per-statement error for the index read and an answer for the other statement. The engine gives an ExecuteStatement the missing-index refusal only after it authorizes the statement, so a caller with no permission gets AccessDeniedException.

The new test reads_of_a_creating_index_through_the_engine in gsi_async_build.rs sends each PartiQL read to the CREATING index and to a missing one. It asserts both answers in full, for an allowed caller and for a refused one. With the production code of d0ee181, it fails on the batch.

return Err(StorageError::IndexBackfilling(index_name.to_owned()));
}

let index_type = match idx_type_str.as_str() {
"GSI" => IndexType::Gsi,
Expand Down
Loading
Loading