diff --git a/collectors/freeipmi.plugin/freeipmi_plugin.c b/collectors/freeipmi.plugin/freeipmi_plugin.c index 74274ea215..bd3c533cad 100644 --- a/collectors/freeipmi.plugin/freeipmi_plugin.c +++ b/collectors/freeipmi.plugin/freeipmi_plugin.c @@ -160,7 +160,7 @@ char *sel_config_file = NULL; static void _init_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config) { - assert (ipmi_config); + fatal_assert(ipmi_config); ipmi_config->driver_type = driver_type; ipmi_config->disable_auto_probe = disable_auto_probe; @@ -1580,7 +1580,7 @@ int ipmi_detect_speed_secs(struct ipmi_monitoring_ipmi_config *ipmi_config) { int parse_inband_driver_type (const char *str) { - assert (str); + fatal_assert(str); if (strcasecmp (str, IPMI_PARSE_DEVICE_KCS_STR) == 0) return (IPMI_MONITORING_DRIVER_TYPE_KCS); @@ -1604,7 +1604,7 @@ int parse_inband_driver_type (const char *str) int parse_outofband_driver_type (const char *str) { - assert (str); + fatal_assert(str); if (strcasecmp (str, IPMI_PARSE_DEVICE_LAN_STR) == 0) return (IPMI_MONITORING_PROTOCOL_VERSION_1_5); diff --git a/daemon/commands.c b/daemon/commands.c index 1944b6c370..57d39007e5 100644 --- a/daemon/commands.c +++ b/daemon/commands.c @@ -474,7 +474,7 @@ static void parse_commands(struct command_context *cmd_ctx) cmd_ctx->args = lstrip; cmd_ctx->message = NULL; - assert(0 == uv_queue_work(loop, &cmd_ctx->work, schedule_command, after_schedule_command)); + fatal_assert(0 == uv_queue_work(loop, &cmd_ctx->work, schedule_command, after_schedule_command)); break; } } @@ -533,7 +533,7 @@ static void connection_cb(uv_stream_t *server, int status) int ret; uv_pipe_t *client; struct command_context *cmd_ctx; - assert(status == 0); + fatal_assert(status == 0); /* combined allocation of client pipe and command context */ cmd_ctx = mallocz(sizeof(*cmd_ctx)); @@ -636,7 +636,7 @@ static void command_thread(void *arg) uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */ info("Shutting down command loop complete."); - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); freez(loop); return; @@ -648,7 +648,7 @@ error_after_pipe_init: uv_close((uv_handle_t *)&async, NULL); error_after_async_init: uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */ - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); error_after_loop_init: freez(loop); @@ -673,9 +673,9 @@ void commands_init(void) info("Initializing command server."); for (i = 0 ; i < CMD_TOTAL_COMMANDS ; ++i) { - assert(0 == uv_mutex_init(&command_lock_array[i])); + fatal_assert(0 == uv_mutex_init(&command_lock_array[i])); } - assert(0 == uv_rwlock_init(&exclusive_rwlock)); + fatal_assert(0 == uv_rwlock_init(&exclusive_rwlock)); init_completion(&completion); error = uv_thread_create(&thread, command_thread, NULL); @@ -713,8 +713,8 @@ void commands_exit(void) command_thread_shutdown = 1; info("Shutting down command server."); /* wake up event loop */ - assert(0 == uv_async_send(&async)); - assert(0 == uv_thread_join(&thread)); + fatal_assert(0 == uv_async_send(&async)); + fatal_assert(0 == uv_thread_join(&thread)); for (i = 0 ; i < CMD_TOTAL_COMMANDS ; ++i) { uv_mutex_destroy(&command_lock_array[i]); diff --git a/database/engine/datafile.c b/database/engine/datafile.c index 8ef4ed5990..01f6863d55 100644 --- a/database/engine/datafile.c +++ b/database/engine/datafile.c @@ -30,7 +30,7 @@ void datafile_list_delete(struct rrdengine_instance *ctx, struct rrdengine_dataf struct rrdengine_datafile *next; next = datafile->next; - assert((NULL != next) && (ctx->datafiles.first == datafile) && (ctx->datafiles.last != datafile)); + fatal_assert((NULL != next) && (ctx->datafiles.first == datafile) && (ctx->datafiles.last != datafile)); ctx->datafiles.first = next; } @@ -38,7 +38,7 @@ void datafile_list_delete(struct rrdengine_instance *ctx, struct rrdengine_dataf static void datafile_init(struct rrdengine_datafile *datafile, struct rrdengine_instance *ctx, unsigned tier, unsigned fileno) { - assert(tier == 1); + fatal_assert(tier == 1); datafile->tier = tier; datafile->fileno = fileno; datafile->file = (uv_file)0; @@ -146,7 +146,7 @@ int create_data_file(struct rrdengine_datafile *datafile) ret = uv_fs_write(NULL, &req, file, &iov, 1, 0, NULL); if (ret < 0) { - assert(req.result < 0); + fatal_assert(req.result < 0); error("uv_fs_write: %s", uv_strerror(ret)); ++ctx->stats.io_errors; rrd_stat_atomic_add(&global_io_errors, 1); @@ -184,7 +184,7 @@ static int check_data_file_superblock(uv_file file) uv_fs_req_cleanup(&req); goto error; } - assert(req.result >= 0); + fatal_assert(req.result >= 0); uv_fs_req_cleanup(&req); if (strncmp(superblock->magic_number, RRDENG_DF_MAGIC, RRDENG_MAGIC_SZ) || @@ -271,7 +271,7 @@ static int scan_data_files(struct rrdengine_instance *ctx) ret = uv_fs_scandir(NULL, &req, ctx->dbfiles_path, 0, NULL); if (ret < 0) { - assert(req.result < 0); + fatal_assert(req.result < 0); uv_fs_req_cleanup(&req); error("uv_fs_scandir(%s): %s", ctx->dbfiles_path, uv_strerror(ret)); ++ctx->stats.fs_errors; diff --git a/database/engine/global_uuid_map/global_uuid_map.c b/database/engine/global_uuid_map/global_uuid_map.c index 340a353528..f55ea5d7ad 100644 --- a/database/engine/global_uuid_map/global_uuid_map.c +++ b/database/engine/global_uuid_map/global_uuid_map.c @@ -254,9 +254,9 @@ void init_global_guid_map() init = 1; info("Configuring locking mechanism for global GUID map"); - assert(0 == uv_rwlock_init(&guid_lock)); - assert(0 == uv_rwlock_init(&object_lock)); - assert(0 == uv_rwlock_init(&global_lock)); + fatal_assert(0 == uv_rwlock_init(&guid_lock)); + fatal_assert(0 == uv_rwlock_init(&object_lock)); + fatal_assert(0 == uv_rwlock_init(&global_lock)); // int rc = guid_bulk_load("6fc56a64-05d7-47a7-bc82-7f3235d8cbda","d6b37186-74db-11ea-88b2-0bf5095b1f9e/cgroup_qemu_ubuntu18.04.cpu_per_core/cpu3"); // rc = guid_bulk_load("75c6fa02-97cc-40c1-aacd-a0132190472e","d6b37186-74db-11ea-88b2-0bf5095b1f9e/services.throttle_io_ops_write/system.slice_setvtrgb.service"); diff --git a/database/engine/journalfile.c b/database/engine/journalfile.c index fac680aa0e..97109ec969 100644 --- a/database/engine/journalfile.c +++ b/database/engine/journalfile.c @@ -52,7 +52,7 @@ void wal_flush_transaction_buffer(struct rrdengine_worker_config* wc) io_descr->iov = uv_buf_init((void *)io_descr->buf, size); ret = uv_fs_write(wc->loop, &io_descr->req, journalfile->file, &io_descr->iov, 1, journalfile->pos, flush_transaction_buffer_cb); - assert (-1 != ret); + fatal_assert(-1 != ret); journalfile->pos += RRDENG_BLOCK_SIZE; ctx->disk_space += RRDENG_BLOCK_SIZE; ctx->commit_log.buf = NULL; @@ -66,7 +66,7 @@ void * wal_get_transaction_buffer(struct rrdengine_worker_config* wc, unsigned s int ret; unsigned buf_pos, buf_size; - assert(size); + fatal_assert(size); if (ctx->commit_log.buf) { unsigned remaining; @@ -194,7 +194,7 @@ int create_journal_file(struct rrdengine_journalfile *journalfile, struct rrdeng ret = uv_fs_write(NULL, &req, file, &iov, 1, 0, NULL); if (ret < 0) { - assert(req.result < 0); + fatal_assert(req.result < 0); error("uv_fs_write: %s", uv_strerror(ret)); ++ctx->stats.io_errors; rrd_stat_atomic_add(&global_io_errors, 1); @@ -232,7 +232,7 @@ static int check_journal_file_superblock(uv_file file) uv_fs_req_cleanup(&req); goto error; } - assert(req.result >= 0); + fatal_assert(req.result >= 0); uv_fs_req_cleanup(&req); 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 /* First time we see the UUID */ uv_rwlock_wrlock(&pg_cache->metrics_index.lock); PValue = JudyHSIns(&pg_cache->metrics_index.JudyHS_array, temp_id, sizeof(uuid_t), PJE0); - assert(NULL == *PValue); /* TODO: figure out concurrency model */ + fatal_assert(NULL == *PValue); /* TODO: figure out concurrency model */ *PValue = page_index = create_page_index(temp_id); page_index->prev = pg_cache->metrics_index.last_page_index; pg_cache->metrics_index.last_page_index = page_index; @@ -408,7 +408,7 @@ static uint64_t iterate_transactions(struct rrdengine_instance *ctx, struct rrde fatal("uv_fs_read: %s", uv_strerror(ret)); /*uv_fs_req_cleanup(&req);*/ } - assert(req.result >= 0); + fatal_assert(req.result >= 0); uv_fs_req_cleanup(&req); ctx->stats.io_read_bytes += size_bytes; ++ctx->stats.io_read_requests; diff --git a/database/engine/metadata_log/compaction.c b/database/engine/metadata_log/compaction.c index 9113fdd940..951cebdc04 100644 --- a/database/engine/metadata_log/compaction.c +++ b/database/engine/metadata_log/compaction.c @@ -87,7 +87,7 @@ static void compact_record_by_uuid(struct metalog_instance *ctx, uuid_t *uuid) ret = find_object_by_guid(uuid, NULL, 0); switch (ret) { case GUID_TYPE_CHAR: - assert(0); + fatal_assert(0); break; case GUID_TYPE_CHART: 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) debug(D_METADATALOG, "Ignoring nonexistent metadata record."); break; default: - assert(0); + fatal_assert(0); break; } } @@ -221,7 +221,7 @@ static void compact_old_records(void *arg) break; } } - assert(nextmetalogfile); /* There are always more than 1 metadata log files during compaction */ + fatal_assert(nextmetalogfile); /* There are always more than 1 metadata log files during compaction */ newmetalogfile = compaction_state->new_metadata_logfiles.last; if (newmetalogfile->starting_fileno != 0) { /* Must rename the last compacted file */ @@ -237,7 +237,7 @@ static void compact_old_records(void *arg) wc->cleanup_thread_compacting_files = 1; /* wake up event loop */ - assert(0 == uv_async_send(&wc->async)); + fatal_assert(0 == uv_async_send(&wc->async)); } /* Returns 0 on success. */ @@ -262,7 +262,7 @@ static int init_compaction_state(struct metalog_instance *ctx) return ret; } newmetalogfile = compaction_state->new_metadata_logfiles.first; - assert(newmetalogfile == compaction_state->new_metadata_logfiles.last); + fatal_assert(newmetalogfile == compaction_state->new_metadata_logfiles.last); init_metadata_record_log(&compaction_state->records_log); return 0; @@ -329,7 +329,7 @@ int compaction_failure_recovery(struct metalog_instance *ctx, struct metadata_lo for (j = 0, recovered_files = 0 ; j < i ; ++j) { metalogfile = metalogfiles[j]; - assert(0 == metalogfile->starting_fileno); + fatal_assert(0 == metalogfile->starting_fileno); if (metalogfile->fileno < starting_fileno) { tmp_metalogfiles[recovered_files++] = metalogfile; continue; @@ -352,7 +352,7 @@ int compaction_failure_recovery(struct metalog_instance *ctx, struct metadata_lo for ( ; j < i ; ++j) { /* continue iterating through normal metadata log files */ metalogfile = metalogfiles[j]; - assert(0 == metalogfile->starting_fileno); + fatal_assert(0 == metalogfile->starting_fileno); if (metalogfile->fileno < fileno) { /* It has already been compacted */ error("Deleting invalid metadata log file \"%s/"METALOG_PREFIX METALOG_FILE_NUMBER_PRINT_TMPL METALOG_EXTENSION"\"", dbfiles_path, 0U, metalogfile->fileno); diff --git a/database/engine/metadata_log/logfile.c b/database/engine/metadata_log/logfile.c index 9ae2866298..117c5e5eee 100644 --- a/database/engine/metadata_log/logfile.c +++ b/database/engine/metadata_log/logfile.c @@ -118,7 +118,7 @@ void mlf_flush_records_buffer(struct metalog_worker_config *wc, struct metadata_ io_descr->iov = uv_buf_init((void *)io_descr->buf, size); ret = uv_fs_write(wc->loop, &io_descr->req, metalogfile->file, &io_descr->iov, 1, metalogfile->pos, flush_records_buffer_cb); - assert (-1 != ret); + fatal_assert(-1 != ret); metalogfile->pos += size; rrd_atomic_fetch_add(&ctx->disk_space, size); records_log->buf = NULL; @@ -132,7 +132,7 @@ void *mlf_get_records_buffer(struct metalog_worker_config *wc, struct metadata_r int ret; unsigned buf_pos, buf_size; - assert(size); + fatal_assert(size); if (records_log->buf) { unsigned remaining; @@ -175,7 +175,7 @@ void metadata_logfile_list_delete(struct metadata_logfile_list *metadata_logfile struct metadata_logfile *next; next = metalogfile->next; - assert((NULL != next) && (metadata_logfiles->first == metalogfile) && + fatal_assert((NULL != next) && (metadata_logfiles->first == metalogfile) && (metadata_logfiles->last != metalogfile)); metadata_logfiles->first = next; } @@ -337,7 +337,7 @@ int create_metadata_logfile(struct metadata_logfile *metalogfile) ret = uv_fs_write(NULL, &req, file, &iov, 1, 0, NULL); if (ret < 0) { - assert(req.result < 0); + fatal_assert(req.result < 0); error("uv_fs_write: %s", uv_strerror(ret)); ++ctx->stats.io_errors; rrd_stat_atomic_add(&global_io_errors, 1); @@ -375,7 +375,7 @@ static int check_metadata_logfile_superblock(uv_file file) uv_fs_req_cleanup(&req); goto error; } - assert(req.result >= 0); + fatal_assert(req.result >= 0); uv_fs_req_cleanup(&req); if (strncmp(superblock->magic_number, RRDENG_METALOG_MAGIC, RRDENG_MAGIC_SZ)) { @@ -614,7 +614,7 @@ static int scan_metalog_files(struct metalog_instance *ctx) ret = uv_fs_scandir(NULL, &req, dbfiles_path, 0, NULL); if (ret < 0) { - assert(req.result < 0); + fatal_assert(req.result < 0); uv_fs_req_cleanup(&req); error("uv_fs_scandir(%s): %s", dbfiles_path, uv_strerror(ret)); ++ctx->stats.fs_errors; diff --git a/database/engine/metadata_log/metadatalog.c b/database/engine/metadata_log/metadatalog.c index b068f85c6a..6ebc2185ea 100644 --- a/database/engine/metadata_log/metadatalog.c +++ b/database/engine/metadata_log/metadatalog.c @@ -52,8 +52,8 @@ void metalog_commit_record(struct metalog_instance *ctx, BUFFER *buffer, enum me { struct metalog_cmd cmd; - assert(buffer_strlen(buffer)); - assert(opcode == METALOG_COMMIT_CREATION_RECORD || opcode == METALOG_COMMIT_DELETION_RECORD); + fatal_assert(buffer_strlen(buffer)); + fatal_assert(opcode == METALOG_COMMIT_CREATION_RECORD || opcode == METALOG_COMMIT_DELETION_RECORD); cmd.opcode = opcode; cmd.record_io_descr.buffer = buffer; @@ -191,8 +191,8 @@ static void metalog_init_cmd_queue(struct metalog_worker_config *wc) { wc->cmd_queue.head = wc->cmd_queue.tail = 0; wc->queue_size = 0; - assert(0 == uv_cond_init(&wc->cmd_cond)); - assert(0 == uv_mutex_init(&wc->cmd_mutex)); + fatal_assert(0 == uv_cond_init(&wc->cmd_cond)); + fatal_assert(0 == uv_mutex_init(&wc->cmd_mutex)); } 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) while ((queue_size = wc->queue_size) == METALOG_CMD_Q_MAX_SIZE) { uv_cond_wait(&wc->cmd_cond, &wc->cmd_mutex); } - assert(queue_size < METALOG_CMD_Q_MAX_SIZE); + fatal_assert(queue_size < METALOG_CMD_Q_MAX_SIZE); /* enqueue command */ wc->cmd_queue.cmd_array[wc->cmd_queue.tail] = *cmd; 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) uv_mutex_unlock(&wc->cmd_mutex); /* wake up event loop */ - assert(0 == uv_async_send(&wc->async)); + fatal_assert(0 == uv_async_send(&wc->async)); } struct metalog_cmd metalog_deq_cmd(struct metalog_worker_config *wc) @@ -318,7 +318,7 @@ void metalog_worker(void* arg) /* wake up initialization thread */ complete(&ctx->metalog_completion); - assert(0 == uv_timer_start(&timer_req, timer_cb, TIMER_PERIOD_MS, TIMER_PERIOD_MS)); + fatal_assert(0 == uv_timer_start(&timer_req, timer_cb, TIMER_PERIOD_MS, TIMER_PERIOD_MS)); shutdown = 0; while (likely(shutdown == 0 || metalog_threads_alive(wc))) { uv_run(loop, UV_RUN_DEFAULT); @@ -347,7 +347,7 @@ void metalog_worker(void* arg) break; case METALOG_QUIESCE: ctx->quiesce = SET_QUIESCE; - assert(0 == uv_timer_stop(&timer_req)); + fatal_assert(0 == uv_timer_stop(&timer_req)); uv_close((uv_handle_t *)&timer_req, NULL); mlf_flush_records_buffer(wc, &ctx->records_log, &ctx->metadata_logfiles); if (!metalog_threads_alive(wc)) { @@ -390,7 +390,7 @@ void metalog_worker(void* arg) /* TODO: don't let the API block by waiting to enqueue commands */ uv_cond_destroy(&wc->cmd_cond); /* uv_mutex_destroy(&wc->cmd_mutex); */ - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); freez(loop); return; @@ -398,7 +398,7 @@ void metalog_worker(void* arg) error_after_timer_init: uv_close((uv_handle_t *)&wc->async, NULL); error_after_async_init: - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); error_after_loop_init: freez(loop); diff --git a/database/engine/metadata_log/metadatalogapi.c b/database/engine/metadata_log/metadatalogapi.c index 6bd09b4d9e..e8a5d27442 100755 --- a/database/engine/metadata_log/metadatalogapi.c +++ b/database/engine/metadata_log/metadatalogapi.c @@ -273,16 +273,16 @@ RRDSET *metalog_get_chart_from_uuid(struct metalog_instance *ctx, uuid_t *chart_ uuid_t *machine_guid, *chart_char_guid; ret = find_object_by_guid(chart_uuid, chart_object, 33); - assert(GUID_TYPE_CHART == ret); + fatal_assert(GUID_TYPE_CHART == ret); machine_guid = (uuid_t *)chart_object; RRDHOST *host = ctx->rrdeng_ctx->host; - assert(!uuid_compare(host->host_uuid, *machine_guid)); + fatal_assert(!uuid_compare(host->host_uuid, *machine_guid)); chart_char_guid = (uuid_t *)(chart_object + 16); ret = find_object_by_guid(chart_char_guid, chart_fullid, RRD_ID_LENGTH_MAX + 1); - assert(GUID_TYPE_CHAR == ret); + fatal_assert(GUID_TYPE_CHAR == ret); RRDSET *st = rrdset_find(host, chart_fullid); return st; @@ -300,22 +300,22 @@ RRDDIM *metalog_get_dimension_from_uuid(struct metalog_instance *ctx, uuid_t *me machine_guid = (uuid_t *)dim_object; RRDHOST *host = ctx->rrdeng_ctx->host; - assert(!uuid_compare(host->host_uuid, *machine_guid)); + fatal_assert(!uuid_compare(host->host_uuid, *machine_guid)); chart_guid = (uuid_t *)(dim_object + 16); dim_char_guid = (uuid_t *)(dim_object + 16 + 16); ret = find_object_by_guid(dim_char_guid, id_str, sizeof(id_str)); - assert(GUID_TYPE_CHAR == ret); + fatal_assert(GUID_TYPE_CHAR == ret); ret = find_object_by_guid(chart_guid, chart_object, sizeof(chart_object)); - assert(GUID_TYPE_CHART == ret); + fatal_assert(GUID_TYPE_CHART == ret); chart_char_guid = (uuid_t *)(chart_object + 16); ret = find_object_by_guid(chart_char_guid, chart_fullid, RRD_ID_LENGTH_MAX + 1); - assert(GUID_TYPE_CHAR == ret); + fatal_assert(GUID_TYPE_CHAR == ret); RRDSET *st = rrdset_find(host, chart_fullid); - assert(st); + fatal_assert(st); RRDDIM *rd = rrddim_find(st, id_str); @@ -386,7 +386,7 @@ int metalog_init(struct rrdengine_instance *rrdeng_parent_ctx) } init_completion(&ctx->metalog_completion); - assert(0 == uv_thread_create(&ctx->worker_config.thread, metalog_worker, &ctx->worker_config)); + fatal_assert(0 == uv_thread_create(&ctx->worker_config.thread, metalog_worker, &ctx->worker_config)); /* wait for worker thread to initialize */ wait_for_completion(&ctx->metalog_completion); destroy_completion(&ctx->metalog_completion); @@ -418,7 +418,7 @@ int metalog_exit(struct metalog_instance *ctx) cmd.opcode = METALOG_SHUTDOWN; metalog_enq_cmd(&ctx->worker_config, &cmd); - assert(0 == uv_thread_join(&ctx->worker_config.thread)); + fatal_assert(0 == uv_thread_join(&ctx->worker_config.thread)); finalize_metalog_files(ctx); freez(ctx); diff --git a/database/engine/metadata_log/metalogpluginsd.c b/database/engine/metadata_log/metalogpluginsd.c index 23027af7b2..da7e19377f 100755 --- a/database/engine/metadata_log/metalogpluginsd.c +++ b/database/engine/metadata_log/metalogpluginsd.c @@ -117,7 +117,7 @@ PARSER_RC metalog_pluginsd_context_action(void *user, uuid_t *uuid) ret = find_object_by_guid(uuid, object, 49); switch (ret) { case GUID_TYPE_CHAR: - assert(0); + fatal_assert(0); break; case GUID_TYPE_CHART: case GUID_TYPE_DIMENSION: @@ -127,22 +127,22 @@ PARSER_RC metalog_pluginsd_context_action(void *user, uuid_t *uuid) chart_char_guid = (uuid_t *)(object + 16); ret = find_object_by_guid(chart_char_guid, id_str, RRD_ID_LENGTH_MAX + 1); - assert(GUID_TYPE_CHAR == ret); + fatal_assert(GUID_TYPE_CHAR == ret); ((PARSER_USER_OBJECT *) user)->st = rrdset_find(host, id_str); break; case GUID_TYPE_DIMENSION: chart_guid = (uuid_t *)(object + 16); ret = find_object_by_guid(chart_guid, chart_object, 33); - assert(GUID_TYPE_CHART == ret); + fatal_assert(GUID_TYPE_CHART == ret); chart_char_guid = (uuid_t *)(chart_object + 16); ret = find_object_by_guid(chart_char_guid, id_str, RRD_ID_LENGTH_MAX + 1); - assert(GUID_TYPE_CHAR == ret); + fatal_assert(GUID_TYPE_CHAR == ret); ((PARSER_USER_OBJECT *) user)->st = rrdset_find(host, id_str); break; default: - assert(0); + fatal_assert(0); break; } break; @@ -168,7 +168,7 @@ PARSER_RC metalog_pluginsd_tombstone_action(void *user, uuid_t *uuid) ret = find_object_by_guid(uuid, NULL, 0); switch (ret) { case GUID_TYPE_CHAR: - assert(0); + fatal_assert(0); break; case GUID_TYPE_CHART: st = metalog_get_chart_from_uuid(ctx, uuid); diff --git a/database/engine/pagecache.c b/database/engine/pagecache.c index f1f3a5be85..f37257c425 100644 --- a/database/engine/pagecache.c +++ b/database/engine/pagecache.c @@ -406,7 +406,7 @@ uint8_t pg_cache_punch_hole(struct rrdengine_instance *ctx, struct rrdeng_page_d uv_rwlock_rdlock(&pg_cache->metrics_index.lock); PValue = JudyHSGet(pg_cache->metrics_index.JudyHS_array, descr->id, sizeof(uuid_t)); - assert(NULL != PValue); + fatal_assert(NULL != PValue); page_index = *PValue; uv_rwlock_rdunlock(&pg_cache->metrics_index.lock); @@ -428,7 +428,7 @@ uint8_t pg_cache_punch_hole(struct rrdengine_instance *ctx, struct rrdeng_page_d } } uv_rwlock_wrunlock(&page_index->lock); - assert(1 == ret); + fatal_assert(1 == ret); uv_rwlock_wrlock(&pg_cache->pg_cache_rwlock); ++ctx->stats.pg_cache_deletions; @@ -565,7 +565,7 @@ void pg_cache_update_metric_times(struct pg_cache_page_index *page_index) uv_rwlock_rdunlock(&page_index->lock); if (unlikely(NULL == firstPValue)) { - assert(NULL == lastPValue); + fatal_assert(NULL == lastPValue); page_index->oldest_time = page_index->latest_time = INVALID_TIME; return; } @@ -586,7 +586,7 @@ void pg_cache_insert(struct rrdengine_instance *ctx, struct pg_cache_page_index /* there is page cache descriptor pre-allocated state */ struct page_cache_descr *pg_cache_descr = descr->pg_cache_descr; - assert(pg_cache_descr_state & PG_CACHE_DESCR_ALLOCATED); + fatal_assert(pg_cache_descr_state & PG_CACHE_DESCR_ALLOCATED); if (pg_cache_descr->flags & RRD_PAGE_POPULATED) { pg_cache_reserve_pages(ctx, 1); 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 if (unlikely(NULL == index)) { uv_rwlock_rdlock(&pg_cache->metrics_index.lock); PValue = JudyHSGet(pg_cache->metrics_index.JudyHS_array, descr->id, sizeof(uuid_t)); - assert(NULL != PValue); + fatal_assert(NULL != PValue); page_index = *PValue; uv_rwlock_rdunlock(&pg_cache->metrics_index.lock); } else { @@ -662,7 +662,7 @@ void pg_cache_get_filtered_info_prev(struct rrdengine_instance *ctx, struct pg_c Word_t Index; (void)pg_cache; - assert(NULL != page_index); + fatal_assert(NULL != page_index); Index = (Word_t)(point_in_time / USEC_PER_SEC); uv_rwlock_rdlock(&page_index->lock); @@ -707,7 +707,7 @@ unsigned pg_cache_preload(struct rrdengine_instance *ctx, uuid_t *id, usec_t sta Word_t Index; uint8_t failed_to_reserve; - assert(NULL != ret_page_indexp); + fatal_assert(NULL != ret_page_indexp); uv_rwlock_rdlock(&pg_cache->metrics_index.lock); 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) page_index = mallocz(sizeof(*page_index)); page_index->JudyL_array = (Pvoid_t) NULL; uuid_copy(page_index->id, *id); - assert(0 == uv_rwlock_init(&page_index->lock)); + fatal_assert(0 == uv_rwlock_init(&page_index->lock)); page_index->oldest_time = INVALID_TIME; page_index->latest_time = INVALID_TIME; page_index->prev = NULL; @@ -1064,7 +1064,7 @@ static void init_metrics_index(struct rrdengine_instance *ctx) pg_cache->metrics_index.JudyHS_array = (Pvoid_t) NULL; pg_cache->metrics_index.last_page_index = NULL; - assert(0 == uv_rwlock_init(&pg_cache->metrics_index.lock)); + fatal_assert(0 == uv_rwlock_init(&pg_cache->metrics_index.lock)); } static void init_replaceQ(struct rrdengine_instance *ctx) @@ -1073,7 +1073,7 @@ static void init_replaceQ(struct rrdengine_instance *ctx) pg_cache->replaceQ.head = NULL; pg_cache->replaceQ.tail = NULL; - assert(0 == uv_rwlock_init(&pg_cache->replaceQ.lock)); + fatal_assert(0 == uv_rwlock_init(&pg_cache->replaceQ.lock)); } static void init_committed_page_index(struct rrdengine_instance *ctx) @@ -1081,7 +1081,7 @@ static void init_committed_page_index(struct rrdengine_instance *ctx) struct page_cache *pg_cache = &ctx->pg_cache; pg_cache->committed_page_index.JudyL_array = (Pvoid_t) NULL; - assert(0 == uv_rwlock_init(&pg_cache->committed_page_index.lock)); + fatal_assert(0 == uv_rwlock_init(&pg_cache->committed_page_index.lock)); pg_cache->committed_page_index.latest_corr_id = 0; pg_cache->committed_page_index.nr_committed_pages = 0; } @@ -1092,7 +1092,7 @@ void init_page_cache(struct rrdengine_instance *ctx) pg_cache->page_descriptors = 0; pg_cache->populated_pages = 0; - assert(0 == uv_rwlock_init(&pg_cache->pg_cache_rwlock)); + fatal_assert(0 == uv_rwlock_init(&pg_cache->pg_cache_rwlock)); init_metrics_index(ctx); init_replaceQ(ctx); @@ -1111,7 +1111,7 @@ void free_page_cache(struct rrdengine_instance *ctx) /* Free committed page index */ ret_Judy = JudyLFreeArray(&pg_cache->committed_page_index.JudyL_array, PJE0); - assert(NULL == pg_cache->committed_page_index.JudyL_array); + fatal_assert(NULL == pg_cache->committed_page_index.JudyL_array); bytes_freed += ret_Judy; for (page_index = pg_cache->metrics_index.last_page_index ; @@ -1146,14 +1146,14 @@ void free_page_cache(struct rrdengine_instance *ctx) /* Free page index */ ret_Judy = JudyLFreeArray(&page_index->JudyL_array, PJE0); - assert(NULL == page_index->JudyL_array); + fatal_assert(NULL == page_index->JudyL_array); bytes_freed += ret_Judy; freez(page_index); bytes_freed += sizeof(*page_index); } /* Free metrics index */ ret_Judy = JudyHSFreeArray(&pg_cache->metrics_index.JudyHS_array, PJE0); - assert(NULL == pg_cache->metrics_index.JudyHS_array); + fatal_assert(NULL == pg_cache->metrics_index.JudyHS_array); bytes_freed += ret_Judy; info("Freed %lu bytes of memory from page cache.", bytes_freed); diff --git a/database/engine/pagecache.h b/database/engine/pagecache.h index 4ca57cd667..31e9739da6 100644 --- a/database/engine/pagecache.h +++ b/database/engine/pagecache.h @@ -219,7 +219,7 @@ static inline void /* The caller must hold a reference to the page and must have already set the new data */ static inline void pg_cache_atomic_set_pg_info(struct rrdeng_page_descr *descr, usec_t end_time, uint32_t page_length) { - assert(!(end_time & 1)); + fatal_assert(!(end_time & 1)); __sync_synchronize(); descr->end_time |= 1; /* mark start of uncertainty period by adding 1 microsecond */ __sync_synchronize(); diff --git a/database/engine/rrdengine.c b/database/engine/rrdengine.c index bf59242711..000bf88a6a 100644 --- a/database/engine/rrdengine.c +++ b/database/engine/rrdengine.c @@ -191,7 +191,7 @@ static void do_read_extent(struct rrdengine_worker_config* wc, real_io_size = ALIGN_BYTES_CEILING(size_bytes); xt_io_descr->iov = uv_buf_init((void *)xt_io_descr->buf, real_io_size); ret = uv_fs_read(wc->loop, &xt_io_descr->req, datafile->file, &xt_io_descr->iov, 1, pos, read_extent_cb); - assert (-1 != ret); + fatal_assert(-1 != ret); ctx->stats.io_read_bytes += real_io_size; ++ctx->stats.io_read_requests; 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 commit_data_extent(wc, (struct extent_io_descriptor *)data); break; default: - assert(type == STORE_DATA); + fatal_assert(type == STORE_DATA); break; } } @@ -284,7 +284,7 @@ static void invalidate_oldest_committed(void *arg) PValue = JudyLNext(pg_cache->committed_page_index.JudyL_array, &Index, PJE0), descr = unlikely(NULL == PValue) ? NULL : *PValue) { - assert(0 != descr->page_length); + fatal_assert(0 != descr->page_length); rrdeng_page_descr_mutex_lock(ctx, descr); pg_cache_descr = descr->pg_cache_descr; @@ -292,7 +292,7 @@ static void invalidate_oldest_committed(void *arg) rrdeng_page_descr_mutex_unlock(ctx, descr); ret = JudyLDel(&pg_cache->committed_page_index.JudyL_array, Index, PJE0); - assert(1 == ret); + fatal_assert(1 == ret); break; } rrdeng_page_descr_mutex_unlock(ctx, descr); @@ -316,7 +316,7 @@ static void invalidate_oldest_committed(void *arg) out: wc->cleanup_thread_invalidating_dirty_pages = 1; /* wake up event loop */ - assert(0 == uv_async_send(&wc->async)); + fatal_assert(0 == uv_async_send(&wc->async)); } 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 descr = unlikely(NULL == PValue) ? NULL : *PValue) { uint8_t page_write_pending; - assert(0 != descr->page_length); + fatal_assert(0 != descr->page_length); page_write_pending = 0; rrdeng_page_descr_mutex_lock(ctx, descr); @@ -463,7 +463,7 @@ static int do_flush_pages(struct rrdengine_worker_config* wc, int force, struct if (page_write_pending) { ret = JudyLDel(&pg_cache->committed_page_index.JudyL_array, Index, PJE0); - assert(1 == ret); + fatal_assert(1 == ret); } } 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 size_bytes = payload_offset + uncompressed_payload_length + sizeof(*trailer); break; default: /* Compress */ - assert(uncompressed_payload_length < LZ4_MAX_INPUT_SIZE); + fatal_assert(uncompressed_payload_length < LZ4_MAX_INPUT_SIZE); max_compressed_size = LZ4_compressBound(uncompressed_payload_length); compressed_buf = mallocz(max_compressed_size); 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 real_io_size = ALIGN_BYTES_CEILING(size_bytes); xt_io_descr->iov = uv_buf_init((void *)xt_io_descr->buf, real_io_size); ret = uv_fs_write(wc->loop, &xt_io_descr->req, datafile->file, &xt_io_descr->iov, 1, datafile->pos, flush_pages_cb); - assert (-1 != ret); + fatal_assert(-1 != ret); ctx->stats.io_write_bytes += real_io_size; ++ctx->stats.io_write_requests; ctx->stats.io_write_extent_bytes += real_io_size; @@ -657,7 +657,7 @@ static void delete_old_data(void *arg) } wc->cleanup_thread_deleting_files = 1; /* wake up event loop */ - assert(0 == uv_async_send(&wc->async)); + fatal_assert(0 == uv_async_send(&wc->async)); } void rrdeng_test_quota(struct rrdengine_worker_config* wc) @@ -751,8 +751,8 @@ void rrdeng_init_cmd_queue(struct rrdengine_worker_config* wc) { wc->cmd_queue.head = wc->cmd_queue.tail = 0; wc->queue_size = 0; - assert(0 == uv_cond_init(&wc->cmd_cond)); - assert(0 == uv_mutex_init(&wc->cmd_mutex)); + fatal_assert(0 == uv_cond_init(&wc->cmd_cond)); + fatal_assert(0 == uv_mutex_init(&wc->cmd_mutex)); } 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) while ((queue_size = wc->queue_size) == RRDENG_CMD_Q_MAX_SIZE) { uv_cond_wait(&wc->cmd_cond, &wc->cmd_mutex); } - assert(queue_size < RRDENG_CMD_Q_MAX_SIZE); + fatal_assert(queue_size < RRDENG_CMD_Q_MAX_SIZE); /* enqueue command */ wc->cmd_queue.cmd_array[wc->cmd_queue.tail] = *cmd; 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) uv_mutex_unlock(&wc->cmd_mutex); /* wake up event loop */ - assert(0 == uv_async_send(&wc->async)); + fatal_assert(0 == uv_async_send(&wc->async)); } struct rrdeng_cmd rrdeng_deq_cmd(struct rrdengine_worker_config* wc) @@ -914,7 +914,7 @@ void rrdeng_worker(void* arg) /* wake up initialization thread */ complete(&ctx->rrdengine_completion); - assert(0 == uv_timer_start(&timer_req, timer_cb, TIMER_PERIOD_MS, TIMER_PERIOD_MS)); + fatal_assert(0 == uv_timer_start(&timer_req, timer_cb, TIMER_PERIOD_MS, TIMER_PERIOD_MS)); shutdown = 0; while (likely(shutdown == 0 || rrdeng_threads_alive(wc))) { uv_run(loop, UV_RUN_DEFAULT); @@ -944,7 +944,7 @@ void rrdeng_worker(void* arg) case RRDENG_QUIESCE: ctx->drop_metrics_under_page_cache_pressure = 0; ctx->quiesce = SET_QUIESCE; - assert(0 == uv_timer_stop(&timer_req)); + fatal_assert(0 == uv_timer_stop(&timer_req)); uv_close((uv_handle_t *)&timer_req, NULL); while (do_flush_pages(wc, 1, NULL)) { ; /* Force flushing of all committed pages. */ @@ -1003,7 +1003,7 @@ void rrdeng_worker(void* arg) /* TODO: don't let the API block by waiting to enqueue commands */ uv_cond_destroy(&wc->cmd_cond); /* uv_mutex_destroy(&wc->cmd_mutex); */ - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); freez(loop); return; @@ -1011,7 +1011,7 @@ void rrdeng_worker(void* arg) error_after_timer_init: uv_close((uv_handle_t *)&wc->async, NULL); error_after_async_init: - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); error_after_loop_init: freez(loop); diff --git a/database/engine/rrdengineapi.c b/database/engine/rrdengineapi.c index b09d12c0e6..daa96376ed 100755 --- a/database/engine/rrdengineapi.c +++ b/database/engine/rrdengineapi.c @@ -22,7 +22,7 @@ void rrdeng_generate_legacy_uuid(const char *dim_id, char *chart_id, uuid_t *ret EVP_DigestUpdate(evpctx, chart_id, strlen(chart_id)); EVP_DigestFinal_ex(evpctx, hash_value, &hash_len); EVP_MD_CTX_destroy(evpctx); - assert(hash_len > sizeof(uuid_t)); + fatal_assert(hash_len > sizeof(uuid_t)); memcpy(ret_uuid, hash_value, sizeof(uuid_t)); } @@ -39,7 +39,7 @@ void rrdeng_convert_legacy_uuid_to_multihost(char machine_guid[GUID_LEN + 1], uu EVP_DigestUpdate(evpctx, *legacy_uuid, sizeof(uuid_t)); EVP_DigestFinal_ex(evpctx, hash_value, &hash_len); EVP_MD_CTX_destroy(evpctx); - assert(hash_len > sizeof(uuid_t)); + fatal_assert(hash_len > sizeof(uuid_t)); memcpy(ret_uuid, hash_value, sizeof(uuid_t)); } @@ -77,7 +77,7 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid) error("FAILED to generate GUID for %s", rd->id); freez(rd->state->metric_uuid); rd->state->metric_uuid = NULL; - assert(0); + fatal_assert(0); } uv_rwlock_rdlock(&pg_cache->metrics_index.lock); @@ -89,7 +89,7 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid) if (NULL == PValue) { uv_rwlock_wrlock(&pg_cache->metrics_index.lock); PValue = JudyHSIns(&pg_cache->metrics_index.JudyHS_array, rd->state->metric_uuid, sizeof(uuid_t), PJE0); - assert(NULL == *PValue); /* TODO: figure out concurrency model */ + fatal_assert(NULL == *PValue); /* TODO: figure out concurrency model */ *PValue = page_index = create_page_index(rd->state->metric_uuid); page_index->prev = pg_cache->metrics_index.last_page_index; pg_cache->metrics_index.last_page_index = page_index; @@ -109,7 +109,7 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid) error("FAILED to generate GUID for %s", rd->id); freez(rd->state->metric_uuid); rd->state->metric_uuid = NULL; - assert(0); + fatal_assert(0); } } rd->state->rrdeng_uuid = &page_index->id; @@ -192,7 +192,7 @@ void rrdeng_store_metric_flush_current_page(RRDDIM *rd) rrdeng_page_descr_mutex_lock(ctx, descr); ret = pg_cache_try_get_unsafe(descr, 0); rrdeng_page_descr_mutex_unlock(ctx, descr); - assert (1 == ret); + fatal_assert(1 == ret); rrdeng_commit_page(ctx, descr, handle->page_correlation_id); handle->prev_descr = descr; @@ -247,7 +247,7 @@ void rrdeng_store_metric_next(RRDDIM *rd, usec_t point_in_time, storage_number n rrdeng_store_metric_flush_current_page(rd); page = rrdeng_create_page(ctx, &rd->state->page_index->id, &descr); - assert(page); + fatal_assert(page); handle->descr = descr; @@ -415,7 +415,7 @@ unsigned rrdeng_variable_step_boundaries(RRDSET *st, time_t start_time, time_t e continue; } page_entries = curr->page_length / sizeof(storage_number); - assert(0 != page_entries); + fatal_assert(0 != page_entries); if (likely(1 != page_entries)) { dt = (curr->end_time - curr->start_time) / (page_entries - 1); *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 if (1 == page_points) first_valid_time_in_page = current_position_time; if (unlikely(!is_first_region_initialized)) { - assert(1 == regions); + fatal_assert(1 == regions); /* this is the first region */ region_info_array[0].start_time = current_position_time; is_first_region_initialized = 1; @@ -464,7 +464,7 @@ unsigned rrdeng_variable_step_boundaries(RRDSET *st, time_t start_time, time_t e } if (unlikely(0 == *pginfo_to_dt(curr))) { /* unknown data collection interval */ - assert(1 == page_points); + fatal_assert(1 == page_points); if (likely(NULL != prev)) { /* get interval from previous page */ *pginfo_to_dt(curr) = *pginfo_to_dt(prev); @@ -620,7 +620,7 @@ storage_number rrdeng_load_metric_next(struct rrddim_query_handle *rrdimm_handle } handle->position = position; handle->now = current_position_time / USEC_PER_SEC; -/* assert(handle->now >= rrdimm_handle->start_time && handle->now <= rrdimm_handle->end_time); +/* fatal_assert(handle->now >= rrdimm_handle->start_time && handle->now <= rrdimm_handle->end_time); The above assertion is an approximation and needs to take update_every into account */ if (unlikely(handle->now >= rrdimm_handle->end_time)) { /* next calls will not load any more metrics */ @@ -716,7 +716,7 @@ void rrdeng_commit_page(struct rrdengine_instance *ctx, struct rrdeng_page_descr debug(D_RRDENGINE, "%s: page descriptor is NULL, page has already been force-committed.", __func__); return; } - assert(descr->page_length); + fatal_assert(descr->page_length); uv_rwlock_wrlock(&pg_cache->committed_page_index.lock); 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 array[34] = (uint64_t)global_pg_cache_over_half_dirty_events; array[35] = (uint64_t)ctx->stats.flushing_pressure_page_deletions; array[36] = (uint64_t)global_flushing_pressure_page_deletions; - assert(RRDENG_NR_STATS == 37); + fatal_assert(RRDENG_NR_STATS == 37); } /* Releases reference to page */ @@ -903,7 +903,7 @@ int rrdeng_init(RRDHOST *host, struct rrdengine_instance **ctxp, char *dbfiles_p } init_completion(&ctx->rrdengine_completion); - assert(0 == uv_thread_create(&ctx->worker_config.thread, rrdeng_worker, &ctx->worker_config)); + fatal_assert(0 == uv_thread_create(&ctx->worker_config.thread, rrdeng_worker, &ctx->worker_config)); /* wait for worker thread to initialize */ wait_for_completion(&ctx->rrdengine_completion); destroy_completion(&ctx->rrdengine_completion); @@ -945,7 +945,7 @@ int rrdeng_exit(struct rrdengine_instance *ctx) cmd.opcode = RRDENG_SHUTDOWN; rrdeng_enq_cmd(&ctx->worker_config, &cmd); - assert(0 == uv_thread_join(&ctx->worker_config.thread)); + fatal_assert(0 == uv_thread_join(&ctx->worker_config.thread)); finalize_rrd_files(ctx); metalog_exit(ctx->metalog_ctx); diff --git a/database/engine/rrdenginelib.c b/database/engine/rrdenginelib.c index 26696fb25d..1edcb9c7e8 100644 --- a/database/engine/rrdenginelib.c +++ b/database/engine/rrdenginelib.c @@ -60,7 +60,7 @@ int check_file_properties(uv_file file, uint64_t *file_size, size_t min_size) if (ret < 0) { fatal("uv_fs_fstat: %s\n", uv_strerror(ret)); } - assert(req.result == 0); + fatal_assert(req.result == 0); s = req.ptr; if (!(s->st_mode & S_IFREG)) { error("Not a regular file.\n"); @@ -92,7 +92,7 @@ int open_file_for_io(char *path, int flags, uv_file *file, int direct) uv_fs_t req; int fd, current_flags; - assert(0 == direct || 1 == direct); + fatal_assert(0 == direct || 1 == direct); for ( ; direct >= 0 ; --direct) { #ifdef __APPLE__ /* 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) --direct; /* break the loop */ } } else { - assert(req.result >= 0); + fatal_assert(req.result >= 0); *file = req.result; #ifdef __APPLE__ info("Disabling OS X caching for file \"%s\".", path); diff --git a/database/engine/rrdenginelib.h b/database/engine/rrdenginelib.h index 7962cbc018..982085d295 100644 --- a/database/engine/rrdenginelib.h +++ b/database/engine/rrdenginelib.h @@ -59,8 +59,8 @@ struct completion { static inline void init_completion(struct completion *p) { p->completed = 0; - assert(0 == uv_cond_init(&p->cond)); - assert(0 == uv_mutex_init(&p->mutex)); + fatal_assert(0 == uv_cond_init(&p->cond)); + fatal_assert(0 == uv_mutex_init(&p->mutex)); } static inline void destroy_completion(struct completion *p) @@ -75,7 +75,7 @@ static inline void wait_for_completion(struct completion *p) while (0 == p->completed) { uv_cond_wait(&p->cond, &p->mutex); } - assert(1 == p->completed); + fatal_assert(1 == p->completed); uv_mutex_unlock(&p->mutex); } diff --git a/database/engine/rrdenglocking.c b/database/engine/rrdenglocking.c index 0c1d26f25a..a23abf307d 100644 --- a/database/engine/rrdenglocking.c +++ b/database/engine/rrdenglocking.c @@ -12,8 +12,8 @@ struct page_cache_descr *rrdeng_create_pg_cache_descr(struct rrdengine_instance pg_cache_descr->prev = pg_cache_descr->next = NULL; pg_cache_descr->refcnt = 0; pg_cache_descr->waiters = 0; - assert(0 == uv_cond_init(&pg_cache_descr->cond)); - assert(0 == uv_mutex_init(&pg_cache_descr->mutex)); + fatal_assert(0 == uv_cond_init(&pg_cache_descr->cond)); + fatal_assert(0 == uv_mutex_init(&pg_cache_descr->mutex)); return pg_cache_descr; } @@ -39,7 +39,7 @@ void rrdeng_page_descr_mutex_lock(struct rrdengine_instance *ctx, struct rrdeng_ old_users = old_state >> PG_CACHE_DESCR_SHIFT; if (unlikely(we_locked)) { - assert(old_state & PG_CACHE_DESCR_LOCKED); + fatal_assert(old_state & PG_CACHE_DESCR_LOCKED); new_state = (1 << PG_CACHE_DESCR_SHIFT) | PG_CACHE_DESCR_ALLOCATED; ret_state = ulong_compare_and_swap(&descr->pg_cache_descr_state, old_state, new_state); if (old_state == ret_state) { @@ -49,7 +49,7 @@ void rrdeng_page_descr_mutex_lock(struct rrdengine_instance *ctx, struct rrdeng_ continue; /* spin */ } if (old_state & PG_CACHE_DESCR_LOCKED) { - assert(0 == old_users); + fatal_assert(0 == old_users); continue; /* spin */ } if (0 == old_state) { @@ -106,7 +106,7 @@ void rrdeng_page_descr_mutex_unlock(struct rrdengine_instance *ctx, struct rrden old_users = old_state >> PG_CACHE_DESCR_SHIFT; if (unlikely(we_locked)) { - assert(0 == old_users); + fatal_assert(0 == old_users); ret_state = ulong_compare_and_swap(&descr->pg_cache_descr_state, old_state, 0); if (old_state == ret_state) { @@ -117,15 +117,15 @@ void rrdeng_page_descr_mutex_unlock(struct rrdengine_instance *ctx, struct rrden continue; /* spin */ } if (old_state & PG_CACHE_DESCR_LOCKED) { - assert(0 == old_users); + fatal_assert(0 == old_users); continue; /* spin */ } - assert(old_state & PG_CACHE_DESCR_ALLOCATED); + fatal_assert(old_state & PG_CACHE_DESCR_ALLOCATED); pg_cache_descr = descr->pg_cache_descr; /* caller is the only page cache descriptor user and there are no pending references on the page */ if ((old_state & PG_CACHE_DESCR_DESTROY) && (1 == old_users) && !pg_cache_descr->flags && !pg_cache_descr->refcnt) { - assert(!pg_cache_descr->waiters); + fatal_assert(!pg_cache_descr->waiters); new_state = PG_CACHE_DESCR_LOCKED; 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 } continue; /* spin */ } - assert(old_users > 0); + fatal_assert(old_users > 0); new_state = (old_users - 1) << PG_CACHE_DESCR_SHIFT; new_state |= old_state & PG_CACHE_DESCR_FLAGS_MASK; @@ -170,13 +170,13 @@ void rrdeng_try_deallocate_pg_cache_descr(struct rrdengine_instance *ctx, struct old_users = old_state >> PG_CACHE_DESCR_SHIFT; if (unlikely(just_locked)) { - assert(0 == old_users); + fatal_assert(0 == old_users); must_unlock = 1; just_locked = 0; /* Try deallocate if there are no pending references on the page */ if (!pg_cache_descr->flags && !pg_cache_descr->refcnt) { - assert(!pg_cache_descr->waiters); + fatal_assert(!pg_cache_descr->waiters); descr->pg_cache_descr = NULL; can_free = 1; @@ -186,7 +186,7 @@ void rrdeng_try_deallocate_pg_cache_descr(struct rrdengine_instance *ctx, struct continue; /* spin */ } if (unlikely(must_unlock)) { - assert(0 == old_users); + fatal_assert(0 == old_users); if (can_free) { /* success */ @@ -209,7 +209,7 @@ void rrdeng_try_deallocate_pg_cache_descr(struct rrdengine_instance *ctx, struct return; } if (old_state & PG_CACHE_DESCR_LOCKED) { - assert(0 == old_users); + fatal_assert(0 == old_users); continue; /* spin */ } /* caller is the only page cache descriptor user */ diff --git a/database/rrdset.c b/database/rrdset.c index 9bce32e528..9fc4009aff 100644 --- a/database/rrdset.c +++ b/database/rrdset.c @@ -927,7 +927,7 @@ RRDSET *rrdset_create_custom( error("FAILED to generate GUID for %s", st->id); freez(st->chart_uuid); st->chart_uuid = NULL; - assert(0); + fatal_assert(0); } st->compaction_id = 0; } diff --git a/libnetdata/log/log.h b/libnetdata/log/log.h index 8b54f28de1..1d32cf2091 100644 --- a/libnetdata/log/log.h +++ b/libnetdata/log/log.h @@ -89,6 +89,7 @@ static inline void debug_dummy(void) {} #define infoerr(args...) error_int("INFO", __FILE__, __FUNCTION__, __LINE__, ##args) #define error(args...) error_int("ERROR", __FILE__, __FUNCTION__, __LINE__, ##args) #define fatal(args...) fatal_int(__FILE__, __FUNCTION__, __LINE__, ##args) +#define fatal_assert(expr) ((expr) ? (void)(0) : fatal_int(__FILE__, __FUNCTION__, __LINE__, "Assertion `%s' failed", #expr)) extern void send_statistics(const char *action, const char *action_result, const char *action_data); extern void debug_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... ) PRINTFLIKE(4, 5); diff --git a/spawn/spawn.c b/spawn/spawn.c index 0bacbbca16..256c046790 100644 --- a/spawn/spawn.c +++ b/spawn/spawn.c @@ -14,8 +14,8 @@ static struct spawn_cmd_info *create_spawn_cmd(char *command_to_run) struct spawn_cmd_info *cmdinfo; cmdinfo = mallocz(sizeof(*cmdinfo)); - assert(0 == uv_cond_init(&cmdinfo->cond)); - assert(0 == uv_mutex_init(&cmdinfo->mutex)); + fatal_assert(0 == uv_cond_init(&cmdinfo->cond)); + fatal_assert(0 == uv_mutex_init(&cmdinfo->mutex)); cmdinfo->serial = 0; /* invalid */ cmdinfo->command_to_run = strdupz(command_to_run); cmdinfo->exit_status = -1; /* invalid */ @@ -51,8 +51,8 @@ static void init_spawn_cmd_queue(void) spawn_cmd_queue.cmd_tree.compar = spawn_cmd_compare; spawn_cmd_queue.size = 0; spawn_cmd_queue.latest_serial = 0; - assert(0 == uv_cond_init(&spawn_cmd_queue.cond)); - assert(0 == uv_mutex_init(&spawn_cmd_queue.mutex)); + fatal_assert(0 == uv_cond_init(&spawn_cmd_queue.cond)); + fatal_assert(0 == uv_mutex_init(&spawn_cmd_queue.mutex)); } /* @@ -72,7 +72,7 @@ uint64_t spawn_enq_cmd(char *command_to_run) while ((queue_size = spawn_cmd_queue.size) == SPAWN_MAX_OUTSTANDING) { uv_cond_wait(&spawn_cmd_queue.cond, &spawn_cmd_queue.mutex); } - assert(queue_size < SPAWN_MAX_OUTSTANDING); + fatal_assert(queue_size < SPAWN_MAX_OUTSTANDING); spawn_cmd_queue.size = queue_size + 1; serial = ++spawn_cmd_queue.latest_serial; /* 0 is invalid */ @@ -80,11 +80,11 @@ uint64_t spawn_enq_cmd(char *command_to_run) /* enqueue command */ avl_ret = avl_insert(&spawn_cmd_queue.cmd_tree, (avl *)cmdinfo); - assert(avl_ret == (avl *)cmdinfo); + fatal_assert(avl_ret == (avl *)cmdinfo); uv_mutex_unlock(&spawn_cmd_queue.mutex); /* wake up event loop */ - assert(0 == uv_async_send(&spawn_async)); + fatal_assert(0 == uv_async_send(&spawn_async)); return serial; } @@ -102,7 +102,7 @@ void spawn_wait_cmd(uint64_t serial, int *exit_status, time_t *exec_run_timestam avl_ret = avl_search(&spawn_cmd_queue.cmd_tree, (avl *)&tmp); uv_mutex_unlock(&spawn_cmd_queue.mutex); - assert(avl_ret); /* Could be NULL if more than 1 threads wait for the command */ + fatal_assert(avl_ret); /* Could be NULL if more than 1 threads wait for the command */ cmdinfo = (struct spawn_cmd_info *)avl_ret; uv_mutex_lock(&cmdinfo->mutex); @@ -126,10 +126,10 @@ void spawn_deq_cmd(struct spawn_cmd_info *cmdinfo) uv_mutex_lock(&spawn_cmd_queue.mutex); queue_size = spawn_cmd_queue.size; - assert(queue_size); + fatal_assert(queue_size); /* dequeue command */ avl_ret = avl_remove(&spawn_cmd_queue.cmd_tree, (avl *)cmdinfo); - assert(avl_ret); + fatal_assert(avl_ret); spawn_cmd_queue.size = queue_size - 1; diff --git a/spawn/spawn_client.c b/spawn/spawn_client.c index bcc028a46c..83dc3c80df 100644 --- a/spawn/spawn_client.c +++ b/spawn/spawn_client.c @@ -42,7 +42,7 @@ static void client_parse_spawn_protocol(unsigned source_len, char *source) header = (struct spawn_prot_header *)prot_buffer; cmdinfo = (struct spawn_cmd_info *)header->handle; - assert(NULL != cmdinfo); + fatal_assert(NULL != cmdinfo); switch(header->opcode) { case SPAWN_PROT_SPAWN_RESULT: @@ -90,7 +90,7 @@ static void client_parse_spawn_protocol(unsigned source_len, char *source) prot_buffer_len = 0; break; default: - assert(0); + fatal_assert(0); break; } @@ -158,7 +158,7 @@ static void spawn_process_cmd(struct spawn_cmd_info *cmdinfo) info("CLIENT %s SPAWN_PROT_EXEC_CMD %u", __func__, (unsigned)cmdinfo->serial); #endif ret = uv_write(&write_ctx->write_req, (uv_stream_t *)&spawn_channel, writebuf, 3, after_pipe_write); - assert(ret == 0); + fatal_assert(ret == 0); } void spawn_client(void *arg) @@ -189,7 +189,7 @@ void spawn_client(void *arg) spawn_thread_error = ret; goto error_after_pipe_init; } - assert(spawn_channel.ipc); + fatal_assert(spawn_channel.ipc); ret = create_spawn_server(loop, &spawn_channel, &process); if (ret) { @@ -205,7 +205,7 @@ void spawn_client(void *arg) prot_buffer_len = 0; ret = uv_read_start((uv_stream_t *)&spawn_channel, on_read_alloc, on_pipe_read); - assert(ret == 0); + fatal_assert(ret == 0); while (spawn_thread_shutdown == 0) { struct spawn_cmd_info *cmdinfo; @@ -222,7 +222,7 @@ void spawn_client(void *arg) uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */ info("Shutting down spawn client loop complete."); - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); return; @@ -232,7 +232,7 @@ error_after_pipe_init: uv_close((uv_handle_t *)&spawn_async, NULL); error_after_async_init: uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */ - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); error_after_loop_init: freez(loop); diff --git a/spawn/spawn_server.c b/spawn/spawn_server.c index b7a2546eae..f84fab1caa 100644 --- a/spawn/spawn_server.c +++ b/spawn/spawn_server.c @@ -96,7 +96,7 @@ static void child_waited_async_cb(uv_async_t *async_handle) fprintf(stderr, "SERVER %s SPAWN_PROT_CMD_EXIT_STATUS\n", __func__); #endif ret = uv_write(&write_ctx->write_req, (uv_stream_t *) &server_pipe, writebuf, 2, after_pipe_write); - assert(ret == 0); + fatal_assert(ret == 0); freez(exec_info); } @@ -131,7 +131,7 @@ static void wait_children(void *arg) #ifdef SPAWN_DEBUG fprintf(stderr, "SPAWN: Successfully waited for pid:%d.\n", (int) i.si_pid); #endif - assert(CLD_EXITED == i.si_code); + fatal_assert(CLD_EXITED == i.si_code); tmp.pid = (pid_t)i.si_pid; while (NULL == (ret_avl = avl_remove_lock(&spawn_outstanding_exec_tree, (avl *)&tmp))) { fprintf(stderr, @@ -144,7 +144,7 @@ static void wait_children(void *arg) enqueue_child_waited_list(exec_info); /* wake up event loop */ - assert(0 == uv_async_send(&child_waited_async)); + fatal_assert(0 == uv_async_send(&child_waited_async)); } } } @@ -175,7 +175,7 @@ void spawn_protocol_execute_command(void *handle, char *command_to_run, uint16_t exec_info->handle = handle; exec_info->pid = write_ctx->spawn_result.exec_pid; avl_ret = avl_insert_lock(&spawn_outstanding_exec_tree, (avl *)exec_info); - assert(avl_ret == (avl *)exec_info); + fatal_assert(avl_ret == (avl *)exec_info); /* wake up the thread that blocks waiting for processes to exit */ uv_mutex_lock(&wait_children_mutex); @@ -192,7 +192,7 @@ void spawn_protocol_execute_command(void *handle, char *command_to_run, uint16_t fprintf(stderr, "SERVER %s SPAWN_PROT_SPAWN_RESULT\n", __func__); #endif ret = uv_write(&write_ctx->write_req, (uv_stream_t *)&server_pipe, writebuf, 2, after_pipe_write); - assert(ret == 0); + fatal_assert(ret == 0); } 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) return; /* Source buffer ran out */ header = (struct spawn_prot_header *)prot_buffer; - assert(SPAWN_PROT_EXEC_CMD == header->opcode); - assert(NULL != header->handle); + fatal_assert(SPAWN_PROT_EXEC_CMD == header->opcode); + fatal_assert(NULL != header->handle); required_len += sizeof(*payload); if (prot_buffer_len < required_len) @@ -338,7 +338,7 @@ void spawn_server(void) fprintf(stderr, "uv_pipe_init(): %s\n", uv_strerror(error)); exit(error); } - assert(server_pipe.ipc); + fatal_assert(server_pipe.ipc); error = uv_pipe_open(&server_pipe, 0 /* UV_STDIN_FD */); if (error) { @@ -348,8 +348,8 @@ void spawn_server(void) avl_init_lock(&spawn_outstanding_exec_tree, spawn_exec_compare); spawned_processes = 0; - assert(0 == uv_cond_init(&wait_children_cond)); - assert(0 == uv_mutex_init(&wait_children_mutex)); + fatal_assert(0 == uv_cond_init(&wait_children_cond)); + fatal_assert(0 == uv_mutex_init(&wait_children_mutex)); child_waited_list = NULL; error = uv_async_init(loop, &child_waited_async, child_waited_async_cb); if (error) { @@ -365,13 +365,13 @@ void spawn_server(void) prot_buffer_len = 0; error = uv_read_start((uv_stream_t *)&server_pipe, on_read_alloc, on_pipe_read); - assert(error == 0); + fatal_assert(error == 0); while (!server_shutdown) { uv_run(loop, UV_RUN_DEFAULT); } fprintf(stderr, "Shutting down spawn server loop complete.\n"); - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); exit(0); }