简体   繁体   English

使B + Tree并发线程安全

[英]Make a B+ Tree concurrent thread safe

I have implemented a B+ Tree in Java. 我在Java中实现了一个B + Tree。 Now I want to know what is the best way to allow concurrent inserts. 现在我想知道允许并发插入的最佳方法是什么。 My thought is to lock a node if it is maxFilled -1 (which means a split event is close). 我的想法是锁定一个节点,如果它是maxFilled -1(这意味着一个分裂事件接近)。 Otherwise I would just lock the array during a shift. 否则我只会在班次期间锁定阵列。 But this way it can happen to lock a node very close to the root and therefore lock far too much child nodes too. 但是这样可能会将节点锁定在非常接近根的位置,因此也会锁定太多的子节点。 Is there a better way or a best practice of how to make a B+ Tree thread safe? 有没有更好的方法或最佳实践如何使B +树线程安全?

You could implement a lock-free version of a B-tree. 您可以实现B树的无锁版本。

This approach causes a node that needs to be split to be gradually marked as frozen (by marking individual entries in the node as frozen one by one with atomic compare-and-swap operations until it is entirely frozen). 这种方法使得需要拆分的节点逐渐被标记为冻结(通过使用原子比较和交换操作将节点中的各个条目逐个标记为冻结,直到它被完全冻结)。 Readers can continue to navigate across a partially/fully frozen node on their way to other parts of the tree, ensuring high concurrency for readers. 读者可以在前往树的其他部分的路上继续浏览部分/完全冻结的节点,从而确保读者的高并发性。 A fully frozen node is replaced and later garbage collected, which works well with Java which has garbage collection. 一个完全冻结的节点被替换,后来被垃圾收集,这对于具有垃圾收集的Java很有效。

Details are well documented in the paper and there is no point in copying them all here. 文中详细记录了详细信息,没有必要在这里复制它们。 This graph (taken from the paper) shows the benefit: 该图(摘自论文)显示了以下好处:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM