Class: Daybreak::Journal Private
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.
Daybreak::Journal 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.
8 9 10 11 12 13 14 15 |
# File 'lib/daybreak/journal.rb', line 8 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.
6 7 8 |
# File 'lib/daybreak/journal.rb', line 6 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.
6 7 8 |
# File 'lib/daybreak/journal.rb', line 6 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
85 86 87 |
# File 'lib/daybreak/journal.rb', line 85 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
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/daybreak/journal.rb', line 51 def clear flush with_tmpfile do |path, file| file.write(@format.header) file.close # Clear replaces the database file like a compactification does 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
23 24 25 26 27 28 |
# File 'lib/daybreak/journal.rb', line 23 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?
18 19 20 |
# File 'lib/daybreak/journal.rb', line 18 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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/daybreak/journal.rb', line 65 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 # Database was replaced (cleared or compactified) in the meantime if @pos != nil # Append changed journal records if the database changed during compactification 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
31 32 33 34 |
# File 'lib/daybreak/journal.rb', line 31 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
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/daybreak/journal.rb', line 37 def lock # Flush everything to start with a clean state # and to protect the @locked variable flush with_flock(File::LOCK_EX) do replay result = yield flush result end end |