Maintain “links” when writing a B+ tree to disk?

怎甘沉沦 提交于 2021-02-08 08:20:30

问题


I have done the implementation of B+ tree in java , but as usual , that is completely in main memory. How can i store a B+ tree onto a disk ? Each node of the btree contains the pointers(main memory addresses or reference to objects) to its children , how can i achieve the similar thing while Btree resides on disk? What replaces main memory addresses in b+ tree nodes in the scenario when b+ tree is on disk ?

There is already a similar Question posted here : B+Tree on-disk implementation in Java

But i dont fully understand the answer.

please share your views ?


回答1:


Take a look at the code of JDBM3 in github. This project persists B+ Tree and similar data structures to disk and you will definitely find your answer there.




回答2:


In the most simplistic form: You will have to keep track of the file offset (the number of bytes from the start of the file) the current node is read from or written to. So instead of memory addresses, on file based DBs, you save offsets.

Then when it is read from the file, you can decide to "cache" it in memory, and save the memory address for the given node, or only operate on offsets.

With this said, I have to add, that usually a file based DB is more complicated than this, optimising disk access by writing nodes to pages (which are usually the same size as the pages on the disk). This way, you can read more than one node with one disk seek operation (regarded as expensive operation).



来源:https://stackoverflow.com/questions/10292026/maintain-links-when-writing-a-b-tree-to-disk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!