{"record":{"id":"db4224906dbf77ee","repo":"juicedata/juicefs","slug":"writechunk-s-s","errorCode":null,"errorMessage":"writechunk %s: %s","messagePattern":"writechunk (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/mdtest.go","lineNumber":77,"sourceCode":"\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc createFile(jfs *fs.FileSystem, bar *utils.Bar, np int, root string, d int, width, files, bytes int) error {\n\tm := jfs.Meta()\n\tfor i := 0; i < files; i++ {\n\t\tfn := path.Join(root, fmt.Sprintf(\"file.mdtest.%d.%d\", np, i))\n\t\tf, err := jfs.Create(ctx, fn, 0666, umask)\n\t\tif err != 0 {\n\t\t\treturn fmt.Errorf(\"create %s: %s\", fn, err)\n\t\t}\n\t\tif bytes > 0 {\n\t\t\tfor indx := 0; indx*meta.ChunkSize < bytes; indx++ {\n\t\t\t\tvar id uint64\n\t\t\t\tif st := m.NewSlice(ctx, &id); st != 0 {\n\t\t\t\t\treturn fmt.Errorf(\"writechunk %s: %s\", fn, st)\n\t\t\t\t}\n\t\t\t\tsize := meta.ChunkSize\n\t\t\t\tif bytes < (indx+1)*meta.ChunkSize {\n\t\t\t\t\tsize = bytes - indx*meta.ChunkSize\n\t\t\t\t}\n\t\t\t\tif st := m.Write(ctx, f.Inode(), uint32(indx), 0, meta.Slice{Id: id, Size: uint32(size), Len: uint32(size)}, time.Now()); st != 0 {\n\t\t\t\t\treturn fmt.Errorf(\"writeend %s: %s\", fn, st)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tf.Close(ctx)\n\t\tbar.Increment()\n\t}\n\tif d > 0 {\n\t\tdirs := make([]int, width)\n\t\tfor i := 0; i < width; i++ {\n\t\t\tdirs[i] = i\n\t\t}","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/mdtest.go#L59-L95","documentation":"Reported when m.NewSlice() — the metadata call that allocates a new chunk/slice ID before writing file data — returns a non-zero errno. NewSlice increments the `nextChunk` counter in the metadata engine (pkg/meta/base.go:2150); the error is the errno from that counter increment (backend unavailable, write failure, serialization error). It appears as `writechunk <file>: <errno>` and only occurs when mdtest runs with -write > 0.","triggerScenarios":"`juicefs mdtest -write N` where the metadata backend fails on the INCR/counter update for nextChunk: Redis connection dropped, MySQL/SQLite write error, TiKV/etcd increment failure, or backend timeout under heavy multi-thread load.","commonSituations":"Large parallel mdtest (-threads high) saturating the metadata engine; Redis maxmemory reached so INCR fails; transient network partition between client and Redis/SQL backend mid-run; SQLite database locked by another process.","solutions":["Check the metadata backend health and connectivity at the moment of failure (ping Redis, check MySQL/etcd/TiKV logs)","Reduce --threads to lower concurrent pressure on the nextChunk counter","If Redis: raise maxmemory or clear eviction pressure; if SQLite: ensure no other process holds the db and the disk isn't full","Retry the run; slice-ID allocation is transiently retriable once the backend recovers","Verify the counter key wasn't manually deleted/corrupted (`juicefs fsck` can help validate metadata)"],"exampleFix":"// before\n$ juicefs mdtest --threads 64 -write 1048576 redis://localhost /t  # backend overloaded\n// after\n$ juicefs mdtest --threads 8 -write 1048576 redis://localhost /t","handlingStrategy":"retry","validationCode":"// verify meta backend is responsive before a write benchmark\nif err := m.Ping(meta.Background()); err != 0 {\n    logger.Fatalf(\"meta engine unreachable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"// retry transient slice-id allocation failures\nfor i := 0; i < 3; i++ {\n    if st := m.NewSlice(ctx, &id); st == 0 {\n        break\n    } else if i == 2 {\n        return fmt.Errorf(\"writechunk %s: %s\", fn, st)\n    }\n    time.Sleep(100 * time.Millisecond)\n}","preventionTips":["Right-size --threads so the metadata backend isn't saturated","Monitor Redis maxmemory / MySQL disk space during benchmarks","Watch meta engine latency metrics; back off when counters increment slowly","Avoid manual edits to meta counter keys (nextChunk)"],"tags":["metadata","write","slice-allocation","mdtest"],"backgroundTag":"database-write-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}