lib/prometheus/client/mmaped_dict.rb in prometheus-client-mmap-0.7.0.beta27 vs lib/prometheus/client/mmaped_dict.rb in prometheus-client-mmap-0.7.0.beta28
- old
+ new
@@ -28,12 +28,10 @@
@mutex = Mutex.new
@m = m
# @m.mlock # TODO: Ensure memory is locked to RAM
- @used = @m.used
-
@positions = {}
read_all_positions.each do |key, pos|
@positions[key] = pos
end
rescue StandardError => e
@@ -64,26 +62,24 @@
Prometheus::Client.logger.warn("munmap raised error #{e}")
end
private
+ def ok(key)
+ @m.add_entry(@positions, key, 0.0)
+ rescue RuntimeError => e
+ raise e if e.message.match /.*ugh.*/
+ nil
+ end
+
def init_value(key)
- @mutex.synchronize do
- return if @positions.key?(key)
+ until ok(key)
+ filepath = @m.filepath
+ size = @m.size
+ @m.close
- until @m.try_add_entry(key, 0.0) do
- filepath = @m.filepath
- size = @m.size
- @m.close
-
- File.truncate(filepath, size * 2)
- @m = Helper::MmapedFile.open(filepath)
- end
-
- # Update how much space we've used.
- @used = @m.used
-
- @positions[key] = @used - 8
+ File.truncate(filepath, size * 2)
+ @m = Helper::MmapedFile.open(filepath)
end
end
# Yield (key, pos). No locking is performed.
def read_all_positions