小组成员: 曹可心-10223903406 朴祉燕-10224602413
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.

104 lines
3.7 KiB

  1. 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 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. (6) 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. -------------------
  46. If a "FilterPolicy" was specified when the database was opened, a
  47. filter block is stored in each table. The "metaindex" block contains
  48. an entry that maps from "filter.<N>" to the BlockHandle for the filter
  49. block where "<N>" is the string returned by the filter policy's
  50. "Name()" method.
  51. The filter block stores a sequence of filters, where filter i contains
  52. the output of FilterPolicy::CreateFilter() on all keys that are stored
  53. in a block whose file offset falls within the range
  54. [ i*base ... (i+1)*base-1 ]
  55. Currently, "base" is 2KB. So for example, if blocks X and Y start in
  56. the range [ 0KB .. 2KB-1 ], all of the keys in X and Y will be
  57. converted to a filter by calling FilterPolicy::CreateFilter(), and the
  58. resulting filter will be stored as the first filter in the filter
  59. block.
  60. The filter block is formatted as follows:
  61. [filter 0]
  62. [filter 1]
  63. [filter 2]
  64. ...
  65. [filter N-1]
  66. [offset of filter 0] : 4 bytes
  67. [offset of filter 1] : 4 bytes
  68. [offset of filter 2] : 4 bytes
  69. ...
  70. [offset of filter N-1] : 4 bytes
  71. [offset of beginning of offset array] : 4 bytes
  72. lg(base) : 1 byte
  73. The offset array at the end of the filter block allows efficient
  74. mapping from a data block offset to the corresponding filter.
  75. "stats" Meta Block
  76. ------------------
  77. This meta block contains a bunch of stats. The key is the name
  78. of the statistic. The value contains the statistic.
  79. TODO(postrelease): record following stats.
  80. data size
  81. index size
  82. key size (uncompressed)
  83. value size (uncompressed)
  84. number of entries
  85. number of data blocks