{"record":{"id":"dcb3b83abd3aec9a","repo":"weaviate/weaviate","slug":"failed-to-preallocate-file-w","errorCode":null,"errorMessage":"failed to preallocate file: %w","messagePattern":"failed to preallocate file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cluster/replication/copier/copier.go","lineNumber":349,"sourceCode":"\t\ttmpPath := localFilePath + \".tmp\"\n\n\t\tif err := func() error {\n\t\t\tf, err := os.Create(tmpPath)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"open file %q for writing: %w\", tmpPath, err)\n\t\t\t}\n\t\t\teg := enterrors.NewErrorGroupWrapper(c.logger)\n\t\t\teg.SetLimit(_NUMCPU)\n\t\t\t// Drain writers before closing the FD: a late WriteAt against a\n\t\t\t// recycled descriptor would otherwise land on the wrong file.\n\t\t\tdefer func() {\n\t\t\t\t_ = eg.Wait()\n\t\t\t\tif f != nil {\n\t\t\t\t\t_ = f.Close()\n\t\t\t\t}\n\t\t\t}()\n\t\t\tif err := f.Truncate(meta.Size); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to preallocate file: %w\", err)\n\t\t\t}\n\n\t\t\tfor {\n\t\t\t\tchunk, err := stream.Recv()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to receive file chunk for %s: %w\", meta.FileName, err)\n\t\t\t\t}\n\t\t\t\tif len(chunk.Data) > 0 {\n\t\t\t\t\teg.Go(func() error {\n\t\t\t\t\t\t// Test-only: forces a deterministic WriteAt-after-Close window.\n\t\t\t\t\t\tif sleep := os.Getenv(\"WEAVIATE_TEST_DOWNLOAD_WRITE_SLEEP\"); sleep != \"\" {\n\t\t\t\t\t\t\tif d, err := time.ParseDuration(sleep); err == nil {\n\t\t\t\t\t\t\t\ttime.Sleep(d)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif _, err := f.WriteAt(chunk.Data, chunk.Offset); err != nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"writing chunk to file %q: %w\", tmpPath, err)\n\t\t\t\t\t\t}","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/cluster/replication/copier/copier.go#L331-L367","documentation":"Fired during replication stream copy when f.Truncate(meta.Size) cannot preallocate the local .tmp file to the expected shard segment size reported by the source node. Indicates local disk failure (out of space, quota, I/O error) or an invalid size, aborting the shard copy before data transfer.","triggerScenarios":"Truncate fails on a full filesystem (cannot grow the file to meta.Size), on filesystems that disallow growing via truncate beyond limits (e.g. some FUSE/network mounts), when meta.Size is negative/corrupt, or when the fd became invalid.","commonSituations":"Very large shard files on a volume that is nearly full; downloading to NFS/CIFS/glusterfs mounts with size limits; corrupted metadata returned by a buggy/mismatched source node version.","solutions":["Free disk space — the volume must have at least meta.Size bytes free for the .tmp file.","Avoid network filesystems (NFS/FUSE) for PERSISTENCE_DATA_PATH; use local SSD storage.","If meta.Size is implausible, verify source and target run compatible Weaviate versions and re-initiate replication.","Retry after resolving; the .tmp file is removed on failure so no cleanup is needed."],"exampleFix":"// before: volume too small for the shard file\n$ df -h /var/lib/weaviate  # 2GB free, file is 5GB\n// after: expand the volume or move PERSISTENCE_DATA_PATH to larger storage\n$ kubectl patch pvc weaviate-data -p '{\"spec\":{\"resources\":{\"requests\":{\"storage\":\"200Gi\"}}}}'","handlingStrategy":"validation","validationCode":"var st syscall.Statfs_t\nif err := syscall.Statfs(shardDir, &st); err == nil {\n    free := st.Bavail * uint64(st.Bsize)\n    if free < uint64(meta.Size)+margin {\n        return fmt.Errorf(\"only %d bytes free, need %d\", free, meta.Size)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check free space before each large file download, not just before the operation.","Use local block storage, not NFS/FUSE, for the data path.","Pin source and target nodes to compatible Weaviate versions so metadata sizes are trustworthy.","Alert on disk usage above 80% to leave headroom for replication tmp files."],"tags":["filesystem","disk","replication","enospc"],"backgroundTag":"disk-full-enospc","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}