@cryptotaxi247 / netdata-1 / commits / ed2d5542c

Replace assert calls (#9349)

* Replace all assert() calls with the new fatal_assert() for proper logging.

Markos Fountoulakis committed Jun 16, 2020 at 21:57 UTC ed2d5542cc6000d80a7d4377435cc175cfd519e4
22 files changed +163 -162
collectors/freeipmi.plugin/freeipmi_plugin.c
+3 -3
@@ -160,7 +160,7 @@ char *sel_config_file = NULL;
160 static void
161 _init_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config)
162 {
163 - assert (ipmi_config);
163 + fatal_assert(ipmi_config);
164
165 ipmi_config->driver_type = driver_type;
166 ipmi_config->disable_auto_probe = disable_auto_probe;
@@ -1580,7 +1580,7 @@ int ipmi_detect_speed_secs(struct ipmi_monitoring_ipmi_config *ipmi_config) {
1580
1581 int parse_inband_driver_type (const char *str)
1582 {
1583 - assert (str);
1583 + fatal_assert(str);
1584
1585 if (strcasecmp (str, IPMI_PARSE_DEVICE_KCS_STR) == 0)
1586 return (IPMI_MONITORING_DRIVER_TYPE_KCS);
@@ -1604,7 +1604,7 @@ int parse_inband_driver_type (const char *str)
1604
1605 int parse_outofband_driver_type (const char *str)
1606 {
1607 - assert (str);
1607 + fatal_assert(str);
1608
1609 if (strcasecmp (str, IPMI_PARSE_DEVICE_LAN_STR) == 0)
1610 return (IPMI_MONITORING_PROTOCOL_VERSION_1_5);
daemon/commands.c
+8 -8
@@ -474,7 +474,7 @@ static void parse_commands(struct command_context *cmd_ctx)
474 cmd_ctx->args = lstrip;
475 cmd_ctx->message = NULL;
476
477 - assert(0 == uv_queue_work(loop, &cmd_ctx->work, schedule_command, after_schedule_command));
477 + fatal_assert(0 == uv_queue_work(loop, &cmd_ctx->work, schedule_command, after_schedule_command));
478 break;
479 }
480 }
@@ -533,7 +533,7 @@ static void connection_cb(uv_stream_t *server, int status)
533 int ret;
534 uv_pipe_t *client;
535 struct command_context *cmd_ctx;
536 - assert(status == 0);
536 + fatal_assert(status == 0);
537
538 /* combined allocation of client pipe and command context */
539 cmd_ctx = mallocz(sizeof(*cmd_ctx));
@@ -636,7 +636,7 @@ static void command_thread(void *arg)
636 uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */
637
638 info("Shutting down command loop complete.");
639 - assert(0 == uv_loop_close(loop));
639 + fatal_assert(0 == uv_loop_close(loop));
640 freez(loop);
641
642 return;
@@ -648,7 +648,7 @@ error_after_pipe_init:
648 uv_close((uv_handle_t *)&async, NULL);
649 error_after_async_init:
650 uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */
651 - assert(0 == uv_loop_close(loop));
651 + fatal_assert(0 == uv_loop_close(loop));
652 error_after_loop_init:
653 freez(loop);
654
@@ -673,9 +673,9 @@ void commands_init(void)
673
674 info("Initializing command server.");
675 for (i = 0 ; i < CMD_TOTAL_COMMANDS ; ++i) {
676 - assert(0 == uv_mutex_init(&command_lock_array[i]));
676 + fatal_assert(0 == uv_mutex_init(&command_lock_array[i]));
677 }
678 - assert(0 == uv_rwlock_init(&exclusive_rwlock));
678 + fatal_assert(0 == uv_rwlock_init(&exclusive_rwlock));
679
680 init_completion(&completion);
681 error = uv_thread_create(&thread, command_thread, NULL);
@@ -713,8 +713,8 @@ void commands_exit(void)
713 command_thread_shutdown = 1;
714 info("Shutting down command server.");
715 /* wake up event loop */
716 - assert(0 == uv_async_send(&async));
717 - assert(0 == uv_thread_join(&thread));
716 + fatal_assert(0 == uv_async_send(&async));
717 + fatal_assert(0 == uv_thread_join(&thread));
718
719 for (i = 0 ; i < CMD_TOTAL_COMMANDS ; ++i) {
720 uv_mutex_destroy(&command_lock_array[i]);
database/engine/datafile.c
+5 -5
@@ -30,7 +30,7 @@ void datafile_list_delete(struct rrdengine_instance *ctx, struct rrdengine_dataf
30 struct rrdengine_datafile *next;
31
32 next = datafile->next;
33 - assert((NULL != next) && (ctx->datafiles.first == datafile) && (ctx->datafiles.last != datafile));
33 + fatal_assert((NULL != next) && (ctx->datafiles.first == datafile) && (ctx->datafiles.last != datafile));
34 ctx->datafiles.first = next;
35 }
36
@@ -38,7 +38,7 @@ void datafile_list_delete(struct rrdengine_instance *ctx, struct rrdengine_dataf
38 static void datafile_init(struct rrdengine_datafile *datafile, struct rrdengine_instance *ctx,
39 unsigned tier, unsigned fileno)
40 {
41 - assert(tier == 1);
41 + fatal_assert(tier == 1);
42 datafile->tier = tier;
43 datafile->fileno = fileno;
44 datafile->file = (uv_file)0;
@@ -146,7 +146,7 @@ int create_data_file(struct rrdengine_datafile *datafile)
146
147 ret = uv_fs_write(NULL, &req, file, &iov, 1, 0, NULL);
148 if (ret < 0) {
149 - assert(req.result < 0);
149 + fatal_assert(req.result < 0);
150 error("uv_fs_write: %s", uv_strerror(ret));
151 ++ctx->stats.io_errors;
152 rrd_stat_atomic_add(&global_io_errors, 1);
@@ -184,7 +184,7 @@ static int check_data_file_superblock(uv_file file)
184 uv_fs_req_cleanup(&req);
185 goto error;
186 }
187 - assert(req.result >= 0);
187 + fatal_assert(req.result >= 0);
188 uv_fs_req_cleanup(&req);
189
190 if (strncmp(superblock->magic_number, RRDENG_DF_MAGIC, RRDENG_MAGIC_SZ) ||
@@ -271,7 +271,7 @@ static int scan_data_files(struct rrdengine_instance *ctx)
271
272 ret = uv_fs_scandir(NULL, &req, ctx->dbfiles_path, 0, NULL);
273 if (ret < 0) {
274 - assert(req.result < 0);
274 + fatal_assert(req.result < 0);
275 uv_fs_req_cleanup(&req);
276 error("uv_fs_scandir(%s): %s", ctx->dbfiles_path, uv_strerror(ret));
277 ++ctx->stats.fs_errors;
database/engine/global_uuid_map/global_uuid_map.c
+3 -3
@@ -254,9 +254,9 @@ void init_global_guid_map()
254
255 init = 1;
256 info("Configuring locking mechanism for global GUID map");
257 - assert(0 == uv_rwlock_init(&guid_lock));
258 - assert(0 == uv_rwlock_init(&object_lock));
259 - assert(0 == uv_rwlock_init(&global_lock));
257 + fatal_assert(0 == uv_rwlock_init(&guid_lock));
258 + fatal_assert(0 == uv_rwlock_init(&object_lock));
259 + fatal_assert(0 == uv_rwlock_init(&global_lock));
260
261 // int rc = guid_bulk_load("6fc56a64-05d7-47a7-bc82-7f3235d8cbda","d6b37186-74db-11ea-88b2-0bf5095b1f9e/cgroup_qemu_ubuntu18.04.cpu_per_core/cpu3");
262 // rc = guid_bulk_load("75c6fa02-97cc-40c1-aacd-a0132190472e","d6b37186-74db-11ea-88b2-0bf5095b1f9e/services.throttle_io_ops_write/system.slice_setvtrgb.service");
database/engine/journalfile.c
+6 -6
@@ -52,7 +52,7 @@ void wal_flush_transaction_buffer(struct rrdengine_worker_config* wc)
52 io_descr->iov = uv_buf_init((void *)io_descr->buf, size);
53 ret = uv_fs_write(wc->loop, &io_descr->req, journalfile->file, &io_descr->iov, 1,
54 journalfile->pos, flush_transaction_buffer_cb);
55 - assert (-1 != ret);
55 + fatal_assert(-1 != ret);
56 journalfile->pos += RRDENG_BLOCK_SIZE;
57 ctx->disk_space += RRDENG_BLOCK_SIZE;
58 ctx->commit_log.buf = NULL;
@@ -66,7 +66,7 @@ void * wal_get_transaction_buffer(struct rrdengine_worker_config* wc, unsigned s
66 int ret;
67 unsigned buf_pos, buf_size;
68
69 - assert(size);
69 + fatal_assert(size);
70 if (ctx->commit_log.buf) {
71 unsigned remaining;
72
@@ -194,7 +194,7 @@ int create_journal_file(struct rrdengine_journalfile *journalfile, struct rrdeng
194
195 ret = uv_fs_write(NULL, &req, file, &iov, 1, 0, NULL);
196 if (ret < 0) {
197 - assert(req.result < 0);
197 + fatal_assert(req.result < 0);
198 error("uv_fs_write: %s", uv_strerror(ret));
199 ++ctx->stats.io_errors;
200 rrd_stat_atomic_add(&global_io_errors, 1);
@@ -232,7 +232,7 @@ static int check_journal_file_superblock(uv_file file)
232 uv_fs_req_cleanup(&req);
233 goto error;
234 }
235 - assert(req.result >= 0);
235 + fatal_assert(req.result >= 0);
236 uv_fs_req_cleanup(&req);
237
238 if (strncmp(superblock->magic_number, RRDENG_JF_MAGIC, RRDENG_MAGIC_SZ) ||
@@ -293,7 +293,7 @@ static void restore_extent_metadata(struct rrdengine_instance *ctx, struct rrden
293 /* First time we see the UUID */
294 uv_rwlock_wrlock(&pg_cache->metrics_index.lock);
295 PValue = JudyHSIns(&pg_cache->metrics_index.JudyHS_array, temp_id, sizeof(uuid_t), PJE0);
296 - assert(NULL == *PValue); /* TODO: figure out concurrency model */
296 + fatal_assert(NULL == *PValue); /* TODO: figure out concurrency model */
297 *PValue = page_index = create_page_index(temp_id);
298 page_index->prev = pg_cache->metrics_index.last_page_index;
299 pg_cache->metrics_index.last_page_index = page_index;
@@ -408,7 +408,7 @@ static uint64_t iterate_transactions(struct rrdengine_instance *ctx, struct rrde
408 fatal("uv_fs_read: %s", uv_strerror(ret));
409 /*uv_fs_req_cleanup(&req);*/
410 }
411 - assert(req.result >= 0);
411 + fatal_assert(req.result >= 0);
412 uv_fs_req_cleanup(&req);
413 ctx->stats.io_read_bytes += size_bytes;
414 ++ctx->stats.io_read_requests;
database/engine/metadata_log/compaction.c
+7 -7
@@ -87,7 +87,7 @@ static void compact_record_by_uuid(struct metalog_instance *ctx, uuid_t *uuid)
87 ret = find_object_by_guid(uuid, NULL, 0);
88 switch (ret) {
89 case GUID_TYPE_CHAR:
90 - assert(0);
90 + fatal_assert(0);
91 break;
92 case GUID_TYPE_CHART:
93 st = metalog_get_chart_from_uuid(ctx, uuid);
@@ -130,7 +130,7 @@ static void compact_record_by_uuid(struct metalog_instance *ctx, uuid_t *uuid)
130 debug(D_METADATALOG, "Ignoring nonexistent metadata record.");
131 break;
132 default:
133 - assert(0);
133 + fatal_assert(0);
134 break;
135 }
136 }
@@ -221,7 +221,7 @@ static void compact_old_records(void *arg)
221 break;
222 }
223 }
224 - assert(nextmetalogfile); /* There are always more than 1 metadata log files during compaction */
224 + fatal_assert(nextmetalogfile); /* There are always more than 1 metadata log files during compaction */
225
226 newmetalogfile = compaction_state->new_metadata_logfiles.last;
227 if (newmetalogfile->starting_fileno != 0) { /* Must rename the last compacted file */
@@ -237,7 +237,7 @@ static void compact_old_records(void *arg)
237
238 wc->cleanup_thread_compacting_files = 1;
239 /* wake up event loop */
240 - assert(0 == uv_async_send(&wc->async));
240 + fatal_assert(0 == uv_async_send(&wc->async));
241 }
242
243 /* Returns 0 on success. */
@@ -262,7 +262,7 @@ static int init_compaction_state(struct metalog_instance *ctx)
262 return ret;
263 }
264 newmetalogfile = compaction_state->new_metadata_logfiles.first;
265 - assert(newmetalogfile == compaction_state->new_metadata_logfiles.last);
265 + fatal_assert(newmetalogfile == compaction_state->new_metadata_logfiles.last);
266 init_metadata_record_log(&compaction_state->records_log);
267
268 return 0;
@@ -329,7 +329,7 @@ int compaction_failure_recovery(struct metalog_instance *ctx, struct metadata_lo
329
330 for (j = 0, recovered_files = 0 ; j < i ; ++j) {
331 metalogfile = metalogfiles[j];
332 - assert(0 == metalogfile->starting_fileno);
332 + fatal_assert(0 == metalogfile->starting_fileno);
333 if (metalogfile->fileno < starting_fileno) {
334 tmp_metalogfiles[recovered_files++] = metalogfile;
335 continue;
@@ -352,7 +352,7 @@ int compaction_failure_recovery(struct metalog_instance *ctx, struct metadata_lo
352
353 for ( ; j < i ; ++j) { /* continue iterating through normal metadata log files */
354 metalogfile = metalogfiles[j];
355 - assert(0 == metalogfile->starting_fileno);
355 + fatal_assert(0 == metalogfile->starting_fileno);
356 if (metalogfile->fileno < fileno) { /* It has already been compacted */
357 error("Deleting invalid metadata log file \"%s/"METALOG_PREFIX METALOG_FILE_NUMBER_PRINT_TMPL
358 METALOG_EXTENSION"\"", dbfiles_path, 0U, metalogfile->fileno);
database/engine/metadata_log/logfile.c
+6 -6
@@ -118,7 +118,7 @@ void mlf_flush_records_buffer(struct metalog_worker_config *wc, struct metadata_
118 io_descr->iov = uv_buf_init((void *)io_descr->buf, size);
119 ret = uv_fs_write(wc->loop, &io_descr->req, metalogfile->file, &io_descr->iov, 1,
120 metalogfile->pos, flush_records_buffer_cb);
121 - assert (-1 != ret);
121 + fatal_assert(-1 != ret);
122 metalogfile->pos += size;
123 rrd_atomic_fetch_add(&ctx->disk_space, size);
124 records_log->buf = NULL;
@@ -132,7 +132,7 @@ void *mlf_get_records_buffer(struct metalog_worker_config *wc, struct metadata_r
132 int ret;
133 unsigned buf_pos, buf_size;
134
135 - assert(size);
135 + fatal_assert(size);
136 if (records_log->buf) {
137 unsigned remaining;
138
@@ -175,7 +175,7 @@ void metadata_logfile_list_delete(struct metadata_logfile_list *metadata_logfile
175 struct metadata_logfile *next;
176
177 next = metalogfile->next;
178 - assert((NULL != next) && (metadata_logfiles->first == metalogfile) &&
178 + fatal_assert((NULL != next) && (metadata_logfiles->first == metalogfile) &&
179 (metadata_logfiles->last != metalogfile));
180 metadata_logfiles->first = next;
181 }
@@ -337,7 +337,7 @@ int create_metadata_logfile(struct metadata_logfile *metalogfile)
337
338 ret = uv_fs_write(NULL, &req, file, &iov, 1, 0, NULL);
339 if (ret < 0) {
340 - assert(req.result < 0);
340 + fatal_assert(req.result < 0);
341 error("uv_fs_write: %s", uv_strerror(ret));
342 ++ctx->stats.io_errors;
343 rrd_stat_atomic_add(&global_io_errors, 1);
@@ -375,7 +375,7 @@ static int check_metadata_logfile_superblock(uv_file file)
375 uv_fs_req_cleanup(&req);
376 goto error;
377 }
378 - assert(req.result >= 0);
378 + fatal_assert(req.result >= 0);
379 uv_fs_req_cleanup(&req);
380
381 if (strncmp(superblock->magic_number, RRDENG_METALOG_MAGIC, RRDENG_MAGIC_SZ)) {
@@ -614,7 +614,7 @@ static int scan_metalog_files(struct metalog_instance *ctx)
614
615 ret = uv_fs_scandir(NULL, &req, dbfiles_path, 0, NULL);
616 if (ret < 0) {
617 - assert(req.result < 0);
617 + fatal_assert(req.result < 0);
618 uv_fs_req_cleanup(&req);
619 error("uv_fs_scandir(%s): %s", dbfiles_path, uv_strerror(ret));
620 ++ctx->stats.fs_errors;
database/engine/metadata_log/metadatalog.c
+10 -10
@@ -52,8 +52,8 @@ void metalog_commit_record(struct metalog_instance *ctx, BUFFER *buffer, enum me
52 {
53 struct metalog_cmd cmd;
54
55 - assert(buffer_strlen(buffer));
56 - assert(opcode == METALOG_COMMIT_CREATION_RECORD || opcode == METALOG_COMMIT_DELETION_RECORD);
55 + fatal_assert(buffer_strlen(buffer));
56 + fatal_assert(opcode == METALOG_COMMIT_CREATION_RECORD || opcode == METALOG_COMMIT_DELETION_RECORD);
57
58 cmd.opcode = opcode;
59 cmd.record_io_descr.buffer = buffer;
@@ -191,8 +191,8 @@ static void metalog_init_cmd_queue(struct metalog_worker_config *wc)
191 {
192 wc->cmd_queue.head = wc->cmd_queue.tail = 0;
193 wc->queue_size = 0;
194 - assert(0 == uv_cond_init(&wc->cmd_cond));
195 - assert(0 == uv_mutex_init(&wc->cmd_mutex));
194 + fatal_assert(0 == uv_cond_init(&wc->cmd_cond));
195 + fatal_assert(0 == uv_mutex_init(&wc->cmd_mutex));
196 }
197
198 void metalog_enq_cmd(struct metalog_worker_config *wc, struct metalog_cmd *cmd)
@@ -204,7 +204,7 @@ void metalog_enq_cmd(struct metalog_worker_config *wc, struct metalog_cmd *cmd)
204 while ((queue_size = wc->queue_size) == METALOG_CMD_Q_MAX_SIZE) {
205 uv_cond_wait(&wc->cmd_cond, &wc->cmd_mutex);
206 }
207 - assert(queue_size < METALOG_CMD_Q_MAX_SIZE);
207 + fatal_assert(queue_size < METALOG_CMD_Q_MAX_SIZE);
208 /* enqueue command */
209 wc->cmd_queue.cmd_array[wc->cmd_queue.tail] = *cmd;
210 wc->cmd_queue.tail = wc->cmd_queue.tail != METALOG_CMD_Q_MAX_SIZE - 1 ?
@@ -213,7 +213,7 @@ void metalog_enq_cmd(struct metalog_worker_config *wc, struct metalog_cmd *cmd)
213 uv_mutex_unlock(&wc->cmd_mutex);
214
215 /* wake up event loop */
216 - assert(0 == uv_async_send(&wc->async));
216 + fatal_assert(0 == uv_async_send(&wc->async));
217 }
218
219 struct metalog_cmd metalog_deq_cmd(struct metalog_worker_config *wc)
@@ -318,7 +318,7 @@ void metalog_worker(void* arg)
318 /* wake up initialization thread */
319 complete(&ctx->metalog_completion);
320
321 - assert(0 == uv_timer_start(&timer_req, timer_cb, TIMER_PERIOD_MS, TIMER_PERIOD_MS));
321 + fatal_assert(0 == uv_timer_start(&timer_req, timer_cb, TIMER_PERIOD_MS, TIMER_PERIOD_MS));
322 shutdown = 0;
323 while (likely(shutdown == 0 || metalog_threads_alive(wc))) {
324 uv_run(loop, UV_RUN_DEFAULT);
@@ -347,7 +347,7 @@ void metalog_worker(void* arg)
347 break;
348 case METALOG_QUIESCE:
349 ctx->quiesce = SET_QUIESCE;
350 - assert(0 == uv_timer_stop(&timer_req));
350 + fatal_assert(0 == uv_timer_stop(&timer_req));
351 uv_close((uv_handle_t *)&timer_req, NULL);
352 mlf_flush_records_buffer(wc, &ctx->records_log, &ctx->metadata_logfiles);
353 if (!metalog_threads_alive(wc)) {
@@ -390,7 +390,7 @@ void metalog_worker(void* arg)
390 /* TODO: don't let the API block by waiting to enqueue commands */
391 uv_cond_destroy(&wc->cmd_cond);
392 /* uv_mutex_destroy(&wc->cmd_mutex); */
393 - assert(0 == uv_loop_close(loop));
393 + fatal_assert(0 == uv_loop_close(loop));
394 freez(loop);
395
396 return;
@@ -398,7 +398,7 @@ void metalog_worker(void* arg)
398 error_after_timer_init:
399 uv_close((uv_handle_t *)&wc->async, NULL);
400 error_after_async_init:
401 - assert(0 == uv_loop_close(loop));
401 + fatal_assert(0 == uv_loop_close(loop));
402 error_after_loop_init:
403 freez(loop);
404
database/engine/metadata_log/metadatalogapi.c
+10 -10
@@ -273,16 +273,16 @@ RRDSET *metalog_get_chart_from_uuid(struct metalog_instance *ctx, uuid_t *chart_
273 uuid_t *machine_guid, *chart_char_guid;
274
275 ret = find_object_by_guid(chart_uuid, chart_object, 33);
276 - assert(GUID_TYPE_CHART == ret);
276 + fatal_assert(GUID_TYPE_CHART == ret);
277
278 machine_guid = (uuid_t *)chart_object;
279 RRDHOST *host = ctx->rrdeng_ctx->host;
280 - assert(!uuid_compare(host->host_uuid, *machine_guid));
280 + fatal_assert(!uuid_compare(host->host_uuid, *machine_guid));
281
282 chart_char_guid = (uuid_t *)(chart_object + 16);
283
284 ret = find_object_by_guid(chart_char_guid, chart_fullid, RRD_ID_LENGTH_MAX + 1);
285 - assert(GUID_TYPE_CHAR == ret);
285 + fatal_assert(GUID_TYPE_CHAR == ret);
286 RRDSET *st = rrdset_find(host, chart_fullid);
287
288 return st;
@@ -300,22 +300,22 @@ RRDDIM *metalog_get_dimension_from_uuid(struct metalog_instance *ctx, uuid_t *me
300
301 machine_guid = (uuid_t *)dim_object;
302 RRDHOST *host = ctx->rrdeng_ctx->host;
303 - assert(!uuid_compare(host->host_uuid, *machine_guid));
303 + fatal_assert(!uuid_compare(host->host_uuid, *machine_guid));
304
305 chart_guid = (uuid_t *)(dim_object + 16);
306 dim_char_guid = (uuid_t *)(dim_object + 16 + 16);
307
308 ret = find_object_by_guid(dim_char_guid, id_str, sizeof(id_str));
309 - assert(GUID_TYPE_CHAR == ret);
309 + fatal_assert(GUID_TYPE_CHAR == ret);
310
311 ret = find_object_by_guid(chart_guid, chart_object, sizeof(chart_object));
312 - assert(GUID_TYPE_CHART == ret);
312 + fatal_assert(GUID_TYPE_CHART == ret);
313 chart_char_guid = (uuid_t *)(chart_object + 16);
314
315 ret = find_object_by_guid(chart_char_guid, chart_fullid, RRD_ID_LENGTH_MAX + 1);
316 - assert(GUID_TYPE_CHAR == ret);
316 + fatal_assert(GUID_TYPE_CHAR == ret);
317 RRDSET *st = rrdset_find(host, chart_fullid);
318 - assert(st);
318 + fatal_assert(st);
319
320 RRDDIM *rd = rrddim_find(st, id_str);
321
@@ -386,7 +386,7 @@ int metalog_init(struct rrdengine_instance *rrdeng_parent_ctx)
386 }
387
388 init_completion(&ctx->metalog_completion);
389 - assert(0 == uv_thread_create(&ctx->worker_config.thread, metalog_worker, &ctx->worker_config));
389 + fatal_assert(0 == uv_thread_create(&ctx->worker_config.thread, metalog_worker, &ctx->worker_config));
390 /* wait for worker thread to initialize */
391 wait_for_completion(&ctx->metalog_completion);
392 destroy_completion(&ctx->metalog_completion);
@@ -418,7 +418,7 @@ int metalog_exit(struct metalog_instance *ctx)
418 cmd.opcode = METALOG_SHUTDOWN;
419 metalog_enq_cmd(&ctx->worker_config, &cmd);
420
421 - assert(0 == uv_thread_join(&ctx->worker_config.thread));
421 + fatal_assert(0 == uv_thread_join(&ctx->worker_config.thread));
422
423 finalize_metalog_files(ctx);
424 freez(ctx);
database/engine/metadata_log/metalogpluginsd.c
+6 -6
@@ -117,7 +117,7 @@ PARSER_RC metalog_pluginsd_context_action(void *user, uuid_t *uuid)
117 ret = find_object_by_guid(uuid, object, 49);
118 switch (ret) {
119 case GUID_TYPE_CHAR:
120 - assert(0);
120 + fatal_assert(0);
121 break;
122 case GUID_TYPE_CHART:
123 case GUID_TYPE_DIMENSION:
@@ -127,22 +127,22 @@ PARSER_RC metalog_pluginsd_context_action(void *user, uuid_t *uuid)
127 chart_char_guid = (uuid_t *)(object + 16);
128
129 ret = find_object_by_guid(chart_char_guid, id_str, RRD_ID_LENGTH_MAX + 1);
130 - assert(GUID_TYPE_CHAR == ret);
130 + fatal_assert(GUID_TYPE_CHAR == ret);
131 ((PARSER_USER_OBJECT *) user)->st = rrdset_find(host, id_str);
132 break;
133 case GUID_TYPE_DIMENSION:
134 chart_guid = (uuid_t *)(object + 16);
135
136 ret = find_object_by_guid(chart_guid, chart_object, 33);
137 - assert(GUID_TYPE_CHART == ret);
137 + fatal_assert(GUID_TYPE_CHART == ret);
138 chart_char_guid = (uuid_t *)(chart_object + 16);
139
140 ret = find_object_by_guid(chart_char_guid, id_str, RRD_ID_LENGTH_MAX + 1);
141 - assert(GUID_TYPE_CHAR == ret);
141 + fatal_assert(GUID_TYPE_CHAR == ret);
142 ((PARSER_USER_OBJECT *) user)->st = rrdset_find(host, id_str);
143 break;
144 default:
145 - assert(0);
145 + fatal_assert(0);
146 break;
147 }
148 break;
@@ -168,7 +168,7 @@ PARSER_RC metalog_pluginsd_tombstone_action(void *user, uuid_t *uuid)
168 ret = find_object_by_guid(uuid, NULL, 0);
169 switch (ret) {
170 case GUID_TYPE_CHAR:
171 - assert(0);
171 + fatal_assert(0);
172 break;
173 case GUID_TYPE_CHART:
174 st = metalog_get_chart_from_uuid(ctx, uuid);
database/engine/pagecache.c
+15 -15
@@ -406,7 +406,7 @@ uint8_t pg_cache_punch_hole(struct rrdengine_instance *ctx, struct rrdeng_page_d
406
407 uv_rwlock_rdlock(&pg_cache->metrics_index.lock);
408 PValue = JudyHSGet(pg_cache->metrics_index.JudyHS_array, descr->id, sizeof(uuid_t));
409 - assert(NULL != PValue);
409 + fatal_assert(NULL != PValue);
410 page_index = *PValue;
411 uv_rwlock_rdunlock(&pg_cache->metrics_index.lock);
412
@@ -428,7 +428,7 @@ uint8_t pg_cache_punch_hole(struct rrdengine_instance *ctx, struct rrdeng_page_d
428 }
429 }
430 uv_rwlock_wrunlock(&page_index->lock);
431 - assert(1 == ret);
431 + fatal_assert(1 == ret);
432
433 uv_rwlock_wrlock(&pg_cache->pg_cache_rwlock);
434 ++ctx->stats.pg_cache_deletions;
@@ -565,7 +565,7 @@ void pg_cache_update_metric_times(struct pg_cache_page_index *page_index)
565 uv_rwlock_rdunlock(&page_index->lock);
566
567 if (unlikely(NULL == firstPValue)) {
568 - assert(NULL == lastPValue);
568 + fatal_assert(NULL == lastPValue);
569 page_index->oldest_time = page_index->latest_time = INVALID_TIME;
570 return;
571 }
@@ -586,7 +586,7 @@ void pg_cache_insert(struct rrdengine_instance *ctx, struct pg_cache_page_index
586 /* there is page cache descriptor pre-allocated state */
587 struct page_cache_descr *pg_cache_descr = descr->pg_cache_descr;
588
589 - assert(pg_cache_descr_state & PG_CACHE_DESCR_ALLOCATED);
589 + fatal_assert(pg_cache_descr_state & PG_CACHE_DESCR_ALLOCATED);
590 if (pg_cache_descr->flags & RRD_PAGE_POPULATED) {
591 pg_cache_reserve_pages(ctx, 1);
592 if (!(pg_cache_descr->flags & RRD_PAGE_DIRTY))
@@ -597,7 +597,7 @@ void pg_cache_insert(struct rrdengine_instance *ctx, struct pg_cache_page_index
597 if (unlikely(NULL == index)) {
598 uv_rwlock_rdlock(&pg_cache->metrics_index.lock);
599 PValue = JudyHSGet(pg_cache->metrics_index.JudyHS_array, descr->id, sizeof(uuid_t));
600 - assert(NULL != PValue);
600 + fatal_assert(NULL != PValue);
601 page_index = *PValue;
602 uv_rwlock_rdunlock(&pg_cache->metrics_index.lock);
603 } else {
@@ -662,7 +662,7 @@ void pg_cache_get_filtered_info_prev(struct rrdengine_instance *ctx, struct pg_c
662 Word_t Index;
663
664 (void)pg_cache;
665 - assert(NULL != page_index);
665 + fatal_assert(NULL != page_index);
666
667 Index = (Word_t)(point_in_time / USEC_PER_SEC);
668 uv_rwlock_rdlock(&page_index->lock);
@@ -707,7 +707,7 @@ unsigned pg_cache_preload(struct rrdengine_instance *ctx, uuid_t *id, usec_t sta
707 Word_t Index;
708 uint8_t failed_to_reserve;
709
710 - assert(NULL != ret_page_indexp);
710 + fatal_assert(NULL != ret_page_indexp);
711
712 uv_rwlock_rdlock(&pg_cache->metrics_index.lock);
713 PValue = JudyHSGet(pg_cache->metrics_index.JudyHS_array, id, sizeof(uuid_t));
@@ -1048,7 +1048,7 @@ struct pg_cache_page_index *create_page_index(uuid_t *id)
1048 page_index = mallocz(sizeof(*page_index));
1049 page_index->JudyL_array = (Pvoid_t) NULL;
1050 uuid_copy(page_index->id, *id);
1051 - assert(0 == uv_rwlock_init(&page_index->lock));
1051 + fatal_assert(0 == uv_rwlock_init(&page_index->lock));
1052 page_index->oldest_time = INVALID_TIME;
1053 page_index->latest_time = INVALID_TIME;
1054 page_index->prev = NULL;
@@ -1064,7 +1064,7 @@ static void init_metrics_index(struct rrdengine_instance *ctx)
1064
1065 pg_cache->metrics_index.JudyHS_array = (Pvoid_t) NULL;
1066 pg_cache->metrics_index.last_page_index = NULL;
1067 - assert(0 == uv_rwlock_init(&pg_cache->metrics_index.lock));
1067 + fatal_assert(0 == uv_rwlock_init(&pg_cache->metrics_index.lock));
1068 }
1069
1070 static void init_replaceQ(struct rrdengine_instance *ctx)
@@ -1073,7 +1073,7 @@ static void init_replaceQ(struct rrdengine_instance *ctx)
1073
1074 pg_cache->replaceQ.head = NULL;
1075 pg_cache->replaceQ.tail = NULL;
1076 - assert(0 == uv_rwlock_init(&pg_cache->replaceQ.lock));
1076 + fatal_assert(0 == uv_rwlock_init(&pg_cache->replaceQ.lock));
1077 }
1078
1079 static void init_committed_page_index(struct rrdengine_instance *ctx)
@@ -1081,7 +1081,7 @@ static void init_committed_page_index(struct rrdengine_instance *ctx)
1081 struct page_cache *pg_cache = &ctx->pg_cache;
1082
1083 pg_cache->committed_page_index.JudyL_array = (Pvoid_t) NULL;
1084 - assert(0 == uv_rwlock_init(&pg_cache->committed_page_index.lock));
1084 + fatal_assert(0 == uv_rwlock_init(&pg_cache->committed_page_index.lock));
1085 pg_cache->committed_page_index.latest_corr_id = 0;
1086 pg_cache->committed_page_index.nr_committed_pages = 0;
1087 }
@@ -1092,7 +1092,7 @@ void init_page_cache(struct rrdengine_instance *ctx)
1092
1093 pg_cache->page_descriptors = 0;
1094 pg_cache->populated_pages = 0;
1095 - assert(0 == uv_rwlock_init(&pg_cache->pg_cache_rwlock));
1095 + fatal_assert(0 == uv_rwlock_init(&pg_cache->pg_cache_rwlock));
1096
1097 init_metrics_index(ctx);
1098 init_replaceQ(ctx);
@@ -1111,7 +1111,7 @@ void free_page_cache(struct rrdengine_instance *ctx)
1111
1112 /* Free committed page index */
1113 ret_Judy = JudyLFreeArray(&pg_cache->committed_page_index.JudyL_array, PJE0);
1114 - assert(NULL == pg_cache->committed_page_index.JudyL_array);
1114 + fatal_assert(NULL == pg_cache->committed_page_index.JudyL_array);
1115 bytes_freed += ret_Judy;
1116
1117 for (page_index = pg_cache->metrics_index.last_page_index ;
@@ -1146,14 +1146,14 @@ void free_page_cache(struct rrdengine_instance *ctx)
1146
1147 /* Free page index */
1148 ret_Judy = JudyLFreeArray(&page_index->JudyL_array, PJE0);
1149 - assert(NULL == page_index->JudyL_array);
1149 + fatal_assert(NULL == page_index->JudyL_array);
1150 bytes_freed += ret_Judy;
1151 freez(page_index);
1152 bytes_freed += sizeof(*page_index);
1153 }
1154 /* Free metrics index */
1155 ret_Judy = JudyHSFreeArray(&pg_cache->metrics_index.JudyHS_array, PJE0);
1156 - assert(NULL == pg_cache->metrics_index.JudyHS_array);
1156 + fatal_assert(NULL == pg_cache->metrics_index.JudyHS_array);
1157 bytes_freed += ret_Judy;
1158
1159 info("Freed %lu bytes of memory from page cache.", bytes_freed);
database/engine/pagecache.h
+1 -1
@@ -219,7 +219,7 @@ static inline void
219 /* The caller must hold a reference to the page and must have already set the new data */
220 static inline void pg_cache_atomic_set_pg_info(struct rrdeng_page_descr *descr, usec_t end_time, uint32_t page_length)
221 {
222 - assert(!(end_time & 1));
222 + fatal_assert(!(end_time & 1));
223 __sync_synchronize();
224 descr->end_time |= 1; /* mark start of uncertainty period by adding 1 microsecond */
225 __sync_synchronize();
database/engine/rrdengine.c
+18 -18
@@ -191,7 +191,7 @@ static void do_read_extent(struct rrdengine_worker_config* wc,
191 real_io_size = ALIGN_BYTES_CEILING(size_bytes);
192 xt_io_descr->iov = uv_buf_init((void *)xt_io_descr->buf, real_io_size);
193 ret = uv_fs_read(wc->loop, &xt_io_descr->req, datafile->file, &xt_io_descr->iov, 1, pos, read_extent_cb);
194 - assert (-1 != ret);
194 + fatal_assert(-1 != ret);
195 ctx->stats.io_read_bytes += real_io_size;
196 ++ctx->stats.io_read_requests;
197 ctx->stats.io_read_extent_bytes += real_io_size;
@@ -244,7 +244,7 @@ static void do_commit_transaction(struct rrdengine_worker_config* wc, uint8_t ty
244 commit_data_extent(wc, (struct extent_io_descriptor *)data);
245 break;
246 default:
247 - assert(type == STORE_DATA);
247 + fatal_assert(type == STORE_DATA);
248 break;
249 }
250 }
@@ -284,7 +284,7 @@ static void invalidate_oldest_committed(void *arg)
284
285 PValue = JudyLNext(pg_cache->committed_page_index.JudyL_array, &Index, PJE0),
286 descr = unlikely(NULL == PValue) ? NULL : *PValue) {
287 - assert(0 != descr->page_length);
287 + fatal_assert(0 != descr->page_length);
288
289 rrdeng_page_descr_mutex_lock(ctx, descr);
290 pg_cache_descr = descr->pg_cache_descr;
@@ -292,7 +292,7 @@ static void invalidate_oldest_committed(void *arg)
292 rrdeng_page_descr_mutex_unlock(ctx, descr);
293
294 ret = JudyLDel(&pg_cache->committed_page_index.JudyL_array, Index, PJE0);
295 - assert(1 == ret);
295 + fatal_assert(1 == ret);
296 break;
297 }
298 rrdeng_page_descr_mutex_unlock(ctx, descr);
@@ -316,7 +316,7 @@ static void invalidate_oldest_committed(void *arg)
316 out:
317 wc->cleanup_thread_invalidating_dirty_pages = 1;
318 /* wake up event loop */
319 - assert(0 == uv_async_send(&wc->async));
319 + fatal_assert(0 == uv_async_send(&wc->async));
320 }
321
322 void rrdeng_invalidate_oldest_committed(struct rrdengine_worker_config* wc)
@@ -446,7 +446,7 @@ static int do_flush_pages(struct rrdengine_worker_config* wc, int force, struct
446 descr = unlikely(NULL == PValue) ? NULL : *PValue) {
447 uint8_t page_write_pending;
448
449 - assert(0 != descr->page_length);
449 + fatal_assert(0 != descr->page_length);
450 page_write_pending = 0;
451
452 rrdeng_page_descr_mutex_lock(ctx, descr);
@@ -463,7 +463,7 @@ static int do_flush_pages(struct rrdengine_worker_config* wc, int force, struct
463
464 if (page_write_pending) {
465 ret = JudyLDel(&pg_cache->committed_page_index.JudyL_array, Index, PJE0);
466 - assert(1 == ret);
466 + fatal_assert(1 == ret);
467 }
468 }
469 uv_rwlock_wrunlock(&pg_cache->committed_page_index.lock);
@@ -483,7 +483,7 @@ static int do_flush_pages(struct rrdengine_worker_config* wc, int force, struct
483 size_bytes = payload_offset + uncompressed_payload_length + sizeof(*trailer);
484 break;
485 default: /* Compress */
486 - assert(uncompressed_payload_length < LZ4_MAX_INPUT_SIZE);
486 + fatal_assert(uncompressed_payload_length < LZ4_MAX_INPUT_SIZE);
487 max_compressed_size = LZ4_compressBound(uncompressed_payload_length);
488 compressed_buf = mallocz(max_compressed_size);
489 size_bytes = payload_offset + MAX(uncompressed_payload_length, (unsigned)max_compressed_size) + sizeof(*trailer);
@@ -563,7 +563,7 @@ static int do_flush_pages(struct rrdengine_worker_config* wc, int force, struct
563 real_io_size = ALIGN_BYTES_CEILING(size_bytes);
564 xt_io_descr->iov = uv_buf_init((void *)xt_io_descr->buf, real_io_size);
565 ret = uv_fs_write(wc->loop, &xt_io_descr->req, datafile->file, &xt_io_descr->iov, 1, datafile->pos, flush_pages_cb);
566 - assert (-1 != ret);
566 + fatal_assert(-1 != ret);
567 ctx->stats.io_write_bytes += real_io_size;
568 ++ctx->stats.io_write_requests;
569 ctx->stats.io_write_extent_bytes += real_io_size;
@@ -657,7 +657,7 @@ static void delete_old_data(void *arg)
657 }
658 wc->cleanup_thread_deleting_files = 1;
659 /* wake up event loop */
660 - assert(0 == uv_async_send(&wc->async));
660 + fatal_assert(0 == uv_async_send(&wc->async));
661 }
662
663 void rrdeng_test_quota(struct rrdengine_worker_config* wc)
@@ -751,8 +751,8 @@ void rrdeng_init_cmd_queue(struct rrdengine_worker_config* wc)
751 {
752 wc->cmd_queue.head = wc->cmd_queue.tail = 0;
753 wc->queue_size = 0;
754 - assert(0 == uv_cond_init(&wc->cmd_cond));
755 - assert(0 == uv_mutex_init(&wc->cmd_mutex));
754 + fatal_assert(0 == uv_cond_init(&wc->cmd_cond));
755 + fatal_assert(0 == uv_mutex_init(&wc->cmd_mutex));
756 }
757
758 void rrdeng_enq_cmd(struct rrdengine_worker_config* wc, struct rrdeng_cmd *cmd)
@@ -764,7 +764,7 @@ void rrdeng_enq_cmd(struct rrdengine_worker_config* wc, struct rrdeng_cmd *cmd)
764 while ((queue_size = wc->queue_size) == RRDENG_CMD_Q_MAX_SIZE) {
765 uv_cond_wait(&wc->cmd_cond, &wc->cmd_mutex);
766 }
767 - assert(queue_size < RRDENG_CMD_Q_MAX_SIZE);
767 + fatal_assert(queue_size < RRDENG_CMD_Q_MAX_SIZE);
768 /* enqueue command */
769 wc->cmd_queue.cmd_array[wc->cmd_queue.tail] = *cmd;
770 wc->cmd_queue.tail = wc->cmd_queue.tail != RRDENG_CMD_Q_MAX_SIZE - 1 ?
@@ -773,7 +773,7 @@ void rrdeng_enq_cmd(struct rrdengine_worker_config* wc, struct rrdeng_cmd *cmd)
773 uv_mutex_unlock(&wc->cmd_mutex);
774
775 /* wake up event loop */
776 - assert(0 == uv_async_send(&wc->async));
776 + fatal_assert(0 == uv_async_send(&wc->async));
777 }
778
779 struct rrdeng_cmd rrdeng_deq_cmd(struct rrdengine_worker_config* wc)
@@ -914,7 +914,7 @@ void rrdeng_worker(void* arg)
914 /* wake up initialization thread */
915 complete(&ctx->rrdengine_completion);
916
917 - assert(0 == uv_timer_start(&timer_req, timer_cb, TIMER_PERIOD_MS, TIMER_PERIOD_MS));
917 + fatal_assert(0 == uv_timer_start(&timer_req, timer_cb, TIMER_PERIOD_MS, TIMER_PERIOD_MS));
918 shutdown = 0;
919 while (likely(shutdown == 0 || rrdeng_threads_alive(wc))) {
920 uv_run(loop, UV_RUN_DEFAULT);
@@ -944,7 +944,7 @@ void rrdeng_worker(void* arg)
944 case RRDENG_QUIESCE:
945 ctx->drop_metrics_under_page_cache_pressure = 0;
946 ctx->quiesce = SET_QUIESCE;
947 - assert(0 == uv_timer_stop(&timer_req));
947 + fatal_assert(0 == uv_timer_stop(&timer_req));
948 uv_close((uv_handle_t *)&timer_req, NULL);
949 while (do_flush_pages(wc, 1, NULL)) {
950 ; /* Force flushing of all committed pages. */
@@ -1003,7 +1003,7 @@ void rrdeng_worker(void* arg)
1003 /* TODO: don't let the API block by waiting to enqueue commands */
1004 uv_cond_destroy(&wc->cmd_cond);
1005 /* uv_mutex_destroy(&wc->cmd_mutex); */
1006 - assert(0 == uv_loop_close(loop));
1006 + fatal_assert(0 == uv_loop_close(loop));
1007 freez(loop);
1008
1009 return;
@@ -1011,7 +1011,7 @@ void rrdeng_worker(void* arg)
1011 error_after_timer_init:
1012 uv_close((uv_handle_t *)&wc->async, NULL);
1013 error_after_async_init:
1014 - assert(0 == uv_loop_close(loop));
1014 + fatal_assert(0 == uv_loop_close(loop));
1015 error_after_loop_init:
1016 freez(loop);
1017
database/engine/rrdengineapi.c
+15 -15
@@ -22,7 +22,7 @@ void rrdeng_generate_legacy_uuid(const char *dim_id, char *chart_id, uuid_t *ret
22 EVP_DigestUpdate(evpctx, chart_id, strlen(chart_id));
23 EVP_DigestFinal_ex(evpctx, hash_value, &hash_len);
24 EVP_MD_CTX_destroy(evpctx);
25 - assert(hash_len > sizeof(uuid_t));
25 + fatal_assert(hash_len > sizeof(uuid_t));
26 memcpy(ret_uuid, hash_value, sizeof(uuid_t));
27 }
28
@@ -39,7 +39,7 @@ void rrdeng_convert_legacy_uuid_to_multihost(char machine_guid[GUID_LEN + 1], uu
39 EVP_DigestUpdate(evpctx, *legacy_uuid, sizeof(uuid_t));
40 EVP_DigestFinal_ex(evpctx, hash_value, &hash_len);
41 EVP_MD_CTX_destroy(evpctx);
42 - assert(hash_len > sizeof(uuid_t));
42 + fatal_assert(hash_len > sizeof(uuid_t));
43 memcpy(ret_uuid, hash_value, sizeof(uuid_t));
44 }
45
@@ -77,7 +77,7 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid)
77 error("FAILED to generate GUID for %s", rd->id);
78 freez(rd->state->metric_uuid);
79 rd->state->metric_uuid = NULL;
80 - assert(0);
80 + fatal_assert(0);
81 }
82
83 uv_rwlock_rdlock(&pg_cache->metrics_index.lock);
@@ -89,7 +89,7 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid)
89 if (NULL == PValue) {
90 uv_rwlock_wrlock(&pg_cache->metrics_index.lock);
91 PValue = JudyHSIns(&pg_cache->metrics_index.JudyHS_array, rd->state->metric_uuid, sizeof(uuid_t), PJE0);
92 - assert(NULL == *PValue); /* TODO: figure out concurrency model */
92 + fatal_assert(NULL == *PValue); /* TODO: figure out concurrency model */
93 *PValue = page_index = create_page_index(rd->state->metric_uuid);
94 page_index->prev = pg_cache->metrics_index.last_page_index;
95 pg_cache->metrics_index.last_page_index = page_index;
@@ -109,7 +109,7 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid)
109 error("FAILED to generate GUID for %s", rd->id);
110 freez(rd->state->metric_uuid);
111 rd->state->metric_uuid = NULL;
112 - assert(0);
112 + fatal_assert(0);
113 }
114 }
115 rd->state->rrdeng_uuid = &page_index->id;
@@ -192,7 +192,7 @@ void rrdeng_store_metric_flush_current_page(RRDDIM *rd)
192 rrdeng_page_descr_mutex_lock(ctx, descr);
193 ret = pg_cache_try_get_unsafe(descr, 0);
194 rrdeng_page_descr_mutex_unlock(ctx, descr);
195 - assert (1 == ret);
195 + fatal_assert(1 == ret);
196
197 rrdeng_commit_page(ctx, descr, handle->page_correlation_id);
198 handle->prev_descr = descr;
@@ -247,7 +247,7 @@ void rrdeng_store_metric_next(RRDDIM *rd, usec_t point_in_time, storage_number n
247 rrdeng_store_metric_flush_current_page(rd);
248
249 page = rrdeng_create_page(ctx, &rd->state->page_index->id, &descr);
250 - assert(page);
250 + fatal_assert(page);
251
252 handle->descr = descr;
253
@@ -415,7 +415,7 @@ unsigned rrdeng_variable_step_boundaries(RRDSET *st, time_t start_time, time_t e
415 continue;
416 }
417 page_entries = curr->page_length / sizeof(storage_number);
418 - assert(0 != page_entries);
418 + fatal_assert(0 != page_entries);
419 if (likely(1 != page_entries)) {
420 dt = (curr->end_time - curr->start_time) / (page_entries - 1);
421 *pginfo_to_dt(curr) = ROUND_USEC_TO_SEC(dt);
@@ -451,7 +451,7 @@ unsigned rrdeng_variable_step_boundaries(RRDSET *st, time_t start_time, time_t e
451 if (1 == page_points)
452 first_valid_time_in_page = current_position_time;
453 if (unlikely(!is_first_region_initialized)) {
454 - assert(1 == regions);
454 + fatal_assert(1 == regions);
455 /* this is the first region */
456 region_info_array[0].start_time = current_position_time;
457 is_first_region_initialized = 1;
@@ -464,7 +464,7 @@ unsigned rrdeng_variable_step_boundaries(RRDSET *st, time_t start_time, time_t e
464 }
465
466 if (unlikely(0 == *pginfo_to_dt(curr))) { /* unknown data collection interval */
467 - assert(1 == page_points);
467 + fatal_assert(1 == page_points);
468
469 if (likely(NULL != prev)) { /* get interval from previous page */
470 *pginfo_to_dt(curr) = *pginfo_to_dt(prev);
@@ -620,7 +620,7 @@ storage_number rrdeng_load_metric_next(struct rrddim_query_handle *rrdimm_handle
620 }
621 handle->position = position;
622 handle->now = current_position_time / USEC_PER_SEC;
623 -/* assert(handle->now >= rrdimm_handle->start_time && handle->now <= rrdimm_handle->end_time);
623 +/* fatal_assert(handle->now >= rrdimm_handle->start_time && handle->now <= rrdimm_handle->end_time);
624 The above assertion is an approximation and needs to take update_every into account */
625 if (unlikely(handle->now >= rrdimm_handle->end_time)) {
626 /* next calls will not load any more metrics */
@@ -716,7 +716,7 @@ void rrdeng_commit_page(struct rrdengine_instance *ctx, struct rrdeng_page_descr
716 debug(D_RRDENGINE, "%s: page descriptor is NULL, page has already been force-committed.", __func__);
717 return;
718 }
719 - assert(descr->page_length);
719 + fatal_assert(descr->page_length);
720
721 uv_rwlock_wrlock(&pg_cache->committed_page_index.lock);
722 PValue = JudyLIns(&pg_cache->committed_page_index.JudyL_array, page_correlation_id, PJE0);
@@ -835,7 +835,7 @@ void rrdeng_get_37_statistics(struct rrdengine_instance *ctx, unsigned long long
835 array[34] = (uint64_t)global_pg_cache_over_half_dirty_events;
836 array[35] = (uint64_t)ctx->stats.flushing_pressure_page_deletions;
837 array[36] = (uint64_t)global_flushing_pressure_page_deletions;
838 - assert(RRDENG_NR_STATS == 37);
838 + fatal_assert(RRDENG_NR_STATS == 37);
839 }
840
841 /* Releases reference to page */
@@ -903,7 +903,7 @@ int rrdeng_init(RRDHOST *host, struct rrdengine_instance **ctxp, char *dbfiles_p
903 }
904
905 init_completion(&ctx->rrdengine_completion);
906 - assert(0 == uv_thread_create(&ctx->worker_config.thread, rrdeng_worker, &ctx->worker_config));
906 + fatal_assert(0 == uv_thread_create(&ctx->worker_config.thread, rrdeng_worker, &ctx->worker_config));
907 /* wait for worker thread to initialize */
908 wait_for_completion(&ctx->rrdengine_completion);
909 destroy_completion(&ctx->rrdengine_completion);
@@ -945,7 +945,7 @@ int rrdeng_exit(struct rrdengine_instance *ctx)
945 cmd.opcode = RRDENG_SHUTDOWN;
946 rrdeng_enq_cmd(&ctx->worker_config, &cmd);
947
948 - assert(0 == uv_thread_join(&ctx->worker_config.thread));
948 + fatal_assert(0 == uv_thread_join(&ctx->worker_config.thread));
949
950 finalize_rrd_files(ctx);
951 metalog_exit(ctx->metalog_ctx);
database/engine/rrdenginelib.c
+3 -3
@@ -60,7 +60,7 @@ int check_file_properties(uv_file file, uint64_t *file_size, size_t min_size)
60 if (ret < 0) {
61 fatal("uv_fs_fstat: %s\n", uv_strerror(ret));
62 }
63 - assert(req.result == 0);
63 + fatal_assert(req.result == 0);
64 s = req.ptr;
65 if (!(s->st_mode & S_IFREG)) {
66 error("Not a regular file.\n");
@@ -92,7 +92,7 @@ int open_file_for_io(char *path, int flags, uv_file *file, int direct)
92 uv_fs_t req;
93 int fd, current_flags;
94
95 - assert(0 == direct || 1 == direct);
95 + fatal_assert(0 == direct || 1 == direct);
96 for ( ; direct >= 0 ; --direct) {
97 #ifdef __APPLE__
98 /* Apple OS does not support O_DIRECT */
@@ -111,7 +111,7 @@ int open_file_for_io(char *path, int flags, uv_file *file, int direct)
111 --direct; /* break the loop */
112 }
113 } else {
114 - assert(req.result >= 0);
114 + fatal_assert(req.result >= 0);
115 *file = req.result;
116 #ifdef __APPLE__
117 info("Disabling OS X caching for file \"%s\".", path);
database/engine/rrdenginelib.h
+3 -3
@@ -59,8 +59,8 @@ struct completion {
59 static inline void init_completion(struct completion *p)
60 {
61 p->completed = 0;
62 - assert(0 == uv_cond_init(&p->cond));
63 - assert(0 == uv_mutex_init(&p->mutex));
62 + fatal_assert(0 == uv_cond_init(&p->cond));
63 + fatal_assert(0 == uv_mutex_init(&p->mutex));
64 }
65
66 static inline void destroy_completion(struct completion *p)
@@ -75,7 +75,7 @@ static inline void wait_for_completion(struct completion *p)
75 while (0 == p->completed) {
76 uv_cond_wait(&p->cond, &p->mutex);
77 }
78 - assert(1 == p->completed);
78 + fatal_assert(1 == p->completed);
79 uv_mutex_unlock(&p->mutex);
80 }
81
database/engine/rrdenglocking.c
+13 -13
@@ -12,8 +12,8 @@ struct page_cache_descr *rrdeng_create_pg_cache_descr(struct rrdengine_instance
12 pg_cache_descr->prev = pg_cache_descr->next = NULL;
13 pg_cache_descr->refcnt = 0;
14 pg_cache_descr->waiters = 0;
15 - assert(0 == uv_cond_init(&pg_cache_descr->cond));
16 - assert(0 == uv_mutex_init(&pg_cache_descr->mutex));
15 + fatal_assert(0 == uv_cond_init(&pg_cache_descr->cond));
16 + fatal_assert(0 == uv_mutex_init(&pg_cache_descr->mutex));
17
18 return pg_cache_descr;
19 }
@@ -39,7 +39,7 @@ void rrdeng_page_descr_mutex_lock(struct rrdengine_instance *ctx, struct rrdeng_
39 old_users = old_state >> PG_CACHE_DESCR_SHIFT;
40
41 if (unlikely(we_locked)) {
42 - assert(old_state & PG_CACHE_DESCR_LOCKED);
42 + fatal_assert(old_state & PG_CACHE_DESCR_LOCKED);
43 new_state = (1 << PG_CACHE_DESCR_SHIFT) | PG_CACHE_DESCR_ALLOCATED;
44 ret_state = ulong_compare_and_swap(&descr->pg_cache_descr_state, old_state, new_state);
45 if (old_state == ret_state) {
@@ -49,7 +49,7 @@ void rrdeng_page_descr_mutex_lock(struct rrdengine_instance *ctx, struct rrdeng_
49 continue; /* spin */
50 }
51 if (old_state & PG_CACHE_DESCR_LOCKED) {
52 - assert(0 == old_users);
52 + fatal_assert(0 == old_users);
53 continue; /* spin */
54 }
55 if (0 == old_state) {
@@ -106,7 +106,7 @@ void rrdeng_page_descr_mutex_unlock(struct rrdengine_instance *ctx, struct rrden
106 old_users = old_state >> PG_CACHE_DESCR_SHIFT;
107
108 if (unlikely(we_locked)) {
109 - assert(0 == old_users);
109 + fatal_assert(0 == old_users);
110
111 ret_state = ulong_compare_and_swap(&descr->pg_cache_descr_state, old_state, 0);
112 if (old_state == ret_state) {
@@ -117,15 +117,15 @@ void rrdeng_page_descr_mutex_unlock(struct rrdengine_instance *ctx, struct rrden
117 continue; /* spin */
118 }
119 if (old_state & PG_CACHE_DESCR_LOCKED) {
120 - assert(0 == old_users);
120 + fatal_assert(0 == old_users);
121 continue; /* spin */
122 }
123 - assert(old_state & PG_CACHE_DESCR_ALLOCATED);
123 + fatal_assert(old_state & PG_CACHE_DESCR_ALLOCATED);
124 pg_cache_descr = descr->pg_cache_descr;
125 /* caller is the only page cache descriptor user and there are no pending references on the page */
126 if ((old_state & PG_CACHE_DESCR_DESTROY) && (1 == old_users) &&
127 !pg_cache_descr->flags && !pg_cache_descr->refcnt) {
128 - assert(!pg_cache_descr->waiters);
128 + fatal_assert(!pg_cache_descr->waiters);
129
130 new_state = PG_CACHE_DESCR_LOCKED;
131 ret_state = ulong_compare_and_swap(&descr->pg_cache_descr_state, old_state, new_state);
@@ -138,7 +138,7 @@ void rrdeng_page_descr_mutex_unlock(struct rrdengine_instance *ctx, struct rrden
138 }
139 continue; /* spin */
140 }
141 - assert(old_users > 0);
141 + fatal_assert(old_users > 0);
142 new_state = (old_users - 1) << PG_CACHE_DESCR_SHIFT;
143 new_state |= old_state & PG_CACHE_DESCR_FLAGS_MASK;
144
@@ -170,13 +170,13 @@ void rrdeng_try_deallocate_pg_cache_descr(struct rrdengine_instance *ctx, struct
170 old_users = old_state >> PG_CACHE_DESCR_SHIFT;
171
172 if (unlikely(just_locked)) {
173 - assert(0 == old_users);
173 + fatal_assert(0 == old_users);
174
175 must_unlock = 1;
176 just_locked = 0;
177 /* Try deallocate if there are no pending references on the page */
178 if (!pg_cache_descr->flags && !pg_cache_descr->refcnt) {
179 - assert(!pg_cache_descr->waiters);
179 + fatal_assert(!pg_cache_descr->waiters);
180
181 descr->pg_cache_descr = NULL;
182 can_free = 1;
@@ -186,7 +186,7 @@ void rrdeng_try_deallocate_pg_cache_descr(struct rrdengine_instance *ctx, struct
186 continue; /* spin */
187 }
188 if (unlikely(must_unlock)) {
189 - assert(0 == old_users);
189 + fatal_assert(0 == old_users);
190
191 if (can_free) {
192 /* success */
@@ -209,7 +209,7 @@ void rrdeng_try_deallocate_pg_cache_descr(struct rrdengine_instance *ctx, struct
209 return;
210 }
211 if (old_state & PG_CACHE_DESCR_LOCKED) {
212 - assert(0 == old_users);
212 + fatal_assert(0 == old_users);
213 continue; /* spin */
214 }
215 /* caller is the only page cache descriptor user */
database/rrdset.c
+1 -1
@@ -927,7 +927,7 @@ RRDSET *rrdset_create_custom(
927 error("FAILED to generate GUID for %s", st->id);
928 freez(st->chart_uuid);
929 st->chart_uuid = NULL;
930 - assert(0);
930 + fatal_assert(0);
931 }
932 st->compaction_id = 0;
933 }
libnetdata/log/log.h
+1
@@ -89,6 +89,7 @@ static inline void debug_dummy(void) {}
89 #define infoerr(args...) error_int("INFO", __FILE__, __FUNCTION__, __LINE__, ##args)
90 #define error(args...) error_int("ERROR", __FILE__, __FUNCTION__, __LINE__, ##args)
91 #define fatal(args...) fatal_int(__FILE__, __FUNCTION__, __LINE__, ##args)
92 +#define fatal_assert(expr) ((expr) ? (void)(0) : fatal_int(__FILE__, __FUNCTION__, __LINE__, "Assertion `%s' failed", #expr))
93
94 extern void send_statistics(const char *action, const char *action_result, const char *action_data);
95 extern void debug_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... ) PRINTFLIKE(4, 5);
spawn/spawn.c
+10 -10
@@ -14,8 +14,8 @@ static struct spawn_cmd_info *create_spawn_cmd(char *command_to_run)
14 struct spawn_cmd_info *cmdinfo;
15
16 cmdinfo = mallocz(sizeof(*cmdinfo));
17 - assert(0 == uv_cond_init(&cmdinfo->cond));
18 - assert(0 == uv_mutex_init(&cmdinfo->mutex));
17 + fatal_assert(0 == uv_cond_init(&cmdinfo->cond));
18 + fatal_assert(0 == uv_mutex_init(&cmdinfo->mutex));
19 cmdinfo->serial = 0; /* invalid */
20 cmdinfo->command_to_run = strdupz(command_to_run);
21 cmdinfo->exit_status = -1; /* invalid */
@@ -51,8 +51,8 @@ static void init_spawn_cmd_queue(void)
51 spawn_cmd_queue.cmd_tree.compar = spawn_cmd_compare;
52 spawn_cmd_queue.size = 0;
53 spawn_cmd_queue.latest_serial = 0;
54 - assert(0 == uv_cond_init(&spawn_cmd_queue.cond));
55 - assert(0 == uv_mutex_init(&spawn_cmd_queue.mutex));
54 + fatal_assert(0 == uv_cond_init(&spawn_cmd_queue.cond));
55 + fatal_assert(0 == uv_mutex_init(&spawn_cmd_queue.mutex));
56 }
57
58 /*
@@ -72,7 +72,7 @@ uint64_t spawn_enq_cmd(char *command_to_run)
72 while ((queue_size = spawn_cmd_queue.size) == SPAWN_MAX_OUTSTANDING) {
73 uv_cond_wait(&spawn_cmd_queue.cond, &spawn_cmd_queue.mutex);
74 }
75 - assert(queue_size < SPAWN_MAX_OUTSTANDING);
75 + fatal_assert(queue_size < SPAWN_MAX_OUTSTANDING);
76 spawn_cmd_queue.size = queue_size + 1;
77
78 serial = ++spawn_cmd_queue.latest_serial; /* 0 is invalid */
@@ -80,11 +80,11 @@ uint64_t spawn_enq_cmd(char *command_to_run)
80
81 /* enqueue command */
82 avl_ret = avl_insert(&spawn_cmd_queue.cmd_tree, (avl *)cmdinfo);
83 - assert(avl_ret == (avl *)cmdinfo);
83 + fatal_assert(avl_ret == (avl *)cmdinfo);
84 uv_mutex_unlock(&spawn_cmd_queue.mutex);
85
86 /* wake up event loop */
87 - assert(0 == uv_async_send(&spawn_async));
87 + fatal_assert(0 == uv_async_send(&spawn_async));
88 return serial;
89 }
90
@@ -102,7 +102,7 @@ void spawn_wait_cmd(uint64_t serial, int *exit_status, time_t *exec_run_timestam
102 avl_ret = avl_search(&spawn_cmd_queue.cmd_tree, (avl *)&tmp);
103 uv_mutex_unlock(&spawn_cmd_queue.mutex);
104
105 - assert(avl_ret); /* Could be NULL if more than 1 threads wait for the command */
105 + fatal_assert(avl_ret); /* Could be NULL if more than 1 threads wait for the command */
106 cmdinfo = (struct spawn_cmd_info *)avl_ret;
107
108 uv_mutex_lock(&cmdinfo->mutex);
@@ -126,10 +126,10 @@ void spawn_deq_cmd(struct spawn_cmd_info *cmdinfo)
126
127 uv_mutex_lock(&spawn_cmd_queue.mutex);
128 queue_size = spawn_cmd_queue.size;
129 - assert(queue_size);
129 + fatal_assert(queue_size);
130 /* dequeue command */
131 avl_ret = avl_remove(&spawn_cmd_queue.cmd_tree, (avl *)cmdinfo);
132 - assert(avl_ret);
132 + fatal_assert(avl_ret);
133
134 spawn_cmd_queue.size = queue_size - 1;
135
spawn/spawn_client.c
+7 -7
@@ -42,7 +42,7 @@ static void client_parse_spawn_protocol(unsigned source_len, char *source)
42
43 header = (struct spawn_prot_header *)prot_buffer;
44 cmdinfo = (struct spawn_cmd_info *)header->handle;
45 - assert(NULL != cmdinfo);
45 + fatal_assert(NULL != cmdinfo);
46
47 switch(header->opcode) {
48 case SPAWN_PROT_SPAWN_RESULT:
@@ -90,7 +90,7 @@ static void client_parse_spawn_protocol(unsigned source_len, char *source)
90 prot_buffer_len = 0;
91 break;
92 default:
93 - assert(0);
93 + fatal_assert(0);
94 break;
95 }
96
@@ -158,7 +158,7 @@ static void spawn_process_cmd(struct spawn_cmd_info *cmdinfo)
158 info("CLIENT %s SPAWN_PROT_EXEC_CMD %u", __func__, (unsigned)cmdinfo->serial);
159 #endif
160 ret = uv_write(&write_ctx->write_req, (uv_stream_t *)&spawn_channel, writebuf, 3, after_pipe_write);
161 - assert(ret == 0);
161 + fatal_assert(ret == 0);
162 }
163
164 void spawn_client(void *arg)
@@ -189,7 +189,7 @@ void spawn_client(void *arg)
189 spawn_thread_error = ret;
190 goto error_after_pipe_init;
191 }
192 - assert(spawn_channel.ipc);
192 + fatal_assert(spawn_channel.ipc);
193
194 ret = create_spawn_server(loop, &spawn_channel, &process);
195 if (ret) {
@@ -205,7 +205,7 @@ void spawn_client(void *arg)
205
206 prot_buffer_len = 0;
207 ret = uv_read_start((uv_stream_t *)&spawn_channel, on_read_alloc, on_pipe_read);
208 - assert(ret == 0);
208 + fatal_assert(ret == 0);
209
210 while (spawn_thread_shutdown == 0) {
211 struct spawn_cmd_info *cmdinfo;
@@ -222,7 +222,7 @@ void spawn_client(void *arg)
222 uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */
223
224 info("Shutting down spawn client loop complete.");
225 - assert(0 == uv_loop_close(loop));
225 + fatal_assert(0 == uv_loop_close(loop));
226
227 return;
228
@@ -232,7 +232,7 @@ error_after_pipe_init:
232 uv_close((uv_handle_t *)&spawn_async, NULL);
233 error_after_async_init:
234 uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */
235 - assert(0 == uv_loop_close(loop));
235 + fatal_assert(0 == uv_loop_close(loop));
236 error_after_loop_init:
237 freez(loop);
238
spawn/spawn_server.c
+12 -12
@@ -96,7 +96,7 @@ static void child_waited_async_cb(uv_async_t *async_handle)
96 fprintf(stderr, "SERVER %s SPAWN_PROT_CMD_EXIT_STATUS\n", __func__);
97 #endif
98 ret = uv_write(&write_ctx->write_req, (uv_stream_t *) &server_pipe, writebuf, 2, after_pipe_write);
99 - assert(ret == 0);
99 + fatal_assert(ret == 0);
100
101 freez(exec_info);
102 }
@@ -131,7 +131,7 @@ static void wait_children(void *arg)
131 #ifdef SPAWN_DEBUG
132 fprintf(stderr, "SPAWN: Successfully waited for pid:%d.\n", (int) i.si_pid);
133 #endif
134 - assert(CLD_EXITED == i.si_code);
134 + fatal_assert(CLD_EXITED == i.si_code);
135 tmp.pid = (pid_t)i.si_pid;
136 while (NULL == (ret_avl = avl_remove_lock(&spawn_outstanding_exec_tree, (avl *)&tmp))) {
137 fprintf(stderr,
@@ -144,7 +144,7 @@ static void wait_children(void *arg)
144 enqueue_child_waited_list(exec_info);
145
146 /* wake up event loop */
147 - assert(0 == uv_async_send(&child_waited_async));
147 + fatal_assert(0 == uv_async_send(&child_waited_async));
148 }
149 }
150 }
@@ -175,7 +175,7 @@ void spawn_protocol_execute_command(void *handle, char *command_to_run, uint16_t
175 exec_info->handle = handle;
176 exec_info->pid = write_ctx->spawn_result.exec_pid;
177 avl_ret = avl_insert_lock(&spawn_outstanding_exec_tree, (avl *)exec_info);
178 - assert(avl_ret == (avl *)exec_info);
178 + fatal_assert(avl_ret == (avl *)exec_info);
179
180 /* wake up the thread that blocks waiting for processes to exit */
181 uv_mutex_lock(&wait_children_mutex);
@@ -192,7 +192,7 @@ void spawn_protocol_execute_command(void *handle, char *command_to_run, uint16_t
192 fprintf(stderr, "SERVER %s SPAWN_PROT_SPAWN_RESULT\n", __func__);
193 #endif
194 ret = uv_write(&write_ctx->write_req, (uv_stream_t *)&server_pipe, writebuf, 2, after_pipe_write);
195 - assert(ret == 0);
195 + fatal_assert(ret == 0);
196 }
197
198 static void server_parse_spawn_protocol(unsigned source_len, char *source)
@@ -210,8 +210,8 @@ static void server_parse_spawn_protocol(unsigned source_len, char *source)
210 return; /* Source buffer ran out */
211
212 header = (struct spawn_prot_header *)prot_buffer;
213 - assert(SPAWN_PROT_EXEC_CMD == header->opcode);
214 - assert(NULL != header->handle);
213 + fatal_assert(SPAWN_PROT_EXEC_CMD == header->opcode);
214 + fatal_assert(NULL != header->handle);
215
216 required_len += sizeof(*payload);
217 if (prot_buffer_len < required_len)
@@ -338,7 +338,7 @@ void spawn_server(void)
338 fprintf(stderr, "uv_pipe_init(): %s\n", uv_strerror(error));
339 exit(error);
340 }
341 - assert(server_pipe.ipc);
341 + fatal_assert(server_pipe.ipc);
342
343 error = uv_pipe_open(&server_pipe, 0 /* UV_STDIN_FD */);
344 if (error) {
@@ -348,8 +348,8 @@ void spawn_server(void)
348 avl_init_lock(&spawn_outstanding_exec_tree, spawn_exec_compare);
349
350 spawned_processes = 0;
351 - assert(0 == uv_cond_init(&wait_children_cond));
352 - assert(0 == uv_mutex_init(&wait_children_mutex));
351 + fatal_assert(0 == uv_cond_init(&wait_children_cond));
352 + fatal_assert(0 == uv_mutex_init(&wait_children_mutex));
353 child_waited_list = NULL;
354 error = uv_async_init(loop, &child_waited_async, child_waited_async_cb);
355 if (error) {
@@ -365,13 +365,13 @@ void spawn_server(void)
365
366 prot_buffer_len = 0;
367 error = uv_read_start((uv_stream_t *)&server_pipe, on_read_alloc, on_pipe_read);
368 - assert(error == 0);
368 + fatal_assert(error == 0);
369
370 while (!server_shutdown) {
371 uv_run(loop, UV_RUN_DEFAULT);
372 }
373 fprintf(stderr, "Shutting down spawn server loop complete.\n");
374 - assert(0 == uv_loop_close(loop));
374 + fatal_assert(0 == uv_loop_close(loop));
375
376 exit(0);
377 }