{"record":{"id":"06f1c5b80ab0d1fa","repo":"juicedata/juicefs","slug":"create-external-sorter-w","errorCode":null,"errorMessage":"create external sorter: %w","messagePattern":"create external sorter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/utils/extsort/sharded.go","lineNumber":80,"sourceCode":"\tinput := make(chan T, cfg.Threads*128)\n\tsorter, _, errCh := lanratextsort.Generic(\n\t\tinput,\n\t\tcodec.FromBytes,\n\t\tcodec.ToBytes,\n\t\tcodec.Compare,\n\t\t&lanratextsort.Config{\n\t\t\tChunkSize:          defaultChunkSize,\n\t\t\tNumWorkers:         cfg.Threads,\n\t\t\tChanBuffSize:       cfg.Threads,\n\t\t\tSortedChanBuffSize: cfg.Threads * 32,\n\t\t\tTempFilesDir:       workDir,\n\t\t\tChecksum:           cfg.Checksum,\n\t\t},\n\t)\n\tif sorter == nil {\n\t\terr := <-errCh\n\t\t_ = os.RemoveAll(workDir)\n\t\treturn nil, fmt.Errorf(\"create external sorter: %w\", err)\n\t}\n\ts := &Sorter[T]{input: input, sorter: sorter, errCh: errCh, workDir: workDir}\n\tgo sorter.Sort(ctx)\n\treturn s, nil\n}\n\nfunc (s *Sorter[T]) Input() chan<- T {\n\treturn s.input\n}\n\nfunc (s *Sorter[T]) CloseInput() {\n\tclose(s.input)\n}\n\nfunc (s *Sorter[T]) Next(ctx context.Context) (T, bool, error) {\n\treturn s.sorter.Next(ctx)\n}\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/utils/extsort/sharded.go#L62-L98","documentation":"New builds a sharded external sorter for GC; if the underlying sorter library fails to construct (returned over errCh), the work directory is removed and 'create external sorter: %w' wraps the root cause. This indicates the external sort infrastructure could not be initialized, e.g. work-dir or writer failures.","triggerScenarios":"Calling New (via newGcExternalSorters during GC) when the sorter constructor fails — typically the temp/work directory cannot be created or the sorter factory returns an error.","commonSituations":"No space or permissions in the temp directory (TMPDIR misconfigured, read-only FS); excessive memory/disk limits in containers blocking sorter spawn.","solutions":["Read the wrapped root cause (%w) for the actual failure","Ensure the work/temp directory exists and is writable with sufficient space","Set TMPDIR to a larger writable location","Re-run GC after freeing disk space"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"if st, err := os.Stat(workDirParent); err != nil || !st.IsDir() || unix.Access(workDirParent, unix.W_OK) != nil { fail early }","typeGuard":null,"tryCatchPattern":"sorter, err := New(...); if err != nil { return fmt.Errorf(\"gc sorter init: %w\", err) } // inspect %w cause","preventionTips":["Keep adequate free space in TMPDIR","Run GC as a user with write access to temp dirs","Monitor disk usage before launching GC"],"tags":["gc","disk","sort"],"backgroundTag":"internal-invariant-violation","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"}