class Garcon::Stash::Journal
Stash::Io handles background io, compaction and is the arbiter of multiprocess safety.
@api private
Attributes
file[R]
size[R]
Public Class Methods
new(file, format, serializer, &block)
click to toggle source
Calls superclass method
# File lib/garcon/stash/journal.rb, line 29 def initialize(file, format, serializer, &block) super() @file, @format, @serializer, @emit = file, format, serializer, block open @worker = Thread.new(&method(:worker)) @worker.priority = -1 load end
Public Instance Methods
bytesize()
click to toggle source
Return byte size of journal
# File lib/garcon/stash/journal.rb, line 107 def bytesize @fd.stat.size end
clear()
click to toggle source
Clear the database log and yield
# File lib/garcon/stash/journal.rb, line 74 def clear flush with_tmpfile do |path, file| file.write(@format.header) file.close with_flock(File::LOCK_EX) do File.rename(path, @file) end end open end
close()
click to toggle source
Clear the queue and close the file handler
Calls superclass method
# File lib/garcon/stash/journal.rb, line 46 def close self << nil @worker.join @fd.close super end
closed?()
click to toggle source
Is the journal closed?
# File lib/garcon/stash/journal.rb, line 40 def closed? @fd.closed? end
compact() { || ... }
click to toggle source
Compact the logfile to represent the in-memory state
# File lib/garcon/stash/journal.rb, line 88 def compact load with_tmpfile do |path, file| # Compactified database has the same size -> return return self if @pos == file.write(dump(yield, @format.header)) with_flock(File::LOCK_EX) do if @pos != nil file.write(read) file.close File.rename(path, @file) end end end open replay end
load()
click to toggle source
Load new journal entries
# File lib/garcon/stash/journal.rb, line 55 def load flush replay end
lock() { || ... }
click to toggle source
Lock the logfile across thread and process boundaries
# File lib/garcon/stash/journal.rb, line 62 def lock flush with_flock(File::LOCK_EX) do replay result = yield flush result end end