10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.7 KiB

  1. leveldb File format
  2. ===================
  3. <beginning_of_file>
  4. [data block 1]
  5. [data block 2]
  6. ...
  7. [data block N]
  8. [meta block 1]
  9. ...
  10. [meta block K]
  11. [metaindex block]
  12. [index block]
  13. [Footer] (fixed size; starts at file_size - sizeof(Footer))
  14. <end_of_file>
  15. The file contains internal pointers. Each such pointer is called
  16. a BlockHandle and contains the following information:
  17. offset: varint64
  18. size: varint64
  19. See [varints](https://developers.google.com/protocol-buffers/docs/encoding#varints)
  20. for an explanation of varint64 format.
  21. 1. The sequence of key/value pairs in the file are stored in sorted
  22. order and partitioned into a sequence of data blocks. These blocks
  23. come one after another at the beginning of the file. Each data block
  24. is formatted according to the code in `block_builder.cc`, and then
  25. optionally compressed.
  26. 2. After the data blocks we store a bunch of meta blocks. The
  27. supported meta block types are described below. More meta block types
  28. may be added in the future. Each meta block is again formatted using
  29. `block_builder.cc` and then optionally compressed.
  30. 3. A "metaindex" block. It contains one entry for every other meta
  31. block where the key is the name of the meta block and the value is a
  32. BlockHandle pointing to that meta block.
  33. 4. An "index" block. This block contains one entry per data block,
  34. where the key is a string >= last key in that data block and before
  35. the first key in the successive data block. The value is the
  36. BlockHandle for the data block.
  37. 5. At the very end of the file is a fixed length footer that contains
  38. the BlockHandle of the metaindex and index blocks as well as a magic number.
  39. metaindex_handle: char[p]; // Block handle for metaindex
  40. index_handle: char[q]; // Block handle for index
  41. padding: char[40-p-q];// zeroed bytes to make fixed length
  42. // (40==2*BlockHandle::kMaxEncodedLength)
  43. magic: fixed64; // == 0xdb4775248b80fb57 (little-endian)
  44. ## "filter" Meta Block
  45. If a `FilterPolicy` was specified when the database was opened, a
  46. filter block is stored in each table. The "metaindex" block contains
  47. an entry that maps from `filter.<N>` to the BlockHandle for the filter
  48. block where `<N>` is the string returned by the filter policy's
  49. `Name()` method.
  50. The filter block stores a sequence of filters, where filter i contains
  51. the output of `FilterPolicy::CreateFilter()` on all keys that are stored
  52. in a block whose file offset falls within the range
  53. [ i*base ... (i+1)*base-1 ]
  54. Currently, "base" is 2KB. So for example, if blocks X and Y start in
  55. the range `[ 0KB .. 2KB-1 ]`, all of the keys in X and Y will be
  56. converted to a filter by calling `FilterPolicy::CreateFilter()`, and the
  57. resulting filter will be stored as the first filter in the filter
  58. block.
  59. The filter block is formatted as follows:
  60. [filter 0]
  61. [filter 1]
  62. [filter 2]
  63. ...
  64. [filter N-1]
  65. [offset of filter 0] : 4 bytes
  66. [offset of filter 1] : 4 bytes
  67. [offset of filter 2] : 4 bytes
  68. ...
  69. [offset of filter N-1] : 4 bytes
  70. [offset of beginning of offset array] : 4 bytes
  71. lg(base) : 1 byte
  72. The offset array at the end of the filter block allows efficient
  73. mapping from a data block offset to the corresponding filter.
  74. ## "stats" Meta Block
  75. This meta block contains a bunch of stats. The key is the name
  76. of the statistic. The value contains the statistic.
  77. TODO(postrelease): record following stats.
  78. data size
  79. index size
  80. key size (uncompressed)
  81. value size (uncompressed)
  82. number of entries
  83. number of data blocks