func (self *BinaryLog) initializeLogFile() *BinLogFile { if len(self.logFiles) == 0 { firstName := self.logLocation + BinaryLogNamePrefix + "0" + BinaryLogFileExt self.logFiles = append(self.logFiles, &BinLogFile{firstName, 0}) } lastLogFile := self.logFiles[len(self.logFiles)-1] err := createFileIfNotExists(lastLogFile.FilePath) if err != nil { log.Fatal("Failed to open a log file: %s", err.Error()) } return lastLogFile }
func NewBinaryLog(cfg conf.Config) *BinaryLog { binlog := &BinaryLog{ dataChan: make(chan []byte, cfg.BinaryLogBufferSize), serviceChan: make(chan []byte, cfg.BinaryLogBufferSize), seqId: 0, maxPageSize: cfg.BinaryLogPageSize, pageSize: 0, logWriter: nil, } logFiles, err := findLogFiles(cfg.BinaryLogPath) if err != nil { log.Fatal("Coould not init bin log subsystems: %s", err.Error()) } binlog.logFiles = logFiles return binlog }
// createFileIfNotExists initialized log file. func createFileIfNotExists(path string) error { _, err := os.Lstat(path) if err != nil { // What??? It is false if file doesn't exist. if os.IsExist(err) { log.Fatal("Can not read file stats: %s", err.Error()) } f, err := os.Create(path) if err != nil { return err } if err := f.Close(); err != nil { return err } return createFileIfNotExists(path) } return nil }