badgerdb中的logfile

logfile的作用

logfile是一种日志结构,用来记录日志,lsm tree是日志追加写的模式,在bagerdb中,vlog和sst在磁盘中的存放方式都是使用的logfile结构

// memTable structure stores a skiplist and a corresponding WAL. Writes to memTable are written
// both to the WAL and the skiplist. On a crash, the WAL is replayed to bring the skiplist back to
// its pre-crash form.
type memTable struct {
	// TODO: Give skiplist z.Calloc'd []byte.
	sl         *skl.Skiplist
	wal        *logFile//使用logfile结构
	maxVersion uint64
	opt        Options
	buf        *bytes.Buffer
}

type valueLog struct {
	dirPath string

	// guards our view of which files exist, which to be deleted, how many active iterators
	filesLock        sync.RWMutex
	filesMap         map[uint32]*logFile//使用logfile结构
	maxFid           uint32
	nextGCFid        uint32
	filesToBeDeleted []uint32
	// A refcount of iterators -- when this hits zero, we can delete the filesToBeDeleted.
	numActiveIterators int32

	db                *DB
	writableLogOffset uint32 // read by read, written by write. Must access via atomics.
	numEntriesWritten uint32
	opt               Options

	garbageCh    chan struct{}
	discardStats *discardStats
}

logfile文件的结构

badgerdb中的logfile_第1张图片

你可能感兴趣的:(badgerdb)