{"record":{"id":"810dbd47c61c6ffd","repo":"vitessio/vitess","slug":"unable-to-create-file-v","errorCode":null,"errorMessage":"unable to create file: %v","messagePattern":"unable to create file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/backupengine.go","lineNumber":764,"sourceCode":"\n\tlogger.Infof(\"Restore: reinit config file\")\n\tif err := mysqld.ReinitConfig(ctx, cnf); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\n// create restore state file\nfunc createStateFile(cnf *Mycnf) error {\n\t// if we start writing content to this file:\n\t// change RD_ONLY to RDWR\n\t// change Create to Open\n\t// rename func to openStateFile\n\t// change to return a *File\n\tfname := filepath.Join(cnf.TabletDir(), RestoreState)\n\tfd, err := os2.Create(fname)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to create file: %v\", err)\n\t}\n\tif err = fd.Close(); err != nil {\n\t\treturn fmt.Errorf(\"unable to close file: %v\", err)\n\t}\n\treturn nil\n}\n\n// delete restore state file\nfunc removeStateFile(cnf *Mycnf) error {\n\tfname := filepath.Join(cnf.TabletDir(), RestoreState)\n\tif err := os.Remove(fname); err != nil {\n\t\treturn fmt.Errorf(\"unable to delete file: %v\", err)\n\t}\n\treturn nil\n}\n\n// RestoreWasInterrupted tells us whether a previous restore\n// was interrupted and we are now retrying it","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/backupengine.go#L746-L782","documentation":"Thrown by createStateFile (restore preparation) when os2.Create fails on the restore state file at <tabletDir>/restore_state. The state file marks that a restore is in progress so a crash mid-restore can be detected; failure usually means the tablet directory is missing or the filesystem is unwritable.","triggerScenarios":"Restore flow calls createStateFile; the OS returns an error creating the file — tablet dir does not exist, wrong permissions/ownership, read-only filesystem, or disk full.","commonSituations":"Tablet directory deleted or never initialized before restore; mounted restore volume is read-only; running mysqlctl/vttablet as a user lacking write access to the tablet dir; ENOSPC on a full disk.","solutions":["Ensure the tablet directory exists and is writable by the process user (mkdir/chown/chmod as needed).","Read the wrapped OS error for the concrete cause (ENOENT, EACCES, EROFS, ENOSPC) and fix that specific condition.","Check disk space on the volume holding the tablet dir.","Verify the tablet_dir path configuration points at the intended location."],"exampleFix":"// before: dir missing -> \"unable to create file: open /vt/vtdataroot/vt_0000000100/restore_state: no such file or directory\"\nmkdir -p /vt/vtdataroot/vt_0000000100 && chown vitess:vitess /vt/vtdataroot/vt_0000000100\n// after: restore proceeds","handlingStrategy":"validation","validationCode":"dir := cnf.TabletDir()\nif st, err := os.Stat(dir); err != nil || !st.IsDir() {\n    return fmt.Errorf(\"tablet dir %s missing or not a directory\", dir)\n}\nprobe := filepath.Join(dir, \".write_probe\")\nif err := os.WriteFile(probe, nil, 0o644); err != nil {\n    return fmt.Errorf(\"tablet dir not writable: %w\", err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":"if err := restore(); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && (errors.Is(pe.Err, fs.ErrPermission) || errors.Is(pe.Err, fs.ErrNotExist)) {\n        // fix tablet dir permissions/existence, then retry restore\n    }\n    return err\n}","preventionTips":["Initialize the tablet directory before restore.","Run the restore process as the user owning the tablet dir.","Monitor disk space on the vtdataroot volume.","Keep restore volumes read-write; check mount flags."],"tags":["filesystem","restore","permissions","disk"],"backgroundTag":"file-create-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}