node-haystack Episode 5: Volume
2016-09-10 13:36
411 查看
This article talks about the structure of volume file.
NOTE
The data size field of block is a 32bits integer. That means the maximum size of data field of block is 2^32, or 4GB.
Layout
Volume is the entity for service. A volume includes a lot of blocks. Blocks store the exact data.Volume
The layout of a volume file looks like this:Field | Size | Description |
---|---|---|
Magic number of volume | 8 bytes | 0x6b63617453796148 or { ‘H’, ‘a’, ‘y’, ‘S’, ‘t’, ‘a’, ‘c’, ‘k’ } |
Block 0 | Varies | |
block 1 | Varies | |
… | Varies | |
block N | Varies |
Block
The layout of a block looks this:Field | Size | Description |
---|---|---|
Magic number of header | 4 bytes | 0x53796148 or { ‘H’, ‘a’, ‘y’, ‘S’ } |
Key | 16 bytes | A uuid value |
Cookie | 4 bytes | Cookie for avoiding attack |
Tag | 2 bytes | Optional field for user |
Flag | 2 bytes | If removed |
Data size | 4 bytes | Length of data, in byte |
Check sum | 4 bytes | Parity check sum |
Data | Varies | The content |
Padding | Varies | 0 - 7 bytes, make sure the blocks aligning at 8 bytes boundary |
Magic number of footer | 4 bytes | 0x6b636174 or { ‘t’, ‘a’, ‘c’, ‘k’ } |
The data size field of block is a 32bits integer. That means the maximum size of data field of block is 2^32, or 4GB.
Index
To speed the finding of blocks, a hash is used to index the blocks. The key type of hash isstd::string. The following information of a block will be kept in hash:
Field | Size | Description |
---|---|---|
Key | 16bytes | The uuid key |
Cookie | 4bytes | |
Tag | 2bytes | |
Flag | 2bytes | Since the memory will align at 32bits boundary at least, this field should be harmless. 0x0000 for normal, 0x0001 on removed. |
Size | 4bytes | |
Position | 8bytes | The offset of beginning of the block in volume file. |
Cache
Implementing a C++ cache is painful. The flexible high-level language JavaScript will be a better choice, even it may cause the lost of performance a little bit. The cost is worth.相关文章推荐
- node-haystack Episode 11: node object of Volume
- node-haystack Episode 2: Asynchronous and Threading
- node-haystack Episode 7: Asynchronously manipulate blocks
- node-haystack Episode 8: Simple Recovery And Verification
- node-haystack Episode 9: Manipulate Volume
- node-haystack Episode 3: Callback model in C++
- node-haystack Episode 12: problem of C++ closure
- node-haystack Episode - 12 : A Better Random Generator
- node-haystack Episode-4: Wrapper of libuv
- node-haystack Episode 10: Node.js add-on
- node-haystack Episode 1: What is it and why
- node-haystack Episode 6: Data Structure And Constants
- cinder创建云硬盘的时候 出现 cinder-volume | linux-node2@lvm | nova | enabled | down | 2017-04-26T22:45:47.
- Nodejs express、html5实现拖拽上传
- LeetCode - Populating Next Right Pointers in Each Node
- 理解Node.js的事件驱动和异步编程
- hadoop jps datanode开启失败
- node实现一个Websocket服务器
- Populating Next Right Pointers in Each Node