{"record":{"id":"c7a8282c153d1be1","repo":"thanos-io/thanos","slug":"create-working-compact-directory","errorCode":null,"errorMessage":"create working compact directory","messagePattern":"create working compact directory","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/compact.go","lineNumber":356,"sourceCode":"\n\tdefault:\n\t\treturn errors.Errorf(\"unsupported deduplication func, got %s\", conf.dedupFunc)\n\t}\n\n\t// Instantiate the compactor with different time slices. Timestamps in TSDB\n\t// are in milliseconds.\n\tcomp, err := tsdb.NewLeveledCompactor(ctx, reg, logutil.GoKitLogToSlog(logger), levels, downsample.NewPool(), mergeFunc)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"create compactor\")\n\t}\n\n\tvar (\n\t\tcompactDir      = path.Join(conf.dataDir, \"compact\")\n\t\tdownsamplingDir = path.Join(conf.dataDir, \"downsample\")\n\t)\n\n\tif err := os.MkdirAll(compactDir, os.ModePerm); err != nil {\n\t\treturn errors.Wrap(err, \"create working compact directory\")\n\t}\n\n\tif err := os.MkdirAll(downsamplingDir, os.ModePerm); err != nil {\n\t\treturn errors.Wrap(err, \"create working downsample directory\")\n\t}\n\n\tgrouper := compact.NewDefaultGrouper(\n\t\tlogger,\n\t\tinsBkt,\n\t\tconf.acceptMalformedIndex,\n\t\tenableVerticalCompaction,\n\t\treg,\n\t\tcompactMetrics.blocksMarked.WithLabelValues(metadata.DeletionMarkFilename, \"\"),\n\t\tcompactMetrics.garbageCollectedBlocks,\n\t\tcompactMetrics.blocksMarked.WithLabelValues(metadata.NoCompactMarkFilename, metadata.OutOfOrderChunksNoCompactReason),\n\t\tmetadata.HashFunc(conf.hashFunc),\n\t\tconf.blockFilesConcurrency,\n\t\tconf.compactBlocksFetchConcurrency,","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/compact.go#L338-L374","documentation":"runCompact creates the local working directory <dataDir>/compact via os.MkdirAll and wraps any OS error with this message. MkdirAll fails if the path cannot be created: permission denied, parent is a file, or disk errors.","triggerScenarios":"os.MkdirAll(compactDir, os.ModePerm) returns an error because dataDir doesn't exist or isn't writable, a file already occupies the path, or the filesystem is read-only/full.","commonSituations":"Mounting an emptyDir/PV with wrong permissions; --data-dir pointing to a path owned by root while compact runs as non-root; disk full on the node.","solutions":["Ensure the data dir exists and is writable by the thanos process user (chown/chmod).","Check that <dataDir>/compact is not a regular file and remove it if so.","Verify disk space and that the volume is mounted read-write."],"exampleFix":"// before\nmkdir: cannot create directory '/data/compact': Permission denied\n// after\nmkdir -p /data && chown thanos:thanos /data","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(dataDir, 0o755); err != nil {\n    return fmt.Errorf(\"cannot prepare data-dir %q: %w\", dataDir, err)\n}","typeGuard":null,"tryCatchPattern":"if err := runCompact(...); err != nil {\n    if strings.Contains(err.Error(), \"create working compact directory\") {\n        logger.Error(err, \"dataDir unusable; check permissions, mount and free space\")\n    }\n    return err\n}","preventionTips":["Create and chown the data dir before the process starts (init container/entrypoint)","Ensure the volume is mounted read-write with enough free space","Never point --data-dir at a path occupied by a regular file"],"tags":["filesystem","permissions","startup"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}