Skip to content

Commit

Permalink
remove instance variables
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorerlingsson committed Jun 19, 2024
1 parent 9d08d6f commit 6c66ad8
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/lavinmq/queue/stream_queue_message_store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ module LavinMQ
@segment_last_ts = Hash(UInt32, Int64).new(0i64) # used for max-age
@consumer_offset_positions = Hash(String, Int64).new # used for consumer offsets
@consumer_offsets : MFile
@consumer_offset_path : String
@consumer_offset_capacity = 32_768

def initialize(@data_dir : String, @replicator : Replication::Replicator?)
super
@last_offset = get_last_offset
@consumer_offset_path = File.join(@data_dir, "consumer_offsets")
@consumer_offsets = MFile.new(@consumer_offset_path, @consumer_offset_capacity)
@consumer_offsets = MFile.new(File.join(@data_dir, "consumer_offsets"), 32 * 1024)
@consumer_offset_positions = restore_consumer_offset_positions
drop_overflow
end
Expand Down Expand Up @@ -151,8 +148,7 @@ module LavinMQ

def expand_consumer_offset_file
pos = @consumer_offsets.size
@consumer_offset_capacity += 32_768
@consumer_offsets = MFile.new(@consumer_offset_path, @consumer_offset_capacity)
@consumer_offsets = MFile.new(@consumer_offsets.path, @consumer_offsets.capacity + 32 * 1024)
@consumer_offsets.resize(pos)
end

Expand All @@ -177,9 +173,9 @@ module LavinMQ

def replace_offsets_file(&)
old_consumer_offsets = @consumer_offsets
@consumer_offsets = MFile.new("#{@consumer_offset_path}.tmp", @consumer_offset_capacity)
@consumer_offsets = MFile.new("#{@consumer_offsets.path}.tmp", 32 * 1024)
yield # fill the new file with correct data in this block
@consumer_offsets.rename(@consumer_offset_path)
@consumer_offsets.rename(@consumer_offsets.path.sub(".tmp",""))
old_consumer_offsets.close(truncate_to_size: false)
end

Expand Down

0 comments on commit 6c66ad8

Please sign in to comment.