{"record":{"id":"47a6d32847cb25e3","repo":"juicedata/juicefs","slug":"compact-d-s-error-s","errorCode":null,"errorMessage":"compact [%d:%s] error: %s","messagePattern":"compact \\[(.+?):(.+?)\\] error: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compact.go","lineNumber":123,"sourceCode":"\tif err != nil {\n\t\tlogger.Fatalf(\"write message: %s\", err)\n\t}\n\n\tprogress := utils.NewProgress(false)\n\tbar := progress.AddCountBar(\"Compacted chunks\", 0)\n\t_, errno := readProgress(f, func(totalChunks, currChunks uint64) {\n\t\tbar.SetTotal(int64(totalChunks))\n\t\tbar.SetCurrent(int64(currChunks))\n\t})\n\n\tbar.Done()\n\tprogress.Done()\n\n\tif errno == syscall.EINVAL {\n\t\tlogger.Fatalf(\"compact is not supported, please upgrade and mount again\")\n\t}\n\tif errno != 0 {\n\t\treturn fmt.Errorf(\"compact [%d:%s] error: %s\", inode, path, errno)\n\t}\n\n\tlogger.Infof(\"compact [%d:%q] success.\", inode, path)\n\treturn nil\n}\n","sourceCodeStart":105,"sourceCodeEnd":129,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/compact.go#L105-L129","documentation":"doCompact wraps the errno returned by the metadata engine's Compact() call (issued via the internal fs layer). A non-zero errno other than EINVAL is reported as 'compact [inode:path] error: %s', meaning the compact operation failed at the metadata layer. EINVAL specifically is caught earlier and prompts an upgrade, so any message here is an unexpected engine-level failure.","triggerScenarios":"Running `juicefs compact <path>` on a mounted volume when the metadata engine's Compact call returns a non-zero errno (e.g. ENOENT because the inode no longer exists, EACCES, or engine-specific failures).","commonSituations":"Compacting a file deleted concurrently by another client; running compact against a metadata engine version lacking compact support in a way other than EINVAL; metadata backend connectivity issues mid-operation.","solutions":["Re-check the target file still exists and re-run `juicefs compact`","Check metadata engine connectivity/health (redis-cli ping, DB logs)","Confirm the mounted client and metadata engine versions both support compact; upgrade juicefs if needed","Inspect logger output just above the error for the underlying engine error detail"],"exampleFix":"// before\nerr := doCompact(...) // prints 'compact [i:pkg] error: ...'\n// after\nif _, serr := os.Stat(mountPoint + \"/\" + path); serr != nil { log.Fatalf(\"target missing: %v\", serr) }\nerr := doCompact(...)","handlingStrategy":"try-catch","validationCode":"test -e /mnt/jfs/$TARGET_PATH && echo ok || echo 'target missing'","typeGuard":null,"tryCatchPattern":"if err := doCompact(...); err != nil {\n    if strings.Contains(err.Error(), \"not supported\") { /* upgrade path */ }\n    else { log.Printf(\"compact failed, retry later: %v\", err) }\n}","preventionTips":["Verify the file exists before compacting","Keep client and metadata engine versions in sync","Monitor metadata backend health"],"tags":["metadata","compact","cli"],"backgroundTag":"database-query-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}