您的位置:首页 > Web前端 > Node.js

node-haystack Episode 5: Volume

2016-09-10 13:36 411 查看
This article talks about the structure of volume file.

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:

FieldSizeDescription
Magic number of volume8 bytes0x6b63617453796148 or { ‘H’, ‘a’, ‘y’, ‘S’, ‘t’, ‘a’, ‘c’, ‘k’ }
Block 0Varies
block 1Varies
Varies
block NVaries

Block

The layout of a block looks this:

FieldSizeDescription
Magic number of header4 bytes0x53796148 or { ‘H’, ‘a’, ‘y’, ‘S’ }
Key16 bytesA uuid value
Cookie4 bytesCookie for avoiding attack
Tag2 bytesOptional field for user
Flag2 bytesIf removed
Data size4 bytesLength of data, in byte
Check sum4 bytesParity check sum
DataVariesThe content
PaddingVaries0 - 7 bytes, make sure the blocks aligning at 8 bytes boundary
Magic number of footer4 bytes0x6b636174 or { ‘t’, ‘a’, ‘c’, ‘k’ }
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.

Index

To speed the finding of blocks, a hash is used to index the blocks. The key type of hash is
std::string
. The following information of a block will be kept in hash:

FieldSizeDescription
Key16bytesThe uuid key
Cookie4bytes
Tag2bytes
Flag2bytesSince the memory will align at 32bits boundary at least, this field should be harmless. 0x0000 for normal, 0x0001 on removed.
Size4bytes
Position8bytesThe 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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  layout hash cache