2014-09-15 18:42:25 +04:00
|
|
|
package wal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2014-09-17 13:54:04 +04:00
|
|
|
"github.com/siddontang/ledisdb/config"
|
|
|
|
"path"
|
2014-09-15 18:42:25 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
InvalidLogID uint64 = 0
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrLogNotFound = errors.New("log not found")
|
|
|
|
ErrLessLogID = errors.New("log id is less")
|
|
|
|
)
|
|
|
|
|
|
|
|
type Store interface {
|
|
|
|
GetLog(id uint64, log *Log) error
|
|
|
|
|
|
|
|
// Get the first log which ID is equal or larger than id
|
|
|
|
SeekLog(id uint64, log *Log) error
|
|
|
|
|
|
|
|
FirstID() (uint64, error)
|
|
|
|
LastID() (uint64, error)
|
|
|
|
|
|
|
|
// if log id is less than current last id, return error
|
|
|
|
StoreLog(log *Log) error
|
|
|
|
StoreLogs(logs []*Log) error
|
|
|
|
|
2014-09-17 13:54:04 +04:00
|
|
|
// Delete first n logs
|
|
|
|
Purge(n uint64) error
|
|
|
|
|
|
|
|
// Delete logs before n seconds
|
|
|
|
PurgeExpired(n int) error
|
2014-09-15 18:42:25 +04:00
|
|
|
|
|
|
|
// Clear all logs
|
|
|
|
Clear() error
|
|
|
|
|
|
|
|
Close() error
|
|
|
|
}
|
2014-09-17 13:54:04 +04:00
|
|
|
|
|
|
|
func NewStore(cfg *config.Config) (Store, error) {
|
|
|
|
//now we only support goleveldb
|
|
|
|
|
|
|
|
base := cfg.WAL.Path
|
|
|
|
if len(base) == 0 {
|
|
|
|
base = path.Join(cfg.DataDir, "wal")
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewGoLevelDBStore(base)
|
|
|
|
}
|