Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
// 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
}