hardcore-os / corekv Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
cache的s2lru组建中的这段代码:
// 如果 stageOne 没满,整个 LFU 区域也没满
if slru.stageOne.Len() < slru.stageOneCap || slru.Len() < slru.stageOneCap+slru.stageTwoCap {
slru.data[newitem.key] = slru.stageOne.PushFront(&newitem)
return
}
这里为什么允许stageOne满的情况往stageOne中加数据?
addSplits函数代码如下:
// 并行的运行子压缩情况
func (lm *levelManager) addSplits(cd *compactDef) {
cd.splits = cd.splits[:0]
// Let's say we have 10 tables in cd.bot and min width = 3. Then, we'll pick
// 0, 1, 2 (pick), 3, 4, 5 (pick), 6, 7, 8 (pick), 9 (pick, because last table).
// This gives us 4 picks for 10 tables.
// In an edge case, 142 tables in bottom led to 48 splits. That's too many splits, because it
// then uses up a lot of memory for table builder.
// We should keep it so we have at max 5 splits.
width := int(math.Ceil(float64(len(cd.bot)) / 5.0))
if width < 3 {
width = 3
}
skr := cd.thisRange
skr.extend(cd.nextRange)
addRange := func(right []byte) {
skr.right = utils.Copy(right)
cd.splits = append(cd.splits, skr)
skr.left = skr.right
}
for i, t := range cd.bot {
// last entry in bottom table.
// 最后一个range分配无穷大的空间
if i == len(cd.bot)-1 {
addRange([]byte{})
return
}
// 这里实现的是每(cd.bot/5)个合并成一个
if i%width == width-1 {
// 设置最大值为右区间
right := utils.KeyWithTs(utils.ParseKey(t.ss.MaxKey()), math.MaxUint64)
addRange(right)
}
}
}
视频讲解当中有一个细节优化是在切片时,以key为粒度进行划分,目的是为了减少划分后table之间的key重叠,提高效率(我感觉除了l0层,应该也不会有key重叠),但是代码里面,for循环中还是以cd.bot中的table来进行遍历,这里感觉还是以table为粒度来进行划分,请问是这样的吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.