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