小组成员:姚凯文(kevinyao0901),姜嘉琪
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.

72 lines
2.6 KiB

  1. The log file contents are a sequence of 32KB blocks. The only
  2. exception is that the tail of the file may contain a partial block.
  3. Each block consists of a sequence of records:
  4. block := record* trailer?
  5. record :=
  6. checksum: uint32 // crc32c of type and data[]
  7. length: uint16
  8. type: uint8 // One of FULL, FIRST, MIDDLE, LAST
  9. data: uint8[length]
  10. A record never starts within the last seven bytes of a block. Any
  11. leftover bytes here form the trailer, which must consist entirely of
  12. zero bytes and must be skipped by readers. In particular, even if
  13. there are exactly seven bytes left in the block, and a zero-length
  14. user record is added (which will fit in these seven bytes), the writer
  15. must skip these trailer bytes and add the record to the next block.
  16. More types may be added in the future. Some Readers may skip record
  17. types they do not understand, others may report that some data was
  18. skipped.
  19. FULL == 1
  20. FIRST == 2
  21. MIDDLE == 3
  22. LAST == 4
  23. The FULL record contains the contents of an entire user record.
  24. FIRST, MIDDLE, LAST are types used for user records that have been
  25. split into multiple fragments (typically because of block boundaries).
  26. FIRST is the type of the first fragment of a user record, LAST is the
  27. type of the last fragment of a user record, and MID is the type of all
  28. interior fragments of a user record.
  29. Example: consider a sequence of user records:
  30. A: length 1000
  31. B: length 97270
  32. C: length 8000
  33. A will be stored as a FULL record in the first block.
  34. B will be split into three fragments: first fragment occupies the rest
  35. of the first block, second fragment occupies the entirety of the
  36. second block, and the third fragment occupies a prefix of the third
  37. block. This will leave six bytes free in the third block, which will
  38. be left empty as the trailer.
  39. C will be stored as a FULL record in the fourth block.
  40. ===================
  41. Some benefits over the recordio format:
  42. (1) We do not need any heuristics for resyncing - just go to next
  43. block boundary and scan. If there is a corruption, skip to the next
  44. block. As a side-benefit, we do not get confused when part of the
  45. contents of one log file are embedded as a record inside another log
  46. file.
  47. (2) Splitting at approximate boundaries (e.g., for mapreduce) is
  48. simple: find the next block boundary and skip records until we
  49. hit a FULL or FIRST record.
  50. (3) We do not need extra buffering for large records.
  51. Some downsides compared to recordio format:
  52. (1) No packing of tiny records. This could be fixed by adding a new
  53. record type, so it is a shortcoming of the current implementation,
  54. not necessarily the format.
  55. (2) No compression. Again, this could be fixed by adding new record types.