Skip to content

Commit

Permalink
Use DirectDispatcher for logging (#619)
Browse files Browse the repository at this point in the history
Use DirectDispatcher for logging and adds more logging to startup procedure. 

---------

Co-authored-by: Carl Hörberg <carl@84codes.com>
  • Loading branch information
viktorerlingsson and carlhoerberg authored Jan 10, 2024
1 parent d40cdb3 commit 8100a99
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Build binaries and container images using Crystal 1.11.0
- Don't allow clients open an already open channel
- Use DirectDispatcher for logging and add more logging to startup procedure [#619](https://github.com/cloudamqp/lavinmq/pull/619)

### Added

Expand Down
4 changes: 2 additions & 2 deletions src/lavinmq/launcher.cr
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ module LavinMQ
log_file = (path = @config.log_file) ? File.open(path, "a") : STDOUT
broadcast_backend = ::Log::BroadcastBackend.new
backend = if ENV.has_key?("JOURNAL_STREAM")
::Log::IOBackend.new(io: log_file, formatter: JournalLogFormat)
::Log::IOBackend.new(io: log_file, formatter: JournalLogFormat, dispatcher: ::Log::DirectDispatcher)
else
::Log::IOBackend.new(io: log_file, formatter: StdoutLogFormat)
::Log::IOBackend.new(io: log_file, formatter: StdoutLogFormat, dispatcher: ::Log::DirectDispatcher)
end

broadcast_backend.append(backend, @config.log_level)
Expand Down
9 changes: 9 additions & 0 deletions src/lavinmq/queue/message_store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ module LavinMQ
end

private def load_deleted_from_disk
count = 0u32
ack_files = 0u32
Dir.each(@data_dir) do |f|
ack_files += 1 if f.starts_with? "acks."
end

Dir.each_child(@data_dir) do |child|
next unless child.starts_with? "acks."
seg = child[5, 10].to_u32
Expand All @@ -282,6 +288,7 @@ module LavinMQ
end
@replicator.try &.register_file(file)
end
Log.info { "Loading acks (#{count}/#{ack_files})" } if (count += 1) % 128 == 0
@deleted[seg] = acked.sort! unless acked.empty?
end
end
Expand Down Expand Up @@ -320,6 +327,7 @@ module LavinMQ

# Populate bytesize, size and segment_msg_count
private def load_stats_from_segments : Nil
counter = 0
@segments.each do |seg, mfile|
count = 0u32
loop do
Expand All @@ -337,6 +345,7 @@ module LavinMQ
end
mfile.pos = 4
mfile.unmap # will be mmap on demand
Log.info { "Loading stats (#{counter}/#{@segments.size})" } if (counter += 1) % 128 == 0
@segment_msg_count[seg] = count
end
end
Expand Down

0 comments on commit 8100a99

Please sign in to comment.