// Open opens a WAL in the given directory. It will be force synced to disk
// every syncInterval. If syncInterval is 0, it will force sync on every write
// to the WAL.
Open opens a WAL in the given directory. It will be force synced to disk
every syncInterval. If syncInterval is 0, it will force sync on every write
to the WAL.
// Open opens a WAL in the given directory . It will be force synced to disk // every syncInterval . If syncInterval is 0 it will force sync on every write // to the WAL .
func Open(dir string, syncInterval time.Duration) (*WAL, error) {
	wal := &WAL{
		filebased: filebased{
			dir:       dir,
			fileFlags: os.O_CREATE | os.O_APPEND | os.O_WRONLY,
			h:         NewHash(),
			log:       log.New("wal"),
		},
		bufChan: make(chan [][]byte, 4096),
		exit:    make(chan struct{}),
	}
	err := wal.advance()
	if err != nil {
		return nil, err
	}
	if syncInterval <= 0 {
		wal.syncImmediate = true
	} else {
		go wal.sync(syncInterval)
	}
	go func() {
		for bufs := range wal.bufChan {
			wal.write(bufs...)
		}
		wal.exit <- struct{}{}
	}()
	return wal, nil
}
func Open ( dir string , syncInterval time . Duration ) ( * WAL , error ) { wal := & WAL { filebased : filebased { dir : dir , fileFlags : os . O_CREATE | os . O_APPEND | os . O_WRONLY , h : NewHash ( ) , log : log . New ( " " ) , } , bufChan : make ( chan [ ] [ ] byte , 4096 ) , exit : make ( chan struct { } ) , } err := wal . advance ( ) if err != nil { return nil , err } if syncInterval <= 0 { wal . syncImmediate = true } else { go wal . sync ( syncInterval ) } go func ( ) { for bufs := range wal . bufChan { wal . write ( bufs ... ) } wal . exit <- struct { } { } } ( ) return wal , nil }
Open opens a WAL in the given directory.
Open opens a WAL in the given directory .