static void _prepare_eof_test(LogQueueDiskReliable *dq, LogMessage **msg1, LogMessage **msg2) { LogPathOptions local_options = LOG_PATH_OPTIONS_INIT; gint64 start_pos = TEST_DISKQ_SIZE; *msg1 = log_msg_new_mark(); *msg2 = log_msg_new_mark(); (*msg1)->ack_func = _dummy_ack; log_msg_add_ack(*msg1, &local_options); (*msg2)->ack_func = _dummy_ack; log_msg_add_ack(*msg2, &local_options); dq->super.qdisk->hdr->write_head = start_pos; dq->super.qdisk->hdr->read_head = QDISK_RESERVED_SPACE + mark_message_serialized_size + 1; dq->super.qdisk->hdr->backlog_head = dq->super.qdisk->hdr->read_head; log_queue_push_tail(&dq->super.super, *msg1, &local_options); log_queue_push_tail(&dq->super.super, *msg2, &local_options); assert_gint(dq->qreliable->length, NUMBER_MESSAGES_IN_QUEUE(2), ASSERTION_ERROR("Messages aren't in qreliable")); assert_gint64(dq->super.qdisk->hdr->write_head, QDISK_RESERVED_SPACE + mark_message_serialized_size, ASSERTION_ERROR("Bad write head")); assert_gint(num_of_ack, 0, ASSERTION_ERROR("Messages are acked")); dq->super.qdisk->hdr->read_head = start_pos; dq->super.qdisk->hdr->backlog_head = dq->super.qdisk->hdr->read_head; }
/* * The method make the following situation * the backlog contains 6 messages * the qbacklog contains 3 messages, * but messages in qbacklog are the end of the backlog */ void _prepare_rewind_backlog_test(LogQueueDiskReliable *dq, gint64 *start_pos) { gint i; for (i = 0; i < 8; i++) { LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; LogMessage *mark_message; mark_message = log_msg_new_mark(); mark_message->ack_func = _dummy_ack; log_queue_push_tail(&dq->super.super, mark_message, &path_options); } /* Lets read the messages and leave them in the backlog */ for (i = 0; i < 8; i++) { LogMessage *msg; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; msg = log_queue_pop_head(&dq->super.super, &path_options); log_msg_unref(msg); } /* Ack the messages which are not in the qbacklog */ log_queue_ack_backlog(&dq->super.super, 5); assert_gint(dq->qbacklog->length, NUMBER_MESSAGES_IN_QUEUE(3), ASSERTION_ERROR("Incorrect number of items in the qbacklog")); *start_pos = dq->super.qdisk->hdr->read_head; /* Now write 3 more messages and read them from buffer * the number of messages in the qbacklog should not be changed * The backlog should contain 6 messages * from these 6 messages 3 messages are cached in the qbacklog * No readable messages are in the queue */ for (i = 0; i < 3; i++) { LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; LogMessage *mark_message; mark_message = log_msg_new_mark(); mark_message->ack_func = _dummy_ack; log_queue_push_tail(&dq->super.super, mark_message, &path_options); mark_message = log_queue_pop_head(&dq->super.super, &path_options); assert_gint(dq->qreliable->length, 0, ASSERTION_ERROR("Incorrect number of items in the qreliable")); assert_gint(dq->qbacklog->length, NUMBER_MESSAGES_IN_QUEUE(3), ASSERTION_ERROR("Incorrect number of items in the qbacklog")); log_msg_unref(mark_message); } assert_gint(dq->super.qdisk->hdr->backlog_len, 6, ASSERTION_ERROR("Incorrect number of messages in the backlog")); assert_gint(dq->super.qdisk->hdr->length, 0, ASSERTION_ERROR("Reliable diskq isn't empty")); }
static void afinter_source_mark(gpointer s) { AFInterSource *self = (AFInterSource *) s; LogMessage *msg; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; struct timespec nmt; main_loop_assert_main_thread(); g_static_mutex_lock(&internal_mark_target_lock); nmt = next_mark_target; g_static_mutex_unlock(&internal_mark_target_lock); if (log_source_free_to_send(&self->super) && nmt.tv_sec <= self->mark_timer.expires.tv_sec) { /* the internal_mark_target has not been overwritten by an incoming message in afinter_postpone_mark (there was no msg in the meantime) -> the mark msg can be sent */ msg = log_msg_new_mark(); path_options.ack_needed = FALSE; log_pipe_queue(&self->super.super, msg, &path_options); /* the next_mark_target will be increased in afinter_postpone_mark */ } afinter_source_update_watches(self); }
static void test_rewind_over_eof(LogQueueDiskReliable *dq) { LogMessage *msg3 = log_msg_new_mark(); LogMessage *read_message3; LogPathOptions local_options = LOG_PATH_OPTIONS_INIT; msg3->ack_func = _dummy_ack; log_queue_push_tail(&dq->super.super, msg3, &local_options); gint64 previous_read_head = dq->super.qdisk->hdr->read_head; read_message3 = log_queue_pop_head(&dq->super.super, &local_options); assert_true(read_message3 != NULL, ASSERTION_ERROR("Can't read message from queue")); assert_gint(dq->super.qdisk->hdr->read_head, dq->super.qdisk->hdr->write_head, ASSERTION_ERROR("Read head in bad position")); assert_true(msg3 == read_message3, ASSERTION_ERROR("Message 3 isn't read from qreliable")); log_msg_unref(read_message3); log_queue_rewind_backlog(&dq->super.super, 1); assert_gint(dq->super.qdisk->hdr->read_head, previous_read_head, ASSERTION_ERROR("Read head is corrupted")); read_message3 = log_queue_pop_head(&dq->super.super, &local_options); assert_true(read_message3 != NULL, ASSERTION_ERROR("Can't read message from queue")); assert_gint(dq->super.qdisk->hdr->read_head, dq->super.qdisk->hdr->write_head, ASSERTION_ERROR("Read head in bad position")); assert_true(msg3 == read_message3, ASSERTION_ERROR("Message 3 isn't read from qreliable")); log_msg_drop(msg3, &local_options, AT_PROCESSED); }
static void set_mark_message_serialized_size() { LogMessage *mark_message = log_msg_new_mark(); mark_message_serialized_size = get_serialized_message_size(mark_message); log_msg_unref(mark_message); }
/* this is the callback function that gets called when the MARK timeout * elapsed. It runs in the main thread. */ static void log_writer_mark_timeout(void *cookie) { LogWriter *self = (LogWriter *)cookie; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; const gchar *hostname; gsize hostname_len; LogMessage *msg; main_loop_assert_main_thread(); msg = log_msg_new_mark(); /* timeout: there was no new message on the writer or it is in periodical mode */ hostname = resolve_sockaddr_to_hostname(&hostname_len, msg->saddr, &self->options->host_resolve_options); log_msg_set_value(msg, LM_V_HOST, hostname, hostname_len); /* set the current time in the message stamp */ msg->timestamps[LM_TS_STAMP] = msg->timestamps[LM_TS_RECVD]; if (!log_writer_is_msg_suppressed(self, msg)) { log_queue_push_tail(self->queue, msg, &path_options); stats_counter_inc(self->processed_messages); } else { log_msg_drop(msg, &path_options); } /* we need to issue another MARK in all mark-mode cases that already * triggered this callback (dst-idle, host-idle, periodical). The * original setup of the timer is at a different location: * - log_writer_queue() for "*-idle" modes * - log_writer_init() for periodical mode */ log_writer_postpone_mark_timer(self); }