{"record":{"id":"0795f0c835d096ce","repo":"prestodb/presto","slug":"could-not-save-table-statistics-data-0795f0","errorCode":null,"errorMessage":"Could not save table statistics data","messagePattern":"Could not save table statistics data","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-tpch/src/main/java/com/facebook/presto/tpch/statistics/TableStatisticsDataRepository.java","lineNumber":68,"sourceCode":"        String filename = tableStatisticsDataFilename(table, partitionColumn, partitionValue);\n        Path path = Paths.get(\"presto-tpch\", \"src\", \"main\", \"resources\", \"tpch\", \"statistics\", schemaName, filename + \".json\");\n        writeStatistics(path, statisticsData);\n    }\n\n    private void writeStatistics(Path path, TableStatisticsData tableStatisticsData)\n    {\n        File file = path.toFile();\n        file.getParentFile().mkdirs();\n        try {\n            objectMapper\n                    .writerWithDefaultPrettyPrinter()\n                    .writeValue(file, tableStatisticsData);\n            try (BufferedWriter fileWriter = Files.newBufferedWriter(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {\n                fileWriter.append('\\n');\n            }\n        }\n        catch (IOException e) {\n            throw new RuntimeException(\"Could not save table statistics data\", e);\n        }\n    }\n\n    public Optional<TableStatisticsData> load(String schemaName, TpchTable<?> table, Optional<TpchColumn<?>> partitionColumn, Optional<String> partitionValue)\n    {\n        String filename = tableStatisticsDataFilename(table, partitionColumn, partitionValue);\n        String resourcePath = \"/tpch/statistics/\" + schemaName + \"/\" + filename + \".json\";\n        URL resource = getClass().getResource(resourcePath);\n        if (resource == null) {\n            return Optional.empty();\n        }\n        try {\n            return Optional.of(objectMapper.readValue(resource, TableStatisticsData.class));\n        }\n        catch (Exception e) {\n            throw new RuntimeException(format(\"Failed to parse stats from resource [%s]\", resourcePath), e);\n        }\n    }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-tpch/src/main/java/com/facebook/presto/tpch/statistics/TableStatisticsDataRepository.java#L50-L86","documentation":"TableStatisticsDataRepository.writeStatistics serializes TableStatisticsData to JSON via ObjectMapper and writes it to a file in the statistics directory. Any IOException during the write is wrapped in a RuntimeException with this message. It indicates the TPCH statistics cache could not be persisted to disk.","triggerScenarios":"Calling save(schemaName, table, partitionColumn, partitionValue, statisticsData) when the target directory does not exist or is not writable, the disk is full, or the filesystem rejects the write.","commonSituations":"Statistics directory configured with wrong permissions or a read-only mount; disk full in a container; the stats directory was deleted while the connector was running; saving stats on NFS with transient I/O failures.","solutions":["Check that the configured statistics directory exists and the process has write permission; create it or fix permissions.","Verify free disk space and that the mount is not read-only.","Inspect the wrapped IOException (getCause) for the precise filesystem error.","Make statistics saving non-fatal or point the stats directory to a reliably writable location (e.g. local disk instead of NFS)."],"exampleFix":"// before\nthrow new RuntimeException(\"Could not save table statistics data\", e);\n// after\n// ensure dir exists before write\nFiles.createDirectories(file.getParentFile().toPath());\nthrow new RuntimeException(\"Could not save table statistics data to \" + file, e);","handlingStrategy":"try-catch","validationCode":"// before saving: verify the stats directory is writable\nPath dir = Paths.get(statisticsDirectory);\nif (!Files.isDirectory(dir) || !Files.isWritable(dir)) {\n    throw new IllegalStateException(\"Statistics directory missing or not writable: \" + dir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    repository.save(schemaName, table, partitionColumn, partitionValue, stats);\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof IOException) {\n        log.warn(e, \"Statistics persistence failed; continuing without caching\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Create the statistics directory at startup with correct permissions.","Monitor disk space on the coordinator node.","Point the stats directory at local writable storage rather than flaky network mounts.","Treat statistics caching as best-effort, not a hard requirement."],"tags":["tpch-connector","statistics","io","filesystem"],"backgroundTag":"file-write-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}