{"record":{"id":"de31079cf8a30025","repo":"influxdata/influxdb","slug":"database-should-exist-by-id","errorCode":null,"errorMessage":"database should exist by id","messagePattern":"database should exist by id","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"influxdb3_catalog/src/catalog/versions/v2/update.rs","lineNumber":1858,"sourceCode":"impl DatabaseCatalogTransaction {\n    pub fn sequence_number(&self) -> CatalogSequenceNumber {\n        self.catalog_sequence\n    }\n\n    /// Apply the current transaction to the [super::InnerCatalog] and return the updated [DatabaseSchema].\n    ///\n    /// # NOTE\n    ///\n    /// Used for testing purposes.\n    pub fn apply_to_inner(&self, inner: &mut super::InnerCatalog) -> Result<Arc<DatabaseSchema>> {\n        let (catalog_batch, sequence) = self.clone().catalog_batch();\n        inner\n            .apply_catalog_batch(&catalog_batch, sequence, None)\n            .map(|_| {\n                inner\n                    .databases\n                    .get_by_id(&self.database_schema.id)\n                    .expect(\"database should exist by id\")\n            })\n    }\n\n    /// Check if the transaction is empty, meaning it has no pending operations.\n    fn is_empty(&self) -> bool {\n        self.ops.is_empty()\n            && self.tables.resource_iter().all(|tx| {\n                tx.column_definitions.is_empty() && tx.field_family_definitions.is_empty()\n            })\n    }\n\n    fn catalog_batch(self) -> (CatalogBatch, CatalogSequenceNumber) {\n        let s = self.catalog_sequence;\n        (self.into(), s)\n    }\n\n    /// Check if a table exists by its name in the current transaction or in the database schema.\n    fn table_exists_by_name(&self, name: &str) -> bool {","sourceCodeStart":1840,"sourceCodeEnd":1876,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_catalog/src/catalog/versions/v2/update.rs#L1840-L1876","documentation":"Panic from `.expect(\"database should exist by id\")` on `inner.databases.get_by_id(&self.database_schema.id)` inside the commit path of a CatalogTransaction (after `apply_catalog_batch` succeeds in versions/v2/update.rs). The code assumes that a successfully applied batch referencing this database leaves the database present in the catalog's databases map; a None result means the apply silently dropped or failed to register the database — an unrecoverable internal inconsistency.","triggerScenarios":"Committing a database-scoped catalog transaction (write_database / commit) where apply_catalog_batch succeeds but the databases map lacks `self.database_schema.id` — e.g. the batch deleted the database, applied ops out of order, or the database creation op was filtered out during replay.","commonSituations":"Catalog replay where a DROP DATABASE op precedes a pending transaction's ops; snapshots restored with the database missing; concurrent commits where one deletes while another commits writes; bugs in apply_catalog_batch's upsert logic.","solutions":["Check the catalog log for a delete-database op with a sequence number between the transaction's start and commit; re-order or drop the conflicting transaction.","Verify apply_catalog_batch's handling of database upserts for this sequence range; patch or upgrade to a version fixing the replay bug.","Restore the catalog from a snapshot that still contains the database.","Capture the sequence numbers and failing batch and file an upstream issue — this indicates a serious catalog consistency bug."],"exampleFix":"// before\ninner.apply_catalog_batch(&catalog_batch, sequence, None).map(|_| {\n    inner.databases.get_by_id(&self.database_schema.id).expect(\"database should exist by id\")\n})\n// after\ninner.apply_catalog_batch(&catalog_batch, sequence, None).and_then(|_| {\n    inner.databases.get_by_id(&self.database_schema.id)\n        .ok_or_else(|| Error::DatabaseMissingAfterCommit { id: self.database_schema.id })\n})","handlingStrategy":"try-catch","validationCode":"// Before committing, confirm the database still exists in the catalog\nif catalog.databases().get_by_id(&db_schema.id).is_none() {\n    return Err(\"database was dropped; aborting stale transaction\");\n}","typeGuard":null,"tryCatchPattern":"// Wrap commit and handle the panic via catch_unwind at the replay boundary\nlet result = std::panic::catch_unwind(AssertUnwindSafe(|| tx.commit()));\nmatch result {\n    Ok(Ok(db)) => Ok(db),\n    Ok(Err(e)) => Err(e),\n    Err(_panic) => Err(\"catalog consistency failure during commit; restore from snapshot\".into()),\n}","preventionTips":["Serialize database drop and write transactions; never run both concurrently.","Track sequence numbers so a pending transaction is aborted if a drop-database op lands first.","Restore catalogs only from snapshots where the referenced database exists.","Monitor for this panic in replay code paths — it indicates a serious consistency bug to report upstream."],"tags":["influxdb3","catalog","panic","database","missing-entity"],"backgroundTag":"entity-not-found","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}