lib/prometheus/client/mmaped_dict.rb in prometheus-client-mmap-0.7.0.beta9 vs lib/prometheus/client/mmaped_dict.rb in prometheus-client-mmap-0.7.0.beta10

- old
+ new

@@ -1,5 +1,7 @@ +require 'prometheus/client' + module Prometheus module Client class ParsingError < StandardError; end # A dict of doubles, backed by an mmapped file. @@ -16,11 +18,13 @@ attr_reader :m, :capacity, :used, :positions def initialize(filename) @mutex = Mutex.new @f = File.open(filename, 'a+b') - process_file_wrappe_error + process_file + rescue StandardError => e + raise ParsingError.new("exception #{e} while processing metrics file #{@f.path}") end # Yield (key, value, pos). No locking is performed. def all_values read_all_values.map { |k, v, p| [k, v] } @@ -47,23 +51,20 @@ def close() @m.munmap @f.close end - private - - def process_file_wrappe_error - process_file - rescue StandardError => e - raise ParsingError.new("exception #{e} while processing metrics file #{@f.path}") + def initial_mmap_file_size + Prometheus::Client.configuration.initial_mmap_file_size end + private + def process_file if @f.size < MINIMUM_SIZE @f.truncate(initial_mmap_file_size) end - @f.truncate(initial_mmap_file_size) @capacity = @f.size @m = Mmap.new(@f.path, 'rw', Mmap::MAP_SHARED) # @m.mlock # TODO: Why does this raise an error? @@ -75,13 +76,9 @@ else read_all_values.each do |key, _, pos| @positions[key] = pos end end - end - - def initial_mmap_file_size - Prometheus::Client.configuration.initial_mmap_file_size end # Initialize a value. Lock must be held by caller. def init_value(key) # Pad to be 8-byte aligned. \ No newline at end of file