{"record":{"id":"425bb15df04336e1","repo":"vitessio/vitess","slug":"log-file-number-is-zero-cannot-detect-previous-fi","errorCode":null,"errorMessage":"Log file number is zero, cannot detect previous file","messagePattern":"Log file number is zero, cannot detect previous file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtorc/inst/binlog.go","lineNumber":137,"sourceCode":"// Example: FileNumber() of mysqld.log.000789 is (789, 6)\nfunc (binlogCoordinates *BinlogCoordinates) FileNumber() (int, int) {\n\ttokens := strings.Split(binlogCoordinates.LogFile, \".\")\n\tnumPart := tokens[len(tokens)-1]\n\tnumLen := len(numPart)\n\tfileNum, err := strconv.Atoi(numPart)\n\tif err != nil {\n\t\treturn 0, 0\n\t}\n\treturn fileNum, numLen\n}\n\n// PreviousFileCoordinatesBy guesses the filename of the previous binlog/relaylog, by given offset (number of files back)\nfunc (binlogCoordinates *BinlogCoordinates) PreviousFileCoordinatesBy(offset int) (BinlogCoordinates, error) {\n\tresult := BinlogCoordinates{LogPos: 0, Type: binlogCoordinates.Type}\n\n\tfileNum, numLen := binlogCoordinates.FileNumber()\n\tif fileNum == 0 {\n\t\treturn result, errors.New(\"Log file number is zero, cannot detect previous file\")\n\t}\n\tnewNumStr := strconv.Itoa((fileNum - offset))\n\tnewNumStr = strings.Repeat(\"0\", numLen-len(newNumStr)) + newNumStr\n\n\ttokens := strings.Split(binlogCoordinates.LogFile, \".\")\n\ttokens[len(tokens)-1] = newNumStr\n\tresult.LogFile = strings.Join(tokens, \".\")\n\treturn result, nil\n}\n\n// PreviousFileCoordinates guesses the filename of the previous binlog/relaylog\nfunc (binlogCoordinates *BinlogCoordinates) PreviousFileCoordinates() (BinlogCoordinates, error) {\n\treturn binlogCoordinates.PreviousFileCoordinatesBy(1)\n}\n\n// PreviousFileCoordinates guesses the filename of the previous binlog/relaylog\nfunc (binlogCoordinates *BinlogCoordinates) NextFileCoordinates() (BinlogCoordinates, error) {\n\tresult := BinlogCoordinates{LogPos: 0, Type: binlogCoordinates.Type}","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtorc/inst/binlog.go#L119-L155","documentation":"BinlogCoordinates.PreviousFileCoordinatesBy guesses the previous binlog/relaylog file by decrementing the file number in the coordinate's log file name. If the current file number is 0 there is no earlier file to compute, so it returns this error.","triggerScenarios":"Calling PreviousFileCoordinates (which delegates to PreviousFileCoordinatesBy) on coordinates whose log file name has number 000001 (FileNumber()==0 in its internal representation), e.g. the very first binlog file.","commonSituations":"Failover/topology code (vtorc) computing previous coordinates for a server whose binlog is still at the first file, or parsing a malformed log file name that yields file number 0.","solutions":["Guard the call: skip previous-coordinate computation when the file number is 0 and use the current coordinates directly","Advance/rotate the binlog so a previous file exists, or obtain coordinates another way (SHOW BINARY LOG STATUS)","Validate the LogFile name is well-formed (e.g. mysql-bin.000002) before computing previous coordinates"],"exampleFix":"// before\nprev, err := coords.PreviousFileCoordinates()\n// after\nif fileNum, _ := coords.FileNumber(); fileNum == 0 {\n    prev = coords // no previous file exists\n} else {\n    prev, err = coords.PreviousFileCoordinates()\n}","handlingStrategy":"validation","validationCode":"if fileNum, _ := coords.FileNumber(); fileNum == 0 {\n    return coords, nil // no previous file exists\n}\nprev, err := coords.PreviousFileCoordinates()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check FileNumber()==0 before computing previous coordinates","Validate binlog file names parse correctly before coordinate math","Handle first-binlog-file servers explicitly in failover code"],"tags":["vtorc","binlog","coordinates","edge-case"],"backgroundTag":"binlog-file-number-zero","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}