{"record":{"id":"a406baba45a89b8e","repo":"influxdata/influxdb","slug":"database-not-found-for-trigger-key","errorCode":null,"errorMessage":"database not found for trigger {key:?}","messagePattern":"database not found for trigger (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"influxdb3_processing_engine/src/worker/local.rs","lineNumber":188,"sourceCode":"    }\n\n    fn scheduler_for(&self, scheduler_node_id: &str) -> Option<Arc<dyn TriggerScheduler>> {\n        let mut schedulers = self.schedulers.lock();\n        let scheduler = schedulers.get(scheduler_node_id).and_then(Weak::upgrade);\n        if scheduler.is_none() {\n            schedulers.remove(scheduler_node_id);\n        }\n        scheduler\n    }\n\n    async fn plugin_for_key(\n        &self,\n        key: TriggerKey,\n    ) -> Result<Arc<TriggerPlugin>, TriggerExecutionError> {\n        let db_schema = self\n            .catalog\n            .db_schema_by_id(&key.db_id)\n            .ok_or_else(|| anyhow!(\"database not found for trigger {key:?}\"))?;\n        let trigger_definition = db_schema\n            .processing_engine_triggers\n            .get_by_id(&key.trigger_id)\n            .ok_or_else(|| anyhow!(\"trigger not found: {key:?}\"))?;\n        let db_name = db_schema.name.to_string();\n\n        let load_generation = {\n            let mut plugins = self.plugins.lock();\n            let slot = plugins.entry(key).or_insert_with(|| self.new_plugin_slot());\n            if let Some(plugin) = &slot.plugin\n                && plugin.matches(&db_name, &trigger_definition)\n            {\n                return Ok(Arc::clone(plugin));\n            }\n            slot.generation\n        };\n\n        let plugin_code = Arc::new(","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_processing_engine/src/worker/local.rs#L170-L206","documentation":"Raised by `plugin_for_key` when the catalog has no database schema for the `db_id` stored in the trigger key. The trigger references a database that no longer exists (or has not been loaded into this node's catalog), so the plugin cannot be resolved.","triggerScenarios":"`execute_once` (scheduled/WAL trigger run) or `load_plugin_for_test` with a `TriggerKey` whose `db_id` is absent from `self.catalog.db_schema_by_id` — typically after the database was dropped while the trigger still exists, or a stale key from a pre-restart catalog.","commonSituations":"Deleting a database with an active trigger and the trigger record lingering; restoring/partial catalog load where triggers survived but the DB didn't; test harness passing a fabricated TriggerKey.","solutions":["Drop or recreate the orphaned trigger: `DROP TRIGGER <name>` (or recreate the missing database).","Verify the database exists with `SHOW DATABASES` and that the trigger's DB name is spelled correctly.","Restart/re-sync so the catalog is fully loaded on this node.","In tests, build the TriggerKey from an actual catalog lookup rather than hand-constructed IDs."],"exampleFix":"// before (fabricated key in test)\nlet key = TriggerKey { db_id: DatabaseId::new(), trigger_id: TriggerId::new() };\n// after\nlet db = catalog.db_schema(\"mydb\").unwrap();\nlet trig = db.processing_engine_triggers.get_by_name(\"my_trigger\").unwrap();\nlet key = TriggerKey { db_id: db.id, trigger_id: trig.id };","handlingStrategy":"validation","validationCode":"// Resolve the key from a live catalog instead of constructing IDs by hand\nlet db_schema = catalog.db_schema_by_id(&key.db_id)\n    .ok_or_else(|| anyhow!(\"db {} missing; drop orphaned trigger\", key.db_id))?;","typeGuard":null,"tryCatchPattern":"// Caller\nmatch worker.load_plugin_for_test(key) {\n    Err(e) if e.to_string().contains(\"database not found for trigger\") => {\n        // recover: drop the orphaned trigger or recreate the database, then retry\n    }\n    other => other?,\n}","preventionTips":["Drop triggers before dropping their database","Run `SHOW DATABASES` / catalog reconciliation after restores","Build TriggerKeys from catalog lookups in tests"],"tags":["catalog","triggers","resource-not-found","plugins"],"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"}