Skip to content

[engine] $lookup type-0 error, uncancellable string expressions, reindex retry and old-catalog failures #769

Open

Description

@guanzhousongmicrosoft

Engine-side failures found in E2E runs on release/1.0-RC2-v2 @ 40f86c0. Images were documentdb-local PG17/PG18 built from that commit; clients were pymongo and mongosh.

Items

  • $lookup fails with "Unrecognized BSON data type code 0"
  • $regexFindAll / $replaceAll on large input ignore statement_timeout and stall other collections' index builds
  • A reindex that fails in post-processing can never succeed on retry ("could not open relation with OID 0")
  • New binary on an un-updated catalog: InternalError and misleading errors instead of a clear message

1. $lookup fails with "Unrecognized BSON data type code 0"

A plain $lookup with localField/foreignField fails on a fresh 1.0 install, and also on an upgraded catalog:

OperationFailure: Unrecognized BSON data type code 0, code 115 (CommandNotSupported)

We ran a self-lookup on a 1000-document collection with different indexes on the foreign side. No index, a single-field index, a partial index and a compound index all worked. The failure only appeared after a wildcard index ({"$**": 1}) was built on the foreign collection. That trigger is inferred from log timing and not yet isolated.

The error is raised by BsonTypeName() for type 0 (EOD) (pg_documentdb_core/src/io/pgbson_utils.c). This suggests the lookup or wildcard path reads an unset value.

2. Runaway string expressions can't be cancelled

The size_limit cases in the functional tests for $regexFindAll (a 16 MB string, regex a) and $replaceAll (empty-find amplification) behave like this:

  • The gateway gives up at 121 s with ExceededTimeLimit, but the backend keeps running aggregate_cursor_first_page. PG never logs canceling statement due to statement timeout.
  • While it runs, background index builds on other collections hang, because CREATE INDEX CONCURRENTLY waits on its snapshot.
  • In our run it took about 12 minutes until the backend was SIGKILLed. That forced a cluster restart, and both stuck builds then finished within 50 ms.

pg_documentdb/src/operators/bson_expression_string_operators.c has no CHECK_FOR_INTERRUPTS(). Adding it to the regex-find-all and replace-all loops should fix the cancellation. A normal aggregate is cancelled correctly.

Related: #759 item 2 (client_connection_check_interval). These tests are also on the crash list in documentdb-local/functional-tests/config/ci_crash_tests.txt.

3. Reindex retry fails with "could not open relation with OID 0"

Repro:

  1. Run createIndexes with a unique-capable index, then collMod prepareUnique and collMod unique.
  2. Run collMod {index: {..., reindex: true}} with documentdb.indexBuildFailurePoint = 5 (post-processing).

What happens:

  • The first attempt logs Injected failure point 5 ... drop partial state and marks the build Failed.
  • Both retries then fail with Failure in post-processing index could not open relation with OID 0 and end Failed, although collMod returned ok.
  • The original index stays valid, so there is no data risk. But the reindex can never succeed, and the user isn't told.

The first failure drops the _ccnew index, and the retry still looks it up by name (create_indexes_background.c, the reindex post-processing). This cause is inferred.

4. New binary with an old catalog

We ran the 1.0-rc2 binary on a 0.109 catalog. This is the state right after a package or image upgrade, before ALTER EXTENSION documentdb UPDATE:

  • $group returns InternalError (PG: could not find an aggregate named "documentdb_api_internal.bsonfirstwithexpr").
  • Creating a hashed index fails with operator class "...documentdb_extended_rum_hashed_ops" does not exist, mapped to code 11 UserNotFound.
  • createUser with readWriteAnyDatabase + clusterAdmin is rejected with "Only readAnyDatabase or readWriteAnyDatabase+clusterAdmin are allowed built-in roles", which is exactly the combination requested.

After ALTER EXTENSION documentdb UPDATE everything works, and the data and all 11 indexes survived.

Expected: features that need a newer catalog fail with a clear "run ALTER EXTENSION documentdb UPDATE" message instead of InternalError or unrelated error codes. Neither the packages nor the container run that update today; see #771 (packaging) and #773 (documentdb-local).

Activity

  1. added
    documentdb-1.0
    engine
    on Oct 5, 2026
  2. guanzhousongmicrosoft commented on Nov 23, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    On main the documentdb-local image runs ALTER EXTENSION ... UPDATE at boot (53e5456), so the container no longer runs on an old catalog. Still open: a clear error instead of InternalError on an old catalog, items 1 and 2, and confirming whether a9ca0f7's catalog-lookup refresh fixes the reindex retry in item 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdocumentdb-1.0engineindexingquery

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions