log

package
v0.0.0-...-40627cf Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package log 实现日志读写操作.

Index

Constants

View Source
const (
	RecordFullType   = 1
	RecordFirstType  = 2
	RecordMiddleType = 3
	RecordLastType   = 4

	BlockSize  = 32768
	HeaderSize = 7 // 4 (checksum) + 2 (length) + 1 (type)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader interface {
	// ReadRecord 读取一个逻辑 Record.
	ReadRecord() (slice.Slice, error)
	// GetLastRecordOffset 获取最后读出的 Record 相对文件头部的偏移量.
	GetLastRecordOffset() int
}

Reader 定义读日志操作.

type ReaderImpl

type ReaderImpl struct {
	file.SequentialReader
	// 最后一个 Record头部ls 相对日志文件的偏移量
	LastRecordOffset int
	// contains filtered or unexported fields
}

ReaderImpl 实现 Reader 接口, 读取日志.

func (*ReaderImpl) GetLastRecordOffset

func (r *ReaderImpl) GetLastRecordOffset() int

GetLastRecordOffset 获取最后一条日志信息相对文件开头的偏移量.

func (*ReaderImpl) ReadRecord

func (r *ReaderImpl) ReadRecord() (record slice.Slice, err error)

ReadRecord 读取一个逻辑 Record.

type Reporter

type Reporter interface {
	Corruption(err error)
}

Reporter 用于报告读日志时发生的错误.

type Writer

type Writer interface {
	// AddRecord 向日志中添加条目.
	AddRecord(data slice.Slice) error
}

Writer 写日志.

type WriterImpl

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

WriterImpl 实现 Writer 接口提供写日志服务.

func (*WriterImpl) AddRecord

func (w *WriterImpl) AddRecord(data slice.Slice) error

AddRecord 将data写入日志, 写入失败时返回 error.

Jump to

Keyboard shortcuts

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