Class: Igniter::Store::ChangefeedBuffer::DiagnosticRing

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/store/changefeed_buffer.rb

Overview

Bounded ring buffer for structured diagnostic entries. All push/snapshot operations are thread-safe. Oldest entries are evicted when max_size is exceeded; dropped_diagnostics_total counts evictions.

Instance Method Summary collapse

Constructor Details

#initialize(max_size) ⇒ DiagnosticRing

Returns a new instance of DiagnosticRing.



134
135
136
137
138
139
140
# File 'lib/igniter/store/changefeed_buffer.rb', line 134

def initialize(max_size)
  @max_size  = max_size
  @entries   = []
  @mu        = Mutex.new
  @total     = 0
  @dropped   = 0
end

Instance Method Details

#push(entry) ⇒ Object



142
143
144
145
146
147
148
149
150
151
# File 'lib/igniter/store/changefeed_buffer.rb', line 142

def push(entry)
  @mu.synchronize do
    @total += 1
    if @entries.size >= @max_size
      @entries.shift
      @dropped += 1
    end
    @entries << entry
  end
end

#snapshotObject



153
154
155
156
157
158
159
160
161
# File 'lib/igniter/store/changefeed_buffer.rb', line 153

def snapshot
  @mu.synchronize do
    {
      recent:                    @entries.dup,
      recent_count:              @total,
      dropped_diagnostics_total: @dropped
    }
  end
end