Class: Garcon::Stash::Journal Private
- Defined in:
- lib/garcon/stash/journal.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Stash::Io handles background io, compaction and is the arbiter of multiprocess safety.
Instance Attribute Summary collapse
- #file ⇒ Object readonly private
- #size ⇒ Object readonly private
Instance Method Summary collapse
-
#bytesize ⇒ Object
private
Return byte size of journal.
-
#clear ⇒ Object
private
Clear the database log and yield.
-
#close ⇒ Object
private
Clear the queue and close the file handler.
-
#closed? ⇒ Boolean
private
Is the journal closed?.
-
#compact ⇒ Object
private
Compact the logfile to represent the in-memory state.
-
#initialize(file, format, serializer, &block) ⇒ Journal
constructor
private
A new instance of Journal.
-
#load ⇒ Object
private
Load new journal entries.
-
#lock ⇒ Object
private
Lock the logfile across thread and process boundaries.
Methods inherited from Queue
Constructor Details
#initialize(file, format, serializer, &block) ⇒ Journal
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Journal.
29 30 31 32 33 34 35 36 |
# 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 |
Instance Attribute Details
#file ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/garcon/stash/journal.rb', line 27 def file @file end |
#size ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/garcon/stash/journal.rb', line 27 def size @size end |
Instance Method Details
#bytesize ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return byte size of journal
107 108 109 |
# File 'lib/garcon/stash/journal.rb', line 107 def bytesize @fd.stat.size end |
#clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Clear the database log and yield
74 75 76 77 78 79 80 81 82 83 84 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Clear the queue and close the file handler
46 47 48 49 50 51 |
# File 'lib/garcon/stash/journal.rb', line 46 def close self << nil @worker.join @fd.close super end |
#closed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is the journal closed?
40 41 42 |
# File 'lib/garcon/stash/journal.rb', line 40 def closed? @fd.closed? end |
#compact ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compact the logfile to represent the in-memory state
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load new journal entries
55 56 57 58 |
# File 'lib/garcon/stash/journal.rb', line 55 def load flush replay end |
#lock ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Lock the logfile across thread and process boundaries
62 63 64 65 66 67 68 69 70 |
# File 'lib/garcon/stash/journal.rb', line 62 def lock flush with_flock(File::LOCK_EX) do replay result = yield flush result end end |