page.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "page.h"
  3. #include "libnetdata/libnetdata.h"
  4. typedef enum __attribute__((packed)) {
  5. PAGE_OPTION_ALL_VALUES_EMPTY = (1 << 0),
  6. } PAGE_OPTIONS;
  7. typedef enum __attribute__((packed)) {
  8. PGD_STATE_CREATED_FROM_COLLECTOR = (1 << 0),
  9. PGD_STATE_CREATED_FROM_DISK = (1 << 1),
  10. PGD_STATE_SCHEDULED_FOR_FLUSHING = (1 << 2),
  11. PGD_STATE_FLUSHED_TO_DISK = (1 << 3),
  12. } PGD_STATES;
  13. typedef struct {
  14. uint8_t *data;
  15. uint32_t size;
  16. } page_raw_t;
  17. typedef struct {
  18. size_t num_buffers;
  19. gorilla_writer_t *writer;
  20. int aral_index;
  21. } page_gorilla_t;
  22. struct pgd {
  23. // the page type
  24. uint8_t type;
  25. // options related to the page
  26. PAGE_OPTIONS options;
  27. PGD_STATES states;
  28. // the uses number of slots in the page
  29. uint32_t used;
  30. // the total number of slots available in the page
  31. uint32_t slots;
  32. union {
  33. page_raw_t raw;
  34. page_gorilla_t gorilla;
  35. };
  36. };
  37. // ----------------------------------------------------------------------------
  38. // memory management
  39. struct {
  40. ARAL *aral_pgd;
  41. ARAL *aral_data[RRD_STORAGE_TIERS];
  42. ARAL *aral_gorilla_buffer[4];
  43. ARAL *aral_gorilla_writer[4];
  44. } pgd_alloc_globals = {};
  45. static ARAL *pgd_aral_data_lookup(size_t size)
  46. {
  47. for (size_t tier = 0; tier < storage_tiers; tier++)
  48. if (size == tier_page_size[tier])
  49. return pgd_alloc_globals.aral_data[tier];
  50. return NULL;
  51. }
  52. void pgd_init_arals(void)
  53. {
  54. // pgd aral
  55. {
  56. char buf[20 + 1];
  57. snprintfz(buf, sizeof(buf) - 1, "pgd");
  58. // FIXME: add stats
  59. pgd_alloc_globals.aral_pgd = aral_create(
  60. buf,
  61. sizeof(struct pgd),
  62. 64,
  63. 512 * (sizeof(struct pgd)),
  64. pgc_aral_statistics(),
  65. NULL, NULL, false, false);
  66. }
  67. // tier page aral
  68. {
  69. for (size_t i = storage_tiers; i > 0 ;i--)
  70. {
  71. size_t tier = storage_tiers - i;
  72. char buf[20 + 1];
  73. snprintfz(buf, sizeof(buf) - 1, "tier%zu-pages", tier);
  74. pgd_alloc_globals.aral_data[tier] = aral_create(
  75. buf,
  76. tier_page_size[tier],
  77. 64,
  78. 512 * (tier_page_size[tier]),
  79. pgc_aral_statistics(),
  80. NULL, NULL, false, false);
  81. }
  82. }
  83. // gorilla buffers aral
  84. for (size_t i = 0; i != 4; i++) {
  85. char buf[20 + 1];
  86. snprintfz(buf, sizeof(buf) - 1, "gbuffer-%zu", i);
  87. // FIXME: add stats
  88. pgd_alloc_globals.aral_gorilla_buffer[i] = aral_create(
  89. buf,
  90. GORILLA_BUFFER_SIZE,
  91. 64,
  92. 512 * GORILLA_BUFFER_SIZE,
  93. pgc_aral_statistics(),
  94. NULL, NULL, false, false);
  95. }
  96. // gorilla writers aral
  97. for (size_t i = 0; i != 4; i++) {
  98. char buf[20 + 1];
  99. snprintfz(buf, sizeof(buf) - 1, "gwriter-%zu", i);
  100. // FIXME: add stats
  101. pgd_alloc_globals.aral_gorilla_writer[i] = aral_create(
  102. buf,
  103. sizeof(gorilla_writer_t),
  104. 64,
  105. 512 * sizeof(gorilla_writer_t),
  106. pgc_aral_statistics(),
  107. NULL, NULL, false, false);
  108. }
  109. }
  110. static void *pgd_data_aral_alloc(size_t size)
  111. {
  112. ARAL *ar = pgd_aral_data_lookup(size);
  113. if (!ar)
  114. return mallocz(size);
  115. else
  116. return aral_mallocz(ar);
  117. }
  118. static void pgd_data_aral_free(void *page, size_t size)
  119. {
  120. ARAL *ar = pgd_aral_data_lookup(size);
  121. if (!ar)
  122. freez(page);
  123. else
  124. aral_freez(ar, page);
  125. }
  126. // ----------------------------------------------------------------------------
  127. // management api
  128. PGD *pgd_create(uint8_t type, uint32_t slots)
  129. {
  130. PGD *pg = aral_mallocz(pgd_alloc_globals.aral_pgd);
  131. pg->type = type;
  132. pg->used = 0;
  133. pg->slots = slots;
  134. pg->options = PAGE_OPTION_ALL_VALUES_EMPTY;
  135. pg->states = PGD_STATE_CREATED_FROM_COLLECTOR;
  136. switch (type) {
  137. case PAGE_METRICS:
  138. case PAGE_TIER: {
  139. uint32_t size = slots * page_type_size[type];
  140. internal_fatal(!size || slots == 1,
  141. "DBENGINE: invalid number of slots (%u) or page type (%u)", slots, type);
  142. pg->raw.size = size;
  143. pg->raw.data = pgd_data_aral_alloc(size);
  144. break;
  145. }
  146. case PAGE_GORILLA_METRICS: {
  147. internal_fatal(slots == 1,
  148. "DBENGINE: invalid number of slots (%u) or page type (%u)", slots, type);
  149. pg->slots = 8 * GORILLA_BUFFER_SLOTS;
  150. // allocate new gorilla writer
  151. pg->gorilla.aral_index = gettid() % 4;
  152. pg->gorilla.writer = aral_mallocz(pgd_alloc_globals.aral_gorilla_writer[pg->gorilla.aral_index]);
  153. // allocate new gorilla buffer
  154. gorilla_buffer_t *gbuf = aral_mallocz(pgd_alloc_globals.aral_gorilla_buffer[pg->gorilla.aral_index]);
  155. memset(gbuf, 0, GORILLA_BUFFER_SIZE);
  156. global_statistics_gorilla_buffer_add_hot();
  157. *pg->gorilla.writer = gorilla_writer_init(gbuf, GORILLA_BUFFER_SLOTS);
  158. pg->gorilla.num_buffers = 1;
  159. break;
  160. }
  161. default:
  162. fatal("Unknown page type: %uc", type);
  163. }
  164. return pg;
  165. }
  166. PGD *pgd_create_from_disk_data(uint8_t type, void *base, uint32_t size)
  167. {
  168. if (!size)
  169. return PGD_EMPTY;
  170. if (size < page_type_size[type])
  171. return PGD_EMPTY;
  172. PGD *pg = aral_mallocz(pgd_alloc_globals.aral_pgd);
  173. pg->type = type;
  174. pg->states = PGD_STATE_CREATED_FROM_DISK;
  175. pg->options = ~PAGE_OPTION_ALL_VALUES_EMPTY;
  176. switch (type)
  177. {
  178. case PAGE_METRICS:
  179. case PAGE_TIER:
  180. pg->raw.size = size;
  181. pg->used = size / page_type_size[type];
  182. pg->slots = pg->used;
  183. pg->raw.data = pgd_data_aral_alloc(size);
  184. memcpy(pg->raw.data, base, size);
  185. break;
  186. case PAGE_GORILLA_METRICS:
  187. internal_fatal(size == 0, "Asked to create page with 0 data!!!");
  188. internal_fatal(size % sizeof(uint32_t), "Unaligned gorilla buffer size");
  189. internal_fatal(size % GORILLA_BUFFER_SIZE, "Expected size to be a multiple of %zu-bytes", GORILLA_BUFFER_SIZE);
  190. pg->raw.data = mallocz(size);
  191. pg->raw.size = size;
  192. // TODO: rm this
  193. memset(pg->raw.data, 0, size);
  194. memcpy(pg->raw.data, base, size);
  195. uint32_t total_entries = gorilla_buffer_patch((void *) pg->raw.data);
  196. pg->used = total_entries;
  197. pg->slots = pg->used;
  198. break;
  199. default:
  200. fatal("Unknown page type: %uc", type);
  201. }
  202. return pg;
  203. }
  204. void pgd_free(PGD *pg)
  205. {
  206. if (!pg)
  207. return;
  208. if (pg == PGD_EMPTY)
  209. return;
  210. switch (pg->type)
  211. {
  212. case PAGE_METRICS:
  213. case PAGE_TIER:
  214. pgd_data_aral_free(pg->raw.data, pg->raw.size);
  215. break;
  216. case PAGE_GORILLA_METRICS: {
  217. if (pg->states & PGD_STATE_CREATED_FROM_DISK)
  218. {
  219. internal_fatal(pg->raw.data == NULL, "Tried to free gorilla PGD loaded from disk with NULL data");
  220. freez(pg->raw.data);
  221. pg->raw.data = NULL;
  222. }
  223. else if ((pg->states & PGD_STATE_CREATED_FROM_COLLECTOR) ||
  224. (pg->states & PGD_STATE_SCHEDULED_FOR_FLUSHING) ||
  225. (pg->states & PGD_STATE_FLUSHED_TO_DISK))
  226. {
  227. internal_fatal(pg->gorilla.writer == NULL,
  228. "PGD does not have an active gorilla writer");
  229. internal_fatal(pg->gorilla.num_buffers == 0,
  230. "PGD does not have any gorilla buffers allocated");
  231. while (true) {
  232. gorilla_buffer_t *gbuf = gorilla_writer_drop_head_buffer(pg->gorilla.writer);
  233. if (!gbuf)
  234. break;
  235. aral_freez(pgd_alloc_globals.aral_gorilla_buffer[pg->gorilla.aral_index], gbuf);
  236. pg->gorilla.num_buffers -= 1;
  237. }
  238. internal_fatal(pg->gorilla.num_buffers != 0,
  239. "Could not free all gorilla writer buffers");
  240. aral_freez(pgd_alloc_globals.aral_gorilla_writer[pg->gorilla.aral_index], pg->gorilla.writer);
  241. pg->gorilla.writer = NULL;
  242. } else {
  243. fatal("pgd_free() called on gorilla page with unsupported state");
  244. // TODO: should we support any other states?
  245. // if (!(pg->states & PGD_STATE_FLUSHED_TO_DISK))
  246. // fatal("pgd_free() is not supported yet for pages flushed to disk");
  247. }
  248. break;
  249. }
  250. default:
  251. fatal("Unknown page type: %uc", pg->type);
  252. }
  253. aral_freez(pgd_alloc_globals.aral_pgd, pg);
  254. }
  255. // ----------------------------------------------------------------------------
  256. // utility functions
  257. uint32_t pgd_type(PGD *pg)
  258. {
  259. return pg->type;
  260. }
  261. bool pgd_is_empty(PGD *pg)
  262. {
  263. if (!pg)
  264. return true;
  265. if (pg == PGD_EMPTY)
  266. return true;
  267. if (pg->used == 0)
  268. return true;
  269. if (pg->options & PAGE_OPTION_ALL_VALUES_EMPTY)
  270. return true;
  271. return false;
  272. }
  273. uint32_t pgd_slots_used(PGD *pg)
  274. {
  275. if (!pg)
  276. return 0;
  277. if (pg == PGD_EMPTY)
  278. return 0;
  279. return pg->used;
  280. }
  281. uint32_t pgd_memory_footprint(PGD *pg)
  282. {
  283. if (!pg)
  284. return 0;
  285. if (pg == PGD_EMPTY)
  286. return 0;
  287. size_t footprint = 0;
  288. switch (pg->type) {
  289. case PAGE_METRICS:
  290. case PAGE_TIER:
  291. footprint = sizeof(PGD) + pg->raw.size;
  292. break;
  293. case PAGE_GORILLA_METRICS: {
  294. if (pg->states & PGD_STATE_CREATED_FROM_DISK)
  295. footprint = sizeof(PGD) + pg->raw.size;
  296. else
  297. footprint = sizeof(PGD) + sizeof(gorilla_writer_t) + (pg->gorilla.num_buffers * GORILLA_BUFFER_SIZE);
  298. break;
  299. }
  300. default:
  301. fatal("Unknown page type: %uc", pg->type);
  302. }
  303. return footprint;
  304. }
  305. uint32_t pgd_disk_footprint(PGD *pg)
  306. {
  307. if (!pgd_slots_used(pg))
  308. return 0;
  309. size_t size = 0;
  310. switch (pg->type) {
  311. case PAGE_METRICS:
  312. case PAGE_TIER: {
  313. uint32_t used_size = pg->used * page_type_size[pg->type];
  314. internal_fatal(used_size > pg->raw.size, "Wrong disk footprint page size");
  315. size = used_size;
  316. break;
  317. }
  318. case PAGE_GORILLA_METRICS: {
  319. if (pg->states & PGD_STATE_CREATED_FROM_COLLECTOR ||
  320. pg->states & PGD_STATE_SCHEDULED_FOR_FLUSHING ||
  321. pg->states & PGD_STATE_FLUSHED_TO_DISK)
  322. {
  323. internal_fatal(!pg->gorilla.writer,
  324. "pgd_disk_footprint() not implemented for NULL gorilla writers");
  325. internal_fatal(pg->gorilla.num_buffers == 0,
  326. "Gorilla writer does not have any buffers");
  327. size = pg->gorilla.num_buffers * GORILLA_BUFFER_SIZE;
  328. if (pg->states & PGD_STATE_CREATED_FROM_COLLECTOR) {
  329. global_statistics_tier0_disk_compressed_bytes(gorilla_writer_nbytes(pg->gorilla.writer));
  330. global_statistics_tier0_disk_uncompressed_bytes(gorilla_writer_entries(pg->gorilla.writer) * sizeof(storage_number));
  331. }
  332. } else if (pg->states & PGD_STATE_CREATED_FROM_DISK) {
  333. size = pg->raw.size;
  334. } else {
  335. fatal("Asked disk footprint on unknown page state");
  336. }
  337. break;
  338. }
  339. default:
  340. fatal("Unknown page type: %uc", pg->type);
  341. }
  342. internal_fatal(pg->states & PGD_STATE_CREATED_FROM_DISK,
  343. "Disk footprint asked for page created from disk.");
  344. pg->states = PGD_STATE_SCHEDULED_FOR_FLUSHING;
  345. return size;
  346. }
  347. void pgd_copy_to_extent(PGD *pg, uint8_t *dst, uint32_t dst_size)
  348. {
  349. internal_fatal(pgd_disk_footprint(pg) != dst_size, "Wrong disk footprint size requested (need %u, available %u)",
  350. pgd_disk_footprint(pg), dst_size);
  351. switch (pg->type) {
  352. case PAGE_METRICS:
  353. case PAGE_TIER:
  354. memcpy(dst, pg->raw.data, dst_size);
  355. break;
  356. case PAGE_GORILLA_METRICS: {
  357. if ((pg->states & PGD_STATE_SCHEDULED_FOR_FLUSHING) == 0)
  358. fatal("Copying to extent is supported only for PGDs that are scheduled for flushing.");
  359. internal_fatal(!pg->gorilla.writer,
  360. "pgd_copy_to_extent() not implemented for NULL gorilla writers");
  361. internal_fatal(pg->gorilla.num_buffers == 0,
  362. "pgd_copy_to_extent() gorilla writer does not have any buffers");
  363. bool ok = gorilla_writer_serialize(pg->gorilla.writer, dst, dst_size);
  364. UNUSED(ok);
  365. internal_fatal(!ok,
  366. "pgd_copy_to_extent() tried to serialize pg=%p, gw=%p (with dst_size=%u bytes, num_buffers=%zu)",
  367. pg, pg->gorilla.writer, dst_size, pg->gorilla.num_buffers);
  368. break;
  369. }
  370. default:
  371. fatal("Unknown page type: %uc", pg->type);
  372. }
  373. pg->states = PGD_STATE_FLUSHED_TO_DISK;
  374. }
  375. // ----------------------------------------------------------------------------
  376. // data collection
  377. void pgd_append_point(PGD *pg,
  378. usec_t point_in_time_ut __maybe_unused,
  379. NETDATA_DOUBLE n,
  380. NETDATA_DOUBLE min_value,
  381. NETDATA_DOUBLE max_value,
  382. uint16_t count,
  383. uint16_t anomaly_count,
  384. SN_FLAGS flags,
  385. uint32_t expected_slot)
  386. {
  387. if (unlikely(pg->used >= pg->slots))
  388. fatal("DBENGINE: attempted to write beyond page size (page type %u, slots %u, used %u)",
  389. pg->type, pg->slots, pg->used /* FIXME:, pg->size */);
  390. if (unlikely(pg->used != expected_slot))
  391. fatal("DBENGINE: page is not aligned to expected slot (used %u, expected %u)",
  392. pg->used, expected_slot);
  393. if (!(pg->states & PGD_STATE_CREATED_FROM_COLLECTOR))
  394. fatal("DBENGINE: collection on page not created from a collector");
  395. if (pg->states & PGD_STATE_SCHEDULED_FOR_FLUSHING)
  396. fatal("Data collection on page already scheduled for flushing");
  397. switch (pg->type) {
  398. case PAGE_METRICS: {
  399. storage_number *tier0_metric_data = (storage_number *)pg->raw.data;
  400. storage_number t = pack_storage_number(n, flags);
  401. tier0_metric_data[pg->used++] = t;
  402. if ((pg->options & PAGE_OPTION_ALL_VALUES_EMPTY) && does_storage_number_exist(t))
  403. pg->options &= ~PAGE_OPTION_ALL_VALUES_EMPTY;
  404. break;
  405. }
  406. case PAGE_TIER: {
  407. storage_number_tier1_t *tier12_metric_data = (storage_number_tier1_t *)pg->raw.data;
  408. storage_number_tier1_t t;
  409. t.sum_value = (float) n;
  410. t.min_value = (float) min_value;
  411. t.max_value = (float) max_value;
  412. t.anomaly_count = anomaly_count;
  413. t.count = count;
  414. tier12_metric_data[pg->used++] = t;
  415. if ((pg->options & PAGE_OPTION_ALL_VALUES_EMPTY) && fpclassify(n) != FP_NAN)
  416. pg->options &= ~PAGE_OPTION_ALL_VALUES_EMPTY;
  417. break;
  418. }
  419. case PAGE_GORILLA_METRICS: {
  420. pg->used++;
  421. storage_number t = pack_storage_number(n, flags);
  422. if ((pg->options & PAGE_OPTION_ALL_VALUES_EMPTY) && does_storage_number_exist(t))
  423. pg->options &= ~PAGE_OPTION_ALL_VALUES_EMPTY;
  424. bool ok = gorilla_writer_write(pg->gorilla.writer, t);
  425. if (!ok) {
  426. gorilla_buffer_t *new_buffer = aral_mallocz(pgd_alloc_globals.aral_gorilla_buffer[pg->gorilla.aral_index]);
  427. memset(new_buffer, 0, GORILLA_BUFFER_SIZE);
  428. gorilla_writer_add_buffer(pg->gorilla.writer, new_buffer, GORILLA_BUFFER_SLOTS);
  429. pg->gorilla.num_buffers += 1;
  430. global_statistics_gorilla_buffer_add_hot();
  431. ok = gorilla_writer_write(pg->gorilla.writer, t);
  432. internal_fatal(ok == false, "Failed to writer value in newly allocated gorilla buffer.");
  433. }
  434. break;
  435. }
  436. default:
  437. fatal("DBENGINE: unknown page type id %d", pg->type);
  438. break;
  439. }
  440. }
  441. // ----------------------------------------------------------------------------
  442. // querying with cursor
  443. static void pgdc_seek(PGDC *pgdc, uint32_t position)
  444. {
  445. PGD *pg = pgdc->pgd;
  446. switch (pg->type) {
  447. case PAGE_METRICS:
  448. case PAGE_TIER:
  449. pgdc->slots = pgdc->pgd->used;
  450. break;
  451. case PAGE_GORILLA_METRICS: {
  452. if (pg->states & PGD_STATE_CREATED_FROM_DISK) {
  453. pgdc->slots = pgdc->pgd->slots;
  454. pgdc->gr = gorilla_reader_init((void *) pg->raw.data);
  455. } else {
  456. if (!(pg->states & PGD_STATE_CREATED_FROM_COLLECTOR) &&
  457. !(pg->states & PGD_STATE_SCHEDULED_FOR_FLUSHING) &&
  458. !(pg->states & PGD_STATE_FLUSHED_TO_DISK))
  459. fatal("pgdc_seek() currently is not supported for pages created from disk.");
  460. if (!pg->gorilla.writer)
  461. fatal("Seeking from a page without an active gorilla writer is not supported (yet).");
  462. pgdc->slots = gorilla_writer_entries(pg->gorilla.writer);
  463. pgdc->gr = gorilla_writer_get_reader(pg->gorilla.writer);
  464. }
  465. if (position > pgdc->slots)
  466. position = pgdc->slots;
  467. for (uint32_t i = 0; i != position; i++) {
  468. uint32_t value;
  469. bool ok = gorilla_reader_read(&pgdc->gr, &value);
  470. if (!ok) {
  471. // this is fine, the reader will return empty points
  472. break;
  473. }
  474. }
  475. break;
  476. }
  477. default:
  478. fatal("DBENGINE: unknown page type id %d", pg->type);
  479. break;
  480. }
  481. }
  482. void pgdc_reset(PGDC *pgdc, PGD *pgd, uint32_t position)
  483. {
  484. // pgd might be null and position equal to UINT32_MAX
  485. pgdc->pgd = pgd;
  486. pgdc->position = position;
  487. if (!pgd)
  488. return;
  489. if (pgd == PGD_EMPTY)
  490. return;
  491. if (position == UINT32_MAX)
  492. return;
  493. pgdc_seek(pgdc, position);
  494. }
  495. bool pgdc_get_next_point(PGDC *pgdc, uint32_t expected_position, STORAGE_POINT *sp)
  496. {
  497. if (!pgdc->pgd || pgdc->pgd == PGD_EMPTY || pgdc->position >= pgdc->slots)
  498. {
  499. storage_point_empty(*sp, sp->start_time_s, sp->end_time_s);
  500. return false;
  501. }
  502. internal_fatal(pgdc->position != expected_position, "Wrong expected cursor position");
  503. switch (pgdc->pgd->type)
  504. {
  505. case PAGE_METRICS: {
  506. storage_number *array = (storage_number *) pgdc->pgd->raw.data;
  507. storage_number n = array[pgdc->position++];
  508. sp->min = sp->max = sp->sum = unpack_storage_number(n);
  509. sp->flags = (SN_FLAGS)(n & SN_USER_FLAGS);
  510. sp->count = 1;
  511. sp->anomaly_count = is_storage_number_anomalous(n) ? 1 : 0;
  512. return true;
  513. }
  514. case PAGE_TIER: {
  515. storage_number_tier1_t *array = (storage_number_tier1_t *) pgdc->pgd->raw.data;
  516. storage_number_tier1_t n = array[pgdc->position++];
  517. sp->flags = n.anomaly_count ? SN_FLAG_NONE : SN_FLAG_NOT_ANOMALOUS;
  518. sp->count = n.count;
  519. sp->anomaly_count = n.anomaly_count;
  520. sp->min = n.min_value;
  521. sp->max = n.max_value;
  522. sp->sum = n.sum_value;
  523. return true;
  524. }
  525. case PAGE_GORILLA_METRICS: {
  526. pgdc->position++;
  527. uint32_t n = 666666666;
  528. bool ok = gorilla_reader_read(&pgdc->gr, &n);
  529. if (ok) {
  530. sp->min = sp->max = sp->sum = unpack_storage_number(n);
  531. sp->flags = (SN_FLAGS)(n & SN_USER_FLAGS);
  532. sp->count = 1;
  533. sp->anomaly_count = is_storage_number_anomalous(n) ? 1 : 0;
  534. } else {
  535. storage_point_empty(*sp, sp->start_time_s, sp->end_time_s);
  536. }
  537. return ok;
  538. }
  539. default: {
  540. static bool logged = false;
  541. if (!logged)
  542. {
  543. netdata_log_error("DBENGINE: unknown page type %d found. Cannot decode it. Ignoring its metrics.", pgd_type(pgdc->pgd));
  544. logged = true;
  545. }
  546. storage_point_empty(*sp, sp->start_time_s, sp->end_time_s);
  547. return false;
  548. }
  549. }
  550. }