From a56c0b55d2ab33a8be064f6f1eb2dd899c234203 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Tue, 3 Dec 2024 23:06:07 +0100 Subject: [PATCH] logreader: drop log_reader_set_immediate_check() This was to force the LogReader instance to immediately start reading once at startup. This is being replaced by poll-fd-events reporting readability if we are at the middle of the file and also by LogProto if we have buffered data. Signed-off-by: Balazs Scheidler --- lib/logreader.c | 19 ------------------- lib/logreader.h | 3 +-- modules/affile/file-reader.c | 23 ++++------------------- 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/lib/logreader.c b/lib/logreader.c index f59a28c07..8b558f8bf 100644 --- a/lib/logreader.c +++ b/lib/logreader.c @@ -55,14 +55,6 @@ log_reader_set_local_addr(LogReader *s, GSockAddr *local_addr) self->local_addr = g_sockaddr_ref(local_addr); } -void -log_reader_set_immediate_check(LogReader *s) -{ - LogReader *self = (LogReader *) s; - - self->immediate_check = TRUE; -} - void log_reader_set_options(LogReader *s, LogPipe *control, LogReaderOptions *options, const gchar *stats_id, StatsClusterKeyBuilder *kb) @@ -160,7 +152,6 @@ log_reader_disable_watches(LogReader *self) static void log_reader_suspend_until_awoken(LogReader *self) { - self->immediate_check = FALSE; log_reader_disable_watches(self); self->suspended = TRUE; } @@ -168,7 +159,6 @@ log_reader_suspend_until_awoken(LogReader *self) static void log_reader_force_check_in_next_poll(LogReader *self) { - self->immediate_check = FALSE; log_reader_disable_watches(self); self->suspended = FALSE; @@ -326,12 +316,6 @@ log_reader_update_watches(LogReader *self) iv_timer_register(&self->idle_timer); } - if (self->immediate_check) - { - log_reader_force_check_in_next_poll(self); - return; - } - switch (prepare_action) { case LPPA_POLL_IO: @@ -574,8 +558,6 @@ log_reader_fetch_log(LogReader *self) } log_transport_aux_data_destroy(aux); - if (msg_count == self->options->fetch_limit) - self->immediate_check = TRUE; return 0; } @@ -785,7 +767,6 @@ log_reader_new(GlobalConfig *cfg) self->super.wakeup = log_reader_wakeup; self->super.schedule_dynamic_window_realloc = _schedule_dynamic_window_realloc; self->super.metrics.raw_bytes_enabled = TRUE; - self->immediate_check = FALSE; self->handshake_in_progress = TRUE; log_reader_init_watches(self); g_mutex_init(&self->pending_close_lock); diff --git a/lib/logreader.h b/lib/logreader.h index fa0ed3422..563ffdcaa 100644 --- a/lib/logreader.h +++ b/lib/logreader.h @@ -62,7 +62,7 @@ struct _LogReader { LogSource super; LogProtoServer *proto; - gboolean immediate_check, handshake_in_progress; + gboolean handshake_in_progress; LogPipe *control; LogReaderOptions *options; PollEvents *poll_events; @@ -99,7 +99,6 @@ void log_reader_set_follow_filename(LogReader *self, const gchar *follow_filenam void log_reader_set_name(LogReader *s, const gchar *name); void log_reader_set_peer_addr(LogReader *s, GSockAddr *peer_addr); void log_reader_set_local_addr(LogReader *s, GSockAddr *local_addr); -void log_reader_set_immediate_check(LogReader *s); void log_reader_disable_bookmark_saving(LogReader *s); void log_reader_open(LogReader *s, LogProtoServer *proto, PollEvents *poll_events); void log_reader_close_proto(LogReader *s); diff --git a/modules/affile/file-reader.c b/modules/affile/file-reader.c index 7439d6dd5..ab9086773 100644 --- a/modules/affile/file-reader.c +++ b/modules/affile/file-reader.c @@ -155,7 +155,7 @@ _deinit_sd_logreader(FileReader *self) } static void -_setup_logreader(LogPipe *s, PollEvents *poll_events, LogProtoServer *proto, gboolean check_immediately) +_setup_logreader(LogPipe *s, PollEvents *poll_events, LogProtoServer *proto) { FileReader *self = (FileReader *) s; @@ -172,25 +172,12 @@ _setup_logreader(LogPipe *s, PollEvents *poll_events, LogProtoServer *proto, gbo self->owner->super.id, kb); - if (check_immediately) - log_reader_set_immediate_check(self->reader); - /* NOTE: if the file could not be opened, we ignore the last * remembered file position, if the file is created in the future * we're going to read from the start. */ log_pipe_append((LogPipe *) self->reader, s); } -static gboolean -_is_immediate_check_needed(gboolean file_opened, gboolean open_deferred) -{ - if (file_opened) - return TRUE; - else if (open_deferred) - return FALSE; - return FALSE; -} - static gboolean _reader_open_file(LogPipe *s, gboolean recover_state) { @@ -214,7 +201,6 @@ _reader_open_file(LogPipe *s, gboolean recover_state) { LogProtoServer *proto; PollEvents *poll_events; - gboolean check_immediately; poll_events = _construct_poll_events(self, fd); if (!poll_events) @@ -224,8 +210,9 @@ _reader_open_file(LogPipe *s, gboolean recover_state) } proto = _construct_proto(self, fd); - check_immediately = _is_immediate_check_needed(file_opened, open_deferred); - _setup_logreader(s, poll_events, proto, check_immediately); + _setup_logreader(s, poll_events, proto); + if (recover_state) + _recover_state(s, cfg, proto); if (!log_pipe_init((LogPipe *) self->reader)) { msg_error("Error initializing log_reader, closing fd", @@ -235,8 +222,6 @@ _reader_open_file(LogPipe *s, gboolean recover_state) close(fd); return FALSE; } - if (recover_state) - _recover_state(s, cfg, proto); } else {