file

package
v0.0.0-...-8eacd36 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SyncDir

func SyncDir(dir string) error

Types

type CoreFile

type CoreFile interface {
	Close() error
	Truncature(n int64) error
	ReName(name string) error
	NewReader(offset int) io.Reader
	Bytes(off, sz int) ([]byte, error)
	AllocateSlice(sz, offset int) ([]byte, int, error)
	Sync() error
	Delete() error
	Slice(offset int) []byte
}

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) (*utils.Entry, error)

func (*LogFile) DoneWriting

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

func (*LogFile) EncodeEntry

func (lf *LogFile) EncodeEntry(e *utils.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) Open

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

func (*LogFile) Read

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

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
	Tables    map[uint64]TableManifest
	Creations int
	Deletions int
}

Manifest corekv 元数据状态维护

func ReplayManifestFile

func ReplayManifestFile(fp *os.File) (ret *Manifest, truncOffset int64, err error)

ReplayManifestFile 对已经存在的manifest文件重新应用所有状态变更

type ManifestFile

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

ManifestFile 维护sst文件元信息的文件 manifest 比较特殊,不能使用mmap,需要保证实时的写入

func OpenManifestFile

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

OpenManifestFile 打开manifest文件

func (*ManifestFile) AddChanges

func (mf *ManifestFile) AddChanges(changesParam []*pb.ManifestChange) error

AddChanges 对外暴露的写比那更丰富

func (*ManifestFile) AddTableMeta

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

AddTableMeta 存储level表到manifest的level中

func (*ManifestFile) Close

func (mf *ManifestFile) Close() error

Close 关闭文件

func (*ManifestFile) GetManifest

func (mf *ManifestFile) GetManifest() *Manifest

GetManifest manifest

func (*ManifestFile) RevertToManifest

func (mf *ManifestFile) RevertToManifest(idMap map[uint64]struct{}) error

RevertToManifest checks that all necessary table files exist and removes all table files not referenced by the manifest. idMap is a set of table file id's that were read from the directory listing.

type MmapFile

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

MmapFile represents an mmapd file and includes both the buffer to the data and the file descriptor.

func OpenMmapFile

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

OpenMmapFile opens an existing file or creates a new file. If the file is created, it would truncate the file to maxSz. In both cases, it would mmap the file to maxSz and returned it. In case the file is created, z.NewFile is returned.

func OpenMmapFileUsing

func OpenMmapFileUsing(fd *os.File, sz int, writable bool) (*MmapFile, error)

OpenMmapFileUsing os

func (*MmapFile) AllocateSlice

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

AllocateSlice allocates a slice of the given size at the given offset.

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)

Bytes returns data starting from offset off of size sz. If there's not enough data, it would return nil slice and io.EOF.

func (*MmapFile) Close

func (m *MmapFile) Close() error

Close would close the file. It would also truncate the file if maxSz >= 0.

func (*MmapFile) Delete

func (m *MmapFile) Delete() error

func (*MmapFile) NewReader

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

func (*MmapFile) ReName

func (m *MmapFile) ReName(name string) error

ReName 兼容接口

func (*MmapFile) Slice

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

Slice returns the slice at the given offset.

func (*MmapFile) Sync

func (m *MmapFile) Sync() error

func (*MmapFile) Truncature

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

Truncature 兼容接口

type Options

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

Options

type SSTable

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

SSTable 文件的内存封装

func OpenSStable

func OpenSStable(opt *Options) *SSTable

OpenSStable 打开一个 sst文件

func (*SSTable) Bytes

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

Bytes returns data starting from offset off of size sz. If there's not enough data, it would return nil slice and io.EOF.

func (*SSTable) Close

func (ss *SSTable) Close() error

Close 关闭

func (*SSTable) Detele

func (ss *SSTable) Detele() error

Detele _

func (*SSTable) FID

func (ss *SSTable) FID() uint64

FID 获取fid

func (*SSTable) GetCreatedAt

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

GetCreatedAt _

func (*SSTable) HasBloomFilter

func (ss *SSTable) HasBloomFilter() bool

HasBloomFilter _

func (*SSTable) Indexs

func (ss *SSTable) Indexs() *pb.TableIndex

Indexs _

func (*SSTable) Init

func (ss *SSTable) Init() error

Init 初始化

func (*SSTable) MaxKey

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

MaxKey 当前最大的key

func (*SSTable) MinKey

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

MinKey 当前最小的key

func (*SSTable) SetCreatedAt

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

SetCreatedAt _

func (*SSTable) SetMaxKey

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

SetMaxKey max 需要使用table的迭代器,来获取最后一个block的最后一个key

func (*SSTable) Size

func (ss *SSTable) Size() int64

Size 返回底层文件的尺寸

func (*SSTable) Truncature

func (ss *SSTable) Truncature(size int64) error

Truncature _

type SafeRead

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

	RecordOffset uint32
	LF           *WalFile
}

封装kv分离的读操作

func (*SafeRead) MakeEntry

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

MakeEntry _

type TableManifest

type TableManifest struct {
	Level    uint8
	Checksum []byte // 方便今后扩展
}

TableManifest 包含sst的基本信息

type TableMeta

type TableMeta struct {
	ID       uint64
	Checksum []byte
}

TableMeta sst 的一些元信息

type WalFile

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

WalFile _

func OpenWalFile

func OpenWalFile(opt *Options) *WalFile

OpenWalFile _

func (*WalFile) Close

func (wf *WalFile) Close() error

Close _

func (*WalFile) Fid

func (wf *WalFile) Fid() uint64

Fid _

func (*WalFile) Iterate

func (wf *WalFile) Iterate(readOnly bool, offset uint32, fn utils.LogEntry) (uint32, error)

Iterate 从磁盘中遍历wal,获得数据

func (*WalFile) Name

func (wf *WalFile) Name() string

Name _

func (*WalFile) Size

func (wf *WalFile) Size() uint32

Size 当前已经被写入的数据

func (*WalFile) Truncate

func (wf *WalFile) Truncate(end int64) error

Truncate _ TODO Truncate 函数

func (*WalFile) Write

func (wf *WalFile) Write(entry *utils.Entry) error

Jump to

Keyboard shortcuts

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