1
0
mirror of https://github.com/fumiama/fumidb.git synced 2026-06-09 04:30:34 +08:00
Files
fumidb/api/dbfile.md
源文雨 1b2da23ffb init doc
2022-04-25 23:29:39 +08:00

28 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 数据库文件格式
由于文件内普遍以uint64作为指针因此理论最大支持文件大小为`16384PB`,在现有条件下完全足够使用。
## 文件头
对于未被使用的对齐部分其开头将有一个8字节指针指向下一块未被使用的对齐部分没有则置0接下来紧跟着uint16的数字指示了本块未被使用的对齐部分的长度。因此能加入链表的未被使用的对齐部分最短应为10字节小于这个长度的未被使用部分将不再使用。
```
0 8 16
┌───────────────────┬───────────────────┐
│ ptr of unused blk │ ptr of next table │
├───────────────────┴───────────────────┤
│ first table head │
├───────────────────────────────────────┤
│ ...... ...... ...... │
├───────────────────┬───────────────────┤
│ ptr of next table │ second table head │
├───────────────────┴───────────────────┤
│ ...... ...... ...... │
├───────────────────────────────────────┤
│ some possible padding to fit 4096Byte │
├───────────────────────────────────────┤
│ data blocks ... │
└───────────────────────────────────────┘
```
### 新建表
在新建表时将计算表头大小,优先选取一块未被使用的足够大的对齐部分写入表头。当找不到时,在文件末尾附加表头(并留出新的对齐)。接下来将上一个表头开头的`下一个表头的指针`指向新表头的开头,然后建立相应数据结构,填充表头字段。
### 修改表
一旦创建数据表,将不支持修改。可以先删除表再重新创建,但这样数据将会丢失。
### 删除表
根据表头遍历所有表项,回收空间到未被使用的对齐部分,然后再回收表头,更新表头链表的指针,完成删除。