rrddiskprotocol.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_RRDDISKPROTOCOL_H
  3. #define NETDATA_RRDDISKPROTOCOL_H
  4. #include <stdint.h>
  5. #define RRDENG_BLOCK_SIZE (4096)
  6. #define RRDFILE_ALIGNMENT RRDENG_BLOCK_SIZE
  7. #define RRDENG_MAGIC_SZ (32)
  8. #define RRDENG_DF_MAGIC "netdata-data-file"
  9. #define RRDENG_JF_MAGIC "netdata-journal-file"
  10. #define RRDENG_VER_SZ (16)
  11. #define RRDENG_DF_VER "1.0"
  12. #define RRDENG_JF_VER "1.0"
  13. #define UUID_SZ (16)
  14. #define CHECKSUM_SZ (4) /* CRC32 */
  15. #define RRD_NO_COMPRESSION (0)
  16. #define RRD_LZ4 (1)
  17. #define RRDENG_DF_SB_PADDING_SZ (RRDENG_BLOCK_SIZE - (RRDENG_MAGIC_SZ + RRDENG_VER_SZ + sizeof(uint8_t)))
  18. /*
  19. * Data file persistent super-block
  20. */
  21. struct rrdeng_df_sb {
  22. char magic_number[RRDENG_MAGIC_SZ];
  23. char version[RRDENG_VER_SZ];
  24. uint8_t tier;
  25. uint8_t padding[RRDENG_DF_SB_PADDING_SZ];
  26. } __attribute__ ((packed));
  27. /*
  28. * Page types
  29. */
  30. #define PAGE_METRICS (0)
  31. #define PAGE_TIER (1)
  32. #define PAGE_GORILLA_METRICS (2)
  33. #define PAGE_TYPE_MAX 2 // Maximum page type (inclusive)
  34. /*
  35. * Data file page descriptor
  36. */
  37. struct rrdeng_extent_page_descr {
  38. uint8_t type;
  39. uint8_t uuid[UUID_SZ];
  40. uint32_t page_length;
  41. uint64_t start_time_ut;
  42. union {
  43. struct {
  44. uint32_t entries;
  45. uint32_t delta_time_s;
  46. } gorilla __attribute__((packed));
  47. uint64_t end_time_ut;
  48. };
  49. } __attribute__ ((packed));
  50. /*
  51. * Data file extent header
  52. */
  53. struct rrdeng_df_extent_header {
  54. uint32_t payload_length;
  55. uint8_t compression_algorithm;
  56. uint8_t number_of_pages;
  57. /* #number_of_pages page descriptors follow */
  58. struct rrdeng_extent_page_descr descr[];
  59. } __attribute__ ((packed));
  60. /*
  61. * Data file extent trailer
  62. */
  63. struct rrdeng_df_extent_trailer {
  64. uint8_t checksum[CHECKSUM_SZ]; /* CRC32 */
  65. } __attribute__ ((packed));
  66. #define RRDENG_JF_SB_PADDING_SZ (RRDENG_BLOCK_SIZE - (RRDENG_MAGIC_SZ + RRDENG_VER_SZ))
  67. /*
  68. * Journal file super-block
  69. */
  70. struct rrdeng_jf_sb {
  71. char magic_number[RRDENG_MAGIC_SZ];
  72. char version[RRDENG_VER_SZ];
  73. uint8_t padding[RRDENG_JF_SB_PADDING_SZ];
  74. } __attribute__ ((packed));
  75. /*
  76. * Transaction record types
  77. */
  78. #define STORE_PADDING (0)
  79. #define STORE_DATA (1)
  80. #define STORE_LOGS (2) /* reserved */
  81. /*
  82. * Journal file transaction record header
  83. */
  84. struct rrdeng_jf_transaction_header {
  85. /* when set to STORE_PADDING jump to start of next block */
  86. uint8_t type;
  87. uint32_t reserved; /* reserved for future use */
  88. uint64_t id;
  89. uint16_t payload_length;
  90. } __attribute__ ((packed));
  91. /*
  92. * Journal file transaction record trailer
  93. */
  94. struct rrdeng_jf_transaction_trailer {
  95. uint8_t checksum[CHECKSUM_SZ]; /* CRC32 */
  96. } __attribute__ ((packed));
  97. /*
  98. * Journal file STORE_DATA action
  99. */
  100. struct rrdeng_jf_store_data {
  101. /* data file extent information */
  102. uint64_t extent_offset;
  103. uint32_t extent_size;
  104. uint8_t number_of_pages;
  105. /* #number_of_pages page descriptors follow */
  106. struct rrdeng_extent_page_descr descr[];
  107. } __attribute__ ((packed));
  108. #endif /* NETDATA_RRDDISKPROTOCOL_H */