journal

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileMode = 0664
	DirMode  = 0774
	BufSize  = 1024 * 1024 * 4 // 4 MB
)

Variables

View Source
var (
	// DataFileNameReg journal data file name pattern
	DataFileNameReg = regexp.MustCompile(`\d{8}_\d{8}\.buf`)
	// IDFileNameReg journal id file name pattern
	IDFileNameReg = regexp.MustCompile(`\d{8}_\d{8}\.ids`)
)
View Source
var (
	DuringRotateErr = fmt.Errorf("during rotating")
)

Functions

func GenerateNewBufFName

func GenerateNewBufFName(now time.Time, oldFName string) (string, error)

GenerateNewBufFName return new buf file name depends on current time file name looks like `yyyymmddnnnn.ids`, nnnn begin from 0001 for each day

func OpenBufFile

func OpenBufFile(filepath string) (fp *os.File, err error)

OpenBufFile create and open file

func PrepareDir

func PrepareDir(path string) error

PrepareDir `mkdir -p`

Types

type BufFileStat

type BufFileStat struct {
	NewDataFp, NewIdsDataFp        *os.File
	OldDataFnames, OldIdsDataFname []string
}

BufFileStat current journal files' stats

func PrepareNewBufFile

func PrepareNewBufFile(dirPath string, oldFsStat *BufFileStat, isScan bool) (ret *BufFileStat, err error)

PrepareNewBufFile create new data & id files, and update BufFileStat

type Data

type Data struct {
	Data map[string]interface{}
	ID   int64
}

func (*Data) DecodeMsg

func (z *Data) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Data) EncodeMsg

func (z *Data) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Data) MarshalMsg

func (z *Data) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Data) Msgsize

func (z *Data) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Data) UnmarshalMsg

func (z *Data) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type DataDecoder

type DataDecoder struct {
	// contains filtered or unexported fields
}

func NewDataDecoder

func NewDataDecoder(fp *os.File) *DataDecoder

func (*DataDecoder) Read

func (dec *DataDecoder) Read(data *Data) (err error)

type DataEncoder

type DataEncoder struct {
	// contains filtered or unexported fields
}

func NewDataEncoder

func NewDataEncoder(fp *os.File) *DataEncoder

func (*DataEncoder) Flush

func (enc *DataEncoder) Flush() error

func (*DataEncoder) Write

func (enc *DataEncoder) Write(msg *Data) (err error)

type IdsDecoder

type IdsDecoder struct {
	// contains filtered or unexported fields
}

func NewIdsDecoder

func NewIdsDecoder(fp *os.File) *IdsDecoder

func (*IdsDecoder) LoadMaxId

func (dec *IdsDecoder) LoadMaxId() (maxId int64, err error)

func (*IdsDecoder) ReadAllToBmap

func (dec *IdsDecoder) ReadAllToBmap() (ids *roaring.Bitmap, err error)

func (*IdsDecoder) ReadAllToInt64Set added in v1.3.0

func (dec *IdsDecoder) ReadAllToInt64Set(ids *Int64Set) (err error)

type IdsEncoder

type IdsEncoder struct {
	// contains filtered or unexported fields
}

func NewIdsEncoder

func NewIdsEncoder(fp *os.File) *IdsEncoder

func (*IdsEncoder) Flush

func (enc *IdsEncoder) Flush() error

func (*IdsEncoder) Write

func (enc *IdsEncoder) Write(id int64) (err error)

type Int64Set added in v1.3.0

type Int64Set struct {
	// contains filtered or unexported fields
}

func NewInt64Set added in v1.3.0

func NewInt64Set() *Int64Set

func (*Int64Set) Add added in v1.3.0

func (s *Int64Set) Add(i int64)

func (*Int64Set) CheckAndRemove added in v1.3.0

func (s *Int64Set) CheckAndRemove(i int64) (ok bool)

type Journal

type Journal struct {
	*JournalConfig
	// contains filtered or unexported fields
}

func NewJournal

func NewJournal(cfg *JournalConfig) *Journal

func (*Journal) Flush

func (j *Journal) Flush() (err error)

func (*Journal) IsLegacyRunning

func (j *Journal) IsLegacyRunning() bool

func (*Journal) LoadLegacyBuf

func (j *Journal) LoadLegacyBuf(data *Data) (err error)

LoadLegacyBuf load legacy data one by one ⚠️Warn: should call `j.LockLegacy()` before invoke this method

func (*Journal) LoadMaxId

func (j *Journal) LoadMaxId() (int64, error)

func (*Journal) LockLegacy

func (j *Journal) LockLegacy() bool

func (*Journal) RefreshLegacyLoader

func (j *Journal) RefreshLegacyLoader()

RefreshLegacyLoader create or reset legacy loader

func (*Journal) Rotate

func (j *Journal) Rotate() (err error)

Rotate create new data and ids buf file this function is not threadsafe

func (*Journal) UnLockLegacy

func (j *Journal) UnLockLegacy() bool

func (*Journal) WriteData

func (j *Journal) WriteData(data *Data) (err error)

func (*Journal) WriteId

func (j *Journal) WriteId(id int64) error

type JournalConfig

type JournalConfig struct {
	BufDirPath             string
	BufSizeBytes           int64
	RotateCheckIntervalNum int
	RotateDuration         time.Duration
}

type LegacyLoader

type LegacyLoader struct {
	// contains filtered or unexported fields
}

func NewLegacyLoader

func NewLegacyLoader(dataFNames, idsFNames []string) *LegacyLoader

func (*LegacyLoader) AddID added in v1.3.0

func (l *LegacyLoader) AddID(id int64)

func (*LegacyLoader) Clean

func (l *LegacyLoader) Clean() error

func (*LegacyLoader) Load

func (l *LegacyLoader) Load(data *Data) (err error)

func (*LegacyLoader) LoadAllids

func (l *LegacyLoader) LoadAllids(ids *Int64Set) (allErr error)

func (*LegacyLoader) LoadMaxId

func (l *LegacyLoader) LoadMaxId() (maxId int64, err error)

func (*LegacyLoader) Reset

func (l *LegacyLoader) Reset(dataFNames, idsFNames []string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL