Class: Innodb::LogReader

Inherits:
Object
  • Object
show all
Defined in:
lib/innodb/log_reader.rb

Defined Under Namespace

Classes: ChecksumError, Context, EOFError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lsn, group) ⇒ LogReader

Returns a new instance of LogReader.



23
24
25
26
# File 'lib/innodb/log_reader.rb', line 23

def initialize(lsn, group)
  @group = group
  @context = Context.new(buffer: String.new, buffer_lsn: lsn.dup, record_lsn: lsn.dup)
end

Instance Attribute Details

#checksumObject

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

#recordObject

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

#tellObject

Returns the current LSN starting position.



38
39
40
# File 'lib/innodb/log_reader.rb', line 38

def tell
  @context.record_lsn.no
end