file

package
v0.0.0-...-a38de57 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RewriteManifest

func RewriteManifest(dir string, m *Manifest) (*os.File, int, error)

RewriteManifest 覆盖写manifest文件

func SyncDir

func SyncDir(dir string) error

Types

type LevelManifest

type LevelManifest struct {
	Tables map[uint64]struct{} // 每层的table集合
}

type LogFile

type LogFile struct {
	Lock sync.RWMutex
	FID  uint32
	// contains filtered or unexported fields
}

func (*LogFile) AddSize

func (lf *LogFile) AddSize(offset uint32)

func (*LogFile) Bootstrap

func (lf *LogFile) Bootstrap() error

完成log文件的初始化

func (*LogFile) Close

func (lf *LogFile) Close() error

func (*LogFile) DecodeEntry

func (lf *LogFile) DecodeEntry(buf []byte, offset uint32) (*utils2.Entry, error)

func (*LogFile) DoneWriting

func (lf *LogFile) DoneWriting(offset uint32) error

func (*LogFile) EncodeEntry

func (lf *LogFile) EncodeEntry(e *utils2.Entry, buf *bytes.Buffer, offset uint32) (int, error)

EncodeEntry will encode entry to the buf layout of entry +--------+-----+-------+-------+ | header | key | value | crc32 | +--------+-----+-------+-------+

func (*LogFile) FD

func (lf *LogFile) FD() *os.File

func (*LogFile) FileName

func (lf *LogFile) FileName() string

func (*LogFile) Init

func (lf *LogFile) Init() error

func (*LogFile) Iterate

func (lf *LogFile) Iterate(offset uint32, fn utils2.LogEntry) (uint32, error)

func (*LogFile) Open

func (lf *LogFile) Open(opt *Option) error

Open 打开vlog文件,这里底层也是通过mmap映射

func (*LogFile) Read

func (lf *LogFile) Read(p *utils2.ValuePtr) (buf []byte, err error)

Read Acquire lock on mmap/file if you are calling this

func (*LogFile) Seek

func (lf *LogFile) Seek(offset int64, whence int) (ret int64, err error)

func (*LogFile) Size

func (lf *LogFile) Size() int64

func (*LogFile) Sync

func (lf *LogFile) Sync() error

You must hold lf.lock to sync()

func (*LogFile) Truncate

func (lf *LogFile) Truncate(offset int64) error

func (*LogFile) Write

func (lf *LogFile) Write(offset uint32, buf []byte) (err error)

type Manifest

type Manifest struct {
	Levels    []LevelManifest          // 每个level的table集合
	Tables    map[uint64]TableManifest // tableID--{level,crc}的映射
	Creations int
	Deletions int
}

Manifest 存放当前kv的level元数据 磁盘存储结构: magic-num | version | length change | crc | change

32 bit |  32bit  |   32 bit      | 32bit | ...

func ReplayManifest

func ReplayManifest(f *os.File) (*Manifest, int64, error)

func (*Manifest) GetModifies

func (m *Manifest) GetModifies() []*pb.ManifestModify

type ManifestFile

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

func OpenManifestFile

func OpenManifestFile(opt *Option) (*ManifestFile, error)

OpenManifestFile 打开manifest文件

func (*ManifestFile) AddChanges

func (f *ManifestFile) AddChanges(changesParam []*pb.ManifestModify) error

func (*ManifestFile) AddTableMeta

func (f *ManifestFile) AddTableMeta(levelNum int, t *TableMeta) (err error)

AddTableMeta 存储level表到manifest的level中

func (*ManifestFile) Close

func (f *ManifestFile) Close() error

Close 关闭文件

func (*ManifestFile) FilterValidTables

func (f *ManifestFile) FilterValidTables(ids map[uint64]struct{}) error

FilterValidTables 用来将磁盘中存储的sst文件集合与内存中的manifest进行对比过滤 两个集合:manifest,sst目录下集合 以manifest为基准,保证manifest中的所有文件都存在:如果出现某table存在于manifest中,但是磁盘中并不存在此sst文件,返回error 如果manifest中多了,需要将多余的文件删除

func (*ManifestFile) Manifest

func (f *ManifestFile) Manifest() *Manifest

type MmapFile

type MmapFile struct {
	Data []byte
	Fd   *os.File
}

func OpenMmapFile

func OpenMmapFile(filename string, flag int, maxSize int) (*MmapFile, error)

func (*MmapFile) AllocateSlice

func (m *MmapFile) AllocateSlice(sz, offset int) ([]byte, int, error)

func (*MmapFile) AppendBuffer

func (m *MmapFile) AppendBuffer(offset uint32, buf []byte) error

AppendBuffer 向内存中追加一个buffer,如果空间不足则重新映射,扩大空间

func (*MmapFile) Bytes

func (m *MmapFile) Bytes(off, sz int) ([]byte, error)

func (*MmapFile) Close

func (m *MmapFile) Close() error

func (*MmapFile) Delete

func (m *MmapFile) Delete() error

func (*MmapFile) NewReader

func (m *MmapFile) NewReader(offset int) io.Reader

func (*MmapFile) Slice

func (m *MmapFile) Slice(offset int) []byte

func (*MmapFile) Sync

func (m *MmapFile) Sync() error

func (*MmapFile) Truncate

func (m *MmapFile) Truncate(maxSz int64) error

type Option

type Option struct {
	FID      uint64
	FileName string
	Dir      string
	Path     string
	Flag     int
	MaxSz    int
}

type SSTable

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

SSTable construct of : block1 | block2 | ... | index_data | index_len | check_sum | check_sum_len

func OpenSSTable

func OpenSSTable(option *Option) *SSTable

func (*SSTable) Bytes

func (s *SSTable) Bytes(off, sz int) ([]byte, error)

func (*SSTable) GetCreatedAt

func (s *SSTable) GetCreatedAt() *time.Time

GetCreatedAt _

func (*SSTable) HasBloomFilter

func (s *SSTable) HasBloomFilter() bool

func (*SSTable) Index

func (s *SSTable) Index() *pb.TableIndex

func (*SSTable) Init

func (s *SSTable) Init() error

func (*SSTable) MaxKey

func (s *SSTable) MaxKey() []byte

func (*SSTable) MinKey

func (s *SSTable) MinKey() []byte

func (*SSTable) SetCreatedAt

func (s *SSTable) SetCreatedAt(t *time.Time)

SetCreatedAt _

func (*SSTable) SetMaxKey

func (s *SSTable) SetMaxKey(maxKey []byte)

func (*SSTable) Size

func (s *SSTable) Size() int64

type SafeRead

type SafeRead struct {
	K []byte
	V []byte

	RecordOffset uint32
	LF           *Wal
}

func (*SafeRead) MakeEntry

func (r *SafeRead) MakeEntry(reader io.Reader) (*utils2.Entry, error)

type TableManifest

type TableManifest struct {
	Level    uint8  // 所在level
	CheckSum []byte // 校验和
}

type TableMeta

type TableMeta struct {
	ID       uint64
	CheckSum []byte
}

type Wal

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

func OpenWalFile

func OpenWalFile(opt *Option) *Wal

func (*Wal) Close

func (w *Wal) Close() error

func (*Wal) FID

func (w *Wal) FID() uint64

func (*Wal) Iterate

func (w *Wal) Iterate(readonly bool, offset uint32, fn utils2.LogEntry) (uint32, error)

Iterate 从磁盘中遍历wal获取数据 fn : 拿到entry后做的工作

func (*Wal) Name

func (w *Wal) Name() string

func (*Wal) Size

func (w *Wal) Size() uint32

func (*Wal) Truncate

func (w *Wal) Truncate(end int64) error

func (*Wal) Write

func (w *Wal) Write(entry *utils2.Entry) error

Jump to

Keyboard shortcuts

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