leveldb文件位置_为什么在LevelDB系统中,级别0的SST文件中的键重叠?

leveldb文件位置

As is known, keys may be overlap in SST files of level 0 in LevelDB. I am wondering why it needs to be overlap?

众所周知,键在LevelDB的0级SST 文件中可能重叠。 我想知道为什么它需要重叠?

An sstable is read-only after being written to the disk from a memtable. Accumulated K/Vs in the log up to a certain size are organized as a memtable and written to the disk as an sstable in level 0.

从内存表将sstable写入磁盘后,它是只读的。 日志中累积到一定大小的K / V被组织为一个内存表,并以级别为0的sstable形式写入磁盘。

K/Vs coming in to the log file are not sorted. Hence, a later written sstable in level 0 may have “smaller” keys than keys in previous sstables in level 0.

进入日志文件的K / V不会排序。 因此,级别0中后来写入的稳定表可能具有比级别0中先前的稳定表中的键“更小的”键。

Example (keys):

示例(键):

write/updates:        2, 9, 1,   3, 9, 8
sstables in level 0: {1, 2, 9}, {3, 8, 9}

This makes sstables in level 0 written to the disk be “like” a log (append only) which is good for write performance to disks. From level 1, overlappings are avoided through the process of merging sstables.

这使级别0的sstables写入磁盘就像日志(仅附加)一样,有利于磁盘的写入性能。 从级别1开始,通过合并稳定过程避免了重叠。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。


What do you mean by “Accumulated K/Vs in the log up to a certain size are organized as a memtable and written to the disk as an sstable in level 0.”?

您的意思是“日志中达到一定大小的累积K / V被组织为内存表,并以0级的稳定表形式写入磁盘”。

When one KV record is coming for writing, LevelDB would firstly append commit log to Log File (not sorted) and then insert this KV record to Memtable (SkipList Insert Operation). When Memtable (In sorted orders) achieves the threshold value, it would become the Immutable Table (sorted and read only). At last, Immutable Table would be dumped into disk as SSTables. Therefore, KV records in Level0 SSTables are coming from Immutable Table.

当有一条KV记录要写入时,LevelDB首先将提交日志追加到日志文件(未排序),然后将该KV记录插入Memtable(SkipList插入操作)。 当Memtable(按排序顺序)达到阈值时,它将成为不可变表(排序和只读)。 最后,不可变表将作为SSTables转储到磁盘中。 因此,Level0 SSTables中的KV记录来自不可变表。

It seems that you mean SSTables in level0 are coming from the Log File. I am not very clear about your point. Would you please clarify this.

看来您的意思是level0中的SSTables来自日志文件。 我对你的观点不太清楚。 请您澄清一下。



It seems that there are some overlaps in Immutable Memtable so it would be flushed into SSTables files in level 0 (Level 0 is not made by compaction). However, other levels (except level 0) would be compacted and merged so there are no overlaps in other levels.

似乎Immutable Memtable有一些重叠,因此它将被刷新到0级的SSTables文件中(0级不是通过压缩进行的)。 但是,其他级别(级别0除外)将被压缩和合并,因此其他级别没有重叠。



The “accumulated K/Vs in the log” to be written to a sstable is the same set of K/Vs as in the corresponding memtable (turned to be the immutable table).

要写入稳定表的“日志中的累积K / Vs”与对应的内存表(变成不可变表)中的K / Vs集相同。



However, the minor compaction is from Immutable Memtable (records have already been sorted) to SSTables in Level0. There is no merge or delete in this process (Immutable Memtable to SSTable files in Level 0).

但是,次要压缩是从不可变Memtable(记录已经排序)到Level0中的SSTables。 在此过程中没有合并或删除操作(级别0的SSTable文件不可变的内存表)。

It seems like this.

好像是这样

1, write/updates: 2, 9, 1, 3, 9, 8
2, Immutable Memtable: {1, 2, 3, 8, 9, 9}
3, sstable file 1 in level 0: {1, 2, 3, 8, 9, 9}

1,写入/更新:2,9,1,3,9,8
2,不可变的存储器:{1、2、3、8、9、9}
3、0级的sstable文件1:{1、2、3、8、9、9}

1, write/updates: 2, 90, 1, 30, 90, 8
2, Immutable Memtable: {1, 2, 8, 30, 90, 90}
3, sstable file 2 in level 0: {1, 2, 8, 30, 90, 90}

1,写入/更新:2、90、1、30、90、8
2,不可变的存储器:{1、2、8、30、90、90}
3、0级的sstable文件2:{1、2、8、30、90、90}



The immutable memtable should be identical to the sstable, or sstable is just a dump of an immutable memtable to disk.

不可变的内存表应该与sstable相同,或者sstable只是不可变的内存表到磁盘的转储。

Merges are done from level 0 to level 1:

合并从级别0到级别1:

sstable file 1 in level 0: {1, 2, 3, 8, 9, 9}
sstable file 2 in level 0: {1, 2, 8, 30, 90, 90}
sstable file 3 in level 1: {1, 90}

级别0的sstable文件1:{1、2、3、8、9、9}
级别0的sstable文件2:{1、2、8、30、90、90}
级别1中的sstable文件3:{1,90}

will be merged to (assume no other sstables to be merged)

将被合并到(假设没有其他稳定表要合并)

sstable file 4 in level 1: {1, 2, 3, 8, 9, 30, 90} (assume no deletion). In level 1, there are no other sstables covering key range [1, 90].

级别1中的sstable文件4:{1、2、3、8、9、30、90}(假定不删除)。 在级别1中,没有其他密钥覆盖键范围[1,90]。



ACK. for your last comments. Thank you Zhiqiang ;-)

确认 对于您的最后评论。 谢谢志强;-)

翻译自: https://www.systutorials.com/why-are-keys-overlap-in-sst-files-at-level-0-in-leveldb-system/

leveldb文件位置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值