Class: Innodb::LogReader
- Inherits:
-
Object
- Object
- Innodb::LogReader
- Defined in:
- lib/innodb/log_reader.rb
Defined Under Namespace
Classes: ChecksumError, Context, EOFError
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Whether to checksum blocks.
Instance Method Summary collapse
-
#each_record(follow, wait = 0.5) ⇒ Object
Call the given block once for each record in the log until the end of the log (or a corrupted block) is reached.
-
#initialize(lsn, group) ⇒ LogReader
constructor
A new instance of LogReader.
-
#record ⇒ Object
Read a record.
-
#seek(lsn_no) ⇒ Object
Seek to record starting position.
-
#slice(position, length) ⇒ Object
Read a slice of log data (that is, log data used for records).
-
#tell ⇒ Object
Returns the current LSN starting position.
Constructor Details
Instance Attribute Details
#checksum ⇒ Object
Whether to checksum blocks. TODO: Hmm, nothing seems to actually set this.
21 22 23 |
# File 'lib/innodb/log_reader.rb', line 21 def checksum @checksum end |
Instance Method Details
#each_record(follow, wait = 0.5) ⇒ Object
Call the given block once for each record in the log until the end of the log (or a corrupted block) is reached. If the follow argument is true, retry.
54 55 56 57 58 |
# File 'lib/innodb/log_reader.rb', line 54 def each_record(follow, wait = 0.5) loop { yield record } rescue EOFError, ChecksumError sleep(wait) && retry if follow end |
#record ⇒ Object
Read a record.
43 44 45 46 47 48 49 |
# File 'lib/innodb/log_reader.rb', line 43 def record cursor = BufferCursor.new(self, 0) record = Innodb::LogRecord.new record.read(cursor) record.lsn = reposition(cursor.position) record end |
#seek(lsn_no) ⇒ Object
Seek to record starting position.
29 30 31 32 33 34 35 |
# File 'lib/innodb/log_reader.rb', line 29 def seek(lsn_no) check_lsn_no(lsn_no) @context.buffer = String.new @context.buffer_lsn.reposition(lsn_no, @group) @context.record_lsn = @context.buffer_lsn.dup self end |
#slice(position, length) ⇒ Object
Read a slice of log data (that is, log data used for records).
61 62 63 64 65 66 67 68 |
# File 'lib/innodb/log_reader.rb', line 61 def slice(position, length) buffer = @context.buffer length = position + length preload(length) if length > buffer.size buffer.slice(position, length - position) end |
#tell ⇒ Object
Returns the current LSN starting position.
38 39 40 |
# File 'lib/innodb/log_reader.rb', line 38 def tell @context.record_lsn.no end |