{"record":{"id":"5a1b82ae6fc79df7","repo":"SonarSource/sonarqube","slug":"measure-export-failed-after-processing-d-measures","errorCode":null,"errorMessage":"Measure Export failed after processing %d measures successfully","messagePattern":"Measure Export failed after processing (.+?) measures successfully","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStep.java","lineNumber":84,"sourceCode":"  @Override\n  public void execute(Context context) {\n    long count = 0L;\n    try (\n      StreamWriter<ProjectDump.Measure> output = dumpWriter.newStreamWriter(DumpElement.MEASURES);\n      DbSession dbSession = dbClient.openSession(false);\n      PreparedStatement stmt = createSelectStatement(dbSession);\n      ResultSet rs = stmt.executeQuery()) {\n\n      ProjectDump.Measure.Builder measureBuilder = ProjectDump.Measure.newBuilder();\n      ProjectDump.DoubleValue.Builder doubleBuilder = ProjectDump.DoubleValue.newBuilder();\n      while (rs.next()) {\n        ProjectDump.Measure measure = convertToMeasure(rs, measureBuilder, doubleBuilder);\n        output.write(measure);\n        count++;\n      }\n      LoggerFactory.getLogger(getClass()).debug(\"{} measures exported\", count);\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Measure Export failed after processing %d measures successfully\", count), e);\n    }\n  }\n\n  private PreparedStatement createSelectStatement(DbSession dbSession) throws SQLException {\n    PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(dbSession, QUERY);\n    try {\n      stmt.setString(1, projectHolder.projectDto().getUuid());\n      stmt.setBoolean(2, true);\n      stmt.setString(3, SnapshotDto.STATUS_PROCESSED);\n      stmt.setBoolean(4, true);\n      stmt.setBoolean(5, true);\n      return stmt;\n    } catch (Exception t) {\n      DatabaseUtils.closeQuietly(stmt);\n      throw t;\n    }\n  }\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStep.java#L66-L102","documentation":"ExportMeasuresStep.execute() scrolls through all measures of a project and writes them to the export output, counting successes. If any exception occurs mid-export (DB read error, serialization failure, write failure), it wraps it in an IllegalStateException that reports how many measures were already exported successfully before the failure. It is thrown because a partial export cannot be resumed and the compute-engine task must fail loudly.","triggerScenarios":"Any exception thrown while iterating the streaming measure ResultSet or calling output.write(measure) inside execute() — e.g. SQLException from createSelectStatement/scrolling cursor, protobuf conversion failure, or I/O error writing to the dump output.","commonSituations":"Database connection drops or times out during a long scrolling select on a large project; disk full on the CE worker while writing the dump; a corrupted or incompatible measure row that fails protobuf conversion during export.","solutions":["Inspect the wrapped cause exception (getCause()) to find the root failure and fix that issue","Verify database connectivity and increase DB/socket timeouts for long-running export tasks","Check free disk space on the CE worker where the project dump is written","Re-run the export after remediation; the count tells how far it got, but the export restarts from zero"],"exampleFix":"// before\ncatch (Exception e) {\n  throw new IllegalStateException(format(\"Measure Export failed after processing %d measures successfully\", count), e);\n}\n// after\n// keep the IllegalStateException but log/inspect e.getCause():\ncatch (Exception e) {\n  LOGGER.error(\"Measure export failed at count {} due to {}\", count, e.getCause(), e);\n  throw new IllegalStateException(format(\"Measure Export failed after processing %d measures successfully\", count), e);\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight before export\ntry (DbSession db = dbClient.openSession(false)) {\n  long cnt = dbClient.getMeasureDao().countByComponentUuid(db, componentUuid);\n  if (cnt < 0) throw new IllegalStateException(\"DB unavailable for export\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  exportMeasuresStep.execute(context);\n} catch (IllegalStateException e) {\n  LOGGER.error(\"Measure export failed after N measures; cause: {}\", e.getCause(), e);\n  // treat as task failure; do not retry blindly without fixing the cause\n}","preventionTips":["Ensure stable DB connectivity and generous timeouts for long exports","Monitor CE worker disk space before scheduling large exports","Test exports against copies of large projects to catch row-level conversion issues"],"tags":["database","export","compute-engine","io"],"backgroundTag":"database-query-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}