{"record":{"id":"c05b8ac86162a959","repo":"apache/druid","slug":"encountered-metadata-exception-for-task-s","errorCode":null,"errorMessage":"Encountered metadata exception for task [%s]","messagePattern":"Encountered metadata exception for task \\[(.+?)\\]","errorType":"exception","errorClass":"DruidException","httpStatus":null,"severity":"error","filePath":"indexing-service/src/main/java/org/apache/druid/metadata/SQLMetadataStorageActionHandler.java","lineNumber":191,"sourceCode":"      final String sql = StringUtils.format(\n          \"INSERT INTO %s (id, created_date, datasource, payload, type, group_id, active, status_payload) \"\n          + \"VALUES (:id, :created_date, :datasource, :payload, :type, :group_id, :active, :status_payload)\",\n          getEntryTable()\n      );\n      handle.createStatement(sql)\n            .bind(\"id\", entryId)\n            .bind(\"created_date\", timestamp.toString())\n            .bind(\"datasource\", dataSource)\n            .bind(\"payload\", jsonMapper.writeValueAsBytes(entry))\n            .bind(\"type\", type)\n            .bind(\"group_id\", groupId)\n            .bind(\"active\", active)\n            .bind(\"status_payload\", jsonMapper.writeValueAsBytes(status))\n            .execute();\n      return null;\n    }\n    catch (Throwable t) {\n      throw wrapInDruidException(entryId, t);\n    }\n  }\n\n  private boolean isTransientDruidException(Throwable t)\n  {\n    if (t instanceof CallbackFailedException) {\n      return isTransientDruidException(t.getCause());\n    } else if (t instanceof DruidException) {\n      return Boolean.parseBoolean(((DruidException) t).getContextValue(CONTEXT_KEY_IS_TRANSIENT));\n    } else {\n      return getConnector().isTransientException(t);\n    }\n  }\n\n  @Override\n  public boolean setStatus(final String entryId, final boolean active, final TaskStatus status)\n  {\n    return connector.retryWithHandle(","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/indexing-service/src/main/java/org/apache/druid/metadata/SQLMetadataStorageActionHandler.java#L173-L209","documentation":"An unexpected Throwable occurred while inserting a task/lock entry (and its status payload) into the metadata store, so SQLMetadataStorageActionHandler wraps it in a DruidException with 'Encountered metadata exception for task [%s]'. The underlying SQL or serialization failure is wrapped and classified (transient vs not) for retry decisions.","triggerScenarios":"insert → insertEntryWithHandle → statement execute failing: DB connection loss, constraint violation (duplicate entry id), table missing/locked, or serialization of the status payload failing inside the withHandle callback.","commonSituations":"Metadata DB outage or failover mid-task; duplicate task id resubmission hitting a unique key; misconfigured metadata storage credentials; long transaction timeouts under load.","solutions":["Inspect the wrapped cause in the DruidException/logs to find the root SQL error and fix it (connectivity, credentials, schema).","If transient (connection loss), retry the task submission/action after the DB recovers — transient causes are retried automatically where supported.","Avoid resubmitting tasks with an existing id; check task status first or use a new id to prevent duplicate-key failures."],"exampleFix":"// before\noverlordClient.submitTask(sameIdSpec); // duplicate id -> metadata exception\n// after\nif (!taskClient.getStatus(sameId).isPresent()) {\n  overlordClient.submitTask(sameIdSpec);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  overlord.submitTask(spec);\n} catch (DruidException e) {\n  if (String.valueOf(e).contains(\"Encountered metadata exception for task\")) {\n    // inspect wrapped cause; retry with backoff only if transient (connection loss)\n  }\n}","preventionTips":["Keep the metadata DB reachable and credentials valid","Never resubmit a task id that already exists — check status first","Monitor metadata-store health alerts","Size the metadata DB for peak task-submission load"],"tags":["metadata-store","sql","task-management","database-write-failed"],"backgroundTag":"database-write-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}