{"record":{"id":"62df01137a17c652","repo":"influxdata/influxdb","slug":"existing-database-should-be-updated","errorCode":null,"errorMessage":"existing database should be updated","messagePattern":"existing database should be updated","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"influxdb3_catalog/src/catalog/versions/v2.rs","lineNumber":1904,"sourceCode":"                    if needs_update {\n                        // Update the token in the repository\n                        self.tokens\n                            .update_token(token_id, (*updated_token).clone())\n                            .expect(\"token to be updated\");\n                    }\n                }\n            }\n        }\n\n        // Now proceed with the normal database batch processing\n        if let Some(db) = self.databases.get_by_id(&database_batch.database_id) {\n            let Some(new_db) = DatabaseSchema::new_if_updated_from_batch(&db, database_batch)?\n            else {\n                return Ok(false);\n            };\n            self.databases\n                .update(db.id, new_db)\n                .expect(\"existing database should be updated\");\n        } else {\n            let new_db = DatabaseSchema::new_from_batch(database_batch)?;\n            self.databases\n                .insert(new_db.id, new_db)\n                .expect(\"new database should be inserted\");\n        };\n        Ok(true)\n    }\n\n    fn apply_delete_batch(&mut self, delete_batch: &DeleteBatch) -> Result<bool> {\n        let mut updated = false;\n        for op in &delete_batch.ops {\n            match op {\n                DeleteOp::DeleteDatabase(db_id) => {\n                    let Some(mut db_schema) = self.databases.get_by_id(db_id) else {\n                        continue;\n                    };\n","sourceCodeStart":1886,"sourceCodeEnd":1922,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_catalog/src/catalog/versions/v2.rs#L1886-L1922","documentation":"A panic from `.expect()` when applying a database batch. `DatabaseSchema::new_if_updated_from_batch` returned Some(new_db), meaning an update was detected, but `self.databases.update()` failed to find the existing database by id — the repository lost the entry the branch logic assumed. Its sibling insert path panics with \"new database should be inserted\" for the analogous insert failure.","triggerScenarios":"Replaying a database batch whose db.id exists per the new_if_updated_from_batch check but is missing from the databases repository at update time; concurrent database deletion during replay; for the insert variant, a database with the same id already present.","commonSituations":"Overlapping WAL/snapshot replay applying a batch twice, concurrent DROP DATABASE racing with writes to the same database, or corruption of the in-memory catalog.","solutions":["Ensure single-writer semantics for catalog batches; concurrent mutation breaks get-then-update assumptions.","Check snapshot/WAL replay boundaries for double application of the same batch.","Restore catalog from a consistent backup if database entries are missing.","Replace expects with explicit error mapping so a corrupt replay surfaces as a recoverable catalog error."],"exampleFix":"// before\nself.databases\n    .update(db.id, new_db)\n    .expect(\"existing database should be updated\");\n// after\nself.databases\n    .update(db.id, new_db)\n    .unwrap_or_else(|| panic!(\n        \"database {} detected as update but missing from repository\",\n        db.id\n    ));","handlingStrategy":"validation","validationCode":"// verify the database still exists before update\nif databases.get_by_id(db.id).is_none() { /* treat as insert or surface a catalog error */ }","typeGuard":"fn db_exists(dbs: &Databases, id: DbId) -> bool { dbs.get_by_id(id).is_some() }","tryCatchPattern":null,"preventionTips":["Never run DROP DATABASE concurrently with batch replay","Keep single-writer semantics for the databases repository","Check snapshot/WAL overlap to prevent double-applied batches","Map repository update failures to catalog errors instead of expect()"],"tags":["panic","catalog","database-schema","replay"],"backgroundTag":"internal-invariant-violation","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"}