Format PGDs on fatal() (#19521)
vkalintiris committed
Jan 31, 2025 at 08:37 UTC
d542b30c274015e8273878d6ce7c1c97351ad121
1 file changed
+108
-6
src/database/engine/page.c
+108
-6
@@ -51,6 +51,108 @@ struct pgd {
51
};
52
};
53
54
+static PRINTFLIKE(2, 3) void pgd_fatal(const PGD *pg, const char *fmt, ...) {
55
+ BUFFER *wb = buffer_create(0, NULL);
56
+
57
+ va_list args;
58
+ va_start(args, fmt);
59
+ buffer_vsprintf(wb, fmt, args);
60
+ va_end(args);
61
+
62
+ buffer_strcat(wb, " - pgd: { ");
63
+
64
+ {
65
+ buffer_strcat(wb, "type: ");
66
+ bool added = false;
67
+
68
+ if (pg->type == RRDENG_PAGE_TYPE_ARRAY_32BIT) {
69
+ buffer_sprintf(wb, "%s", "ARRAY_32BIT");
70
+ added = true;
71
+ }
72
+
73
+ if (pg->type == RRDENG_PAGE_TYPE_ARRAY_TIER1) {
74
+ buffer_sprintf(wb, added ? "|%s" : "%s", "ARRAY_TIER1");
75
+ added = true;
76
+ }
77
+
78
+ if (pg->type == RRDENG_PAGE_TYPE_GORILLA_32BIT) {
79
+ buffer_sprintf(wb, added ? "|%s" : "%s", "GORILLA_32BIT");
80
+ added = true;
81
+ }
82
+
83
+ if (!added) {
84
+ int type = pg->type;
85
+ buffer_sprintf(wb, "%d", type);
86
+ }
87
+ }
88
+
89
+ {
90
+ int used = pg->used;
91
+ int slots = pg->slots;
92
+ int partition = pg->partition;
93
+ buffer_sprintf(wb, ", used: %d, slots: %d, partition: %d", used, slots, partition);
94
+ }
95
+
96
+ {
97
+ buffer_strcat(wb, ", state: ");
98
+ bool added = false;
99
+
100
+ if (pg->states == PGD_STATE_CREATED_FROM_COLLECTOR) {
101
+ buffer_sprintf(wb, "%s", "CREATED_FROM_COLLECTOR");
102
+ added = true;
103
+ }
104
+
105
+ if (pg->states == PGD_STATE_CREATED_FROM_DISK) {
106
+ buffer_sprintf(wb, added ? "|%s" : "%s", "CREATED_FROM_DISK");
107
+ added = true;
108
+ }
109
+
110
+ if (pg->states == PGD_STATE_SCHEDULED_FOR_FLUSHING) {
111
+ buffer_sprintf(wb, added ? "|%s" : "%s", "SCHEDULED_FOR_FLUSHING");
112
+ added = true;
113
+ }
114
+
115
+ if (pg->states == PGD_STATE_FLUSHED_TO_DISK) {
116
+ buffer_sprintf(wb, added ? "|%s" : "%s", "FLUSHED_TO_DISK");
117
+ added = true;
118
+ }
119
+
120
+ if (!added) {
121
+ int state = pg->states;
122
+ buffer_sprintf(wb, "%d", state);
123
+ }
124
+ }
125
+
126
+ {
127
+ buffer_strcat(wb, ", options: ");
128
+ bool added = false;
129
+
130
+ if (pg->options & PAGE_OPTION_ALL_VALUES_EMPTY) {
131
+ buffer_sprintf(wb, "%s", "ALL_VALUES_EMPTY");
132
+ added = true;
133
+ }
134
+
135
+ if (pg->options & PAGE_OPTION_ARAL_MARKED) {
136
+ buffer_sprintf(wb, added ? "|%s" : "%s", "ARAL_MARKED");
137
+ added = true;
138
+ }
139
+
140
+ if (pg->options & PAGE_OPTION_ARAL_UNMARKED) {
141
+ buffer_sprintf(wb, added ? "|%s" : "%s", "ARAL_UNMARKED");
142
+ added = true;
143
+ }
144
+
145
+ if (!added) {
146
+ int options = pg->options;
147
+ buffer_sprintf(wb, "%d", options);
148
+ }
149
+ }
150
+
151
+ buffer_strcat(wb, " }");
152
+
153
+ fatal("%s", buffer_tostring(wb));
154
+}
155
+
156
// ----------------------------------------------------------------------------
157
// memory management
158
@@ -793,17 +895,17 @@ ALWAYS_INLINE size_t pgd_append_point(PGD *pg,
895
uint32_t expected_slot)
896
{
897
if (pg->states & PGD_STATE_SCHEDULED_FOR_FLUSHING)
796
- fatal("Data collection on page already scheduled for flushing");
898
+ pgd_fatal(pg, "Data collection on page already scheduled for flushing");
899
900
if (!(pg->states & PGD_STATE_CREATED_FROM_COLLECTOR))
799
- fatal("DBENGINE: collection on page not created from a collector");
901
+ pgd_fatal(pg, "DBENGINE: collection on page not created from a collector");
902
903
if (unlikely(pg->used != expected_slot))
802
- fatal("DBENGINE: page is not aligned to expected slot (used %u, expected %u)",
904
+ pgd_fatal(pg, "DBENGINE: page is not aligned to expected slot (used %u, expected %u)",
905
pg->used, expected_slot);
906
907
if (unlikely(pg->used >= pg->slots))
806
- fatal("DBENGINE: attempted to write beyond page size (page type %u, slots %u, used %u)",
908
+ pgd_fatal(pg, "DBENGINE: attempted to write beyond page size (page type %u, slots %u, used %u)",
909
pg->type, pg->slots, pg->used /* FIXME:, pg->size */);
910
911
switch (pg->type) {
@@ -880,10 +982,10 @@ static void pgdc_seek(PGDC *pgdc, uint32_t position)
982
if (!(pg->states & PGD_STATE_CREATED_FROM_COLLECTOR) &&
983
!(pg->states & PGD_STATE_SCHEDULED_FOR_FLUSHING) &&
984
!(pg->states & PGD_STATE_FLUSHED_TO_DISK))
883
- fatal("pgdc_seek() currently is not supported for pages created from disk.");
985
+ pgd_fatal(pg, "pgdc_seek() currently is not supported for pages created from disk.");
986
987
if (!pg->gorilla.writer)
886
- fatal("Seeking from a page without an active gorilla writer is not supported (yet).");
988
+ pgd_fatal(pg, "Seeking from a page without an active gorilla writer is not supported (yet).");
989
990
pgdc->slots = gorilla_writer_entries(pg->gorilla.writer);
991
pgdc->gr = gorilla_writer_get_reader(pg->gorilla.writer);