{"record":{"id":"2e3a107cc71051bd","repo":"apache/druid","slug":"failed-to-publish-schemas-s-to-db-for-datasource","errorCode":null,"errorMessage":"Failed to publish schemas[%s] to DB for datasource[%s] and version[%s]","messagePattern":"Failed to publish schemas\\[(.+?)\\] to DB for datasource\\[(.+?)\\] and version\\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/src/main/java/org/apache/druid/segment/metadata/SegmentSchemaManager.java","lineNumber":272,"sourceCode":"                         .bind(\"payload\", jsonMapper.writeValueAsBytes(fingerprintSchemaPayloadMap.get(fingerprint)))\n                         .bind(\"used\", true)\n                         .bind(\"used_status_last_updated\", now)\n                         .bind(\"version\", version);\n      }\n      final int[] affectedRows = schemaInsertBatch.execute();\n      final List<String> failedInserts = new ArrayList<>();\n      for (int i = 0; i < partition.size(); ++i) {\n        if (affectedRows[i] != 1) {\n          failedInserts.add(partition.get(i));\n        }\n      }\n      if (failedInserts.isEmpty()) {\n        log.info(\n            \"Published schemas [%s] to DB for datasource[%s] and version[%s].\",\n            partition, dataSource, version\n        );\n      } else {\n        throw new ISE(\n            \"Failed to publish schemas[%s] to DB for datasource[%s] and version[%s]\",\n            failedInserts, dataSource, version\n        );\n      }\n    }\n  }\n\n  /**\n   * Update segment with schemaFingerprint and numRows information.\n   */\n  public void updateSegmentWithSchemaInformation(\n      final Handle handle,\n      final List<SegmentSchemaMetadataPlus> batch,\n      final DateTime updateTime\n  )\n  {\n    log.debug(\"Updating segment with schemaFingerprint and numRows information: [%s].\", batch);\n","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/segment/metadata/SegmentSchemaManager.java#L254-L290","documentation":"SegmentSchemaManager.publishSchemasToDB inserts segment schema records in batches into the metadata store; any row whose insert failed is collected in failedInserts. If any insert in a partition fails, this IllegalStateException is thrown to abort persistSchemaAndUpdateSegmentsTable, since publishing schema metadata partially would leave the segments table inconsistent with the schema table.","triggerScenarios":"Calling persistSchemaAndUpdateSegmentsTable (typically from indexing-task cleanup/publish paths) when a batch insert into druid_segment_schema via the metadata storage connector fails for one or more rows — e.g. metadata DB outage, connection pool exhaustion, constraint violation, or oversized schema payload.","commonSituations":"Metadata database unreachable or failing over during segment publish; schema rows too large for the configured column type; duplicate/unique-key conflicts after task retries; network blips between Druid and the metadata store.","solutions":["Check metadata-store connectivity and logs from the metadata storage connector for the root SQL error immediately preceding this ISE","Retry persistSchemaAndUpdateSegmentsTable — inserts are batched and the operation is designed to be retried after transient DB failures","Inspect the failedInserts list in the message to identify which schemas failed and check for constraint/key conflicts on those segment IDs","Verify druid.metadata.storage.connector configuration and DB schema migrations are current for the schema tables"],"exampleFix":"// before\nsegmentSchemaManager.persistSchemaAndUpdateSegmentsTable(segments);\n// after\ntry {\n  segmentSchemaManager.persistSchemaAndUpdateSegmentsTable(segments);\n} catch (ISE e) {\n  log.warn(e, \"Schema publish failed; will retry after metadata store recovers\");\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Verify metadata store reachability before publishing\ntry (MetadataStorageConnector conn = connectorFactory.getConnector()) {\n  conn.lookup(CONFIG_TABLE_KEY); // throws if DB is unreachable\n}","typeGuard":null,"tryCatchPattern":"try {\n  manager.persistSchemaAndUpdateSegmentsTable(segments);\n} catch (ISE e) {\n  log.warn(e, \"Transient schema publish failure; scheduling retry\");\n  scheduleRetry();\n}","preventionTips":["Monitor metadata-store health and connection pool saturation","Keep schema payloads within DB column size limits","Retry publish operations on transient DB failures rather than failing the task permanently"],"tags":["database","metadata-store","ingestion"],"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"}