Class: Innodb::LogGroup

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

Overview

Group of InnoDB logs files that make up the redo log.

Instance Method Summary collapse

Constructor Details

#initialize(log_files) ⇒ LogGroup

Initialize group given a set of sorted log files.



7
8
9
10
11
# File 'lib/innodb/log_group.rb', line 7

def initialize(log_files)
  @logs = log_files.map { |fn| Innodb::Log.new(fn) }
  sizes = @logs.map { |log| log.size }
  raise "Log file sizes do not match" unless sizes.uniq.size == 1
end

Instance Method Details

#capacityObject

The log group capacity (in bytes).



58
59
60
# File 'lib/innodb/log_group.rb', line 58

def capacity
  @logs.first.capacity * @logs.count
end

#each_blockObject

Iterate through all blocks.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/innodb/log_group.rb', line 25

def each_block
  unless block_given?
    return enum_for(:each_block)
  end

  each_log do |log|
    log.each_block do |block_index, block|
      yield block_index, block
    end
  end
end

#each_logObject

Iterate through all logs.



14
15
16
17
18
19
20
21
22
# File 'lib/innodb/log_group.rb', line 14

def each_log
  unless block_given?
    return enum_for(:each_log)
  end

  @logs.each do |log|
    yield log
  end
end

#log(log_no) ⇒ Object

Returns the log at the given position in the log group.



43
44
45
# File 'lib/innodb/log_group.rb', line 43

def log(log_no)
  @logs.at(log_no)
end

#log_sizeObject

The size in byes of each and every log in the group.



48
49
50
# File 'lib/innodb/log_group.rb', line 48

def log_size
  @logs.first.size
end

#logsObject

The number of log files in the group.



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

def logs
  @logs.count
end

#max_checkpoint_lsnObject

Returns the LSN coordinates of the most recent (highest) checkpoint.



68
69
70
71
# File 'lib/innodb/log_group.rb', line 68

def max_checkpoint_lsn
  checkpoint = @logs.first.checkpoint.max_by{|f,v| v[:number]}.last
  checkpoint.values_at(:lsn, :lsn_offset)
end

#reader(lsn_coord = start_lsn) ⇒ Object

Returns a LogReader using the given LSN reference coordinates.



74
75
76
77
78
# File 'lib/innodb/log_group.rb', line 74

def reader(lsn_coord = start_lsn)
  lsn_no, lsn_offset = lsn_coord
  lsn = Innodb::LSN.new(lsn_no, lsn_offset)
  Innodb::LogReader.new(lsn, self)
end

#record(lsn_no) ⇒ Object

Parse and return a record at a given LSN.



81
82
83
# File 'lib/innodb/log_group.rb', line 81

def record(lsn_no)
  reader.seek(lsn_no).record
end

#sizeObject

The size of the log group (in bytes)



53
54
55
# File 'lib/innodb/log_group.rb', line 53

def size
  @logs.first.size * @logs.count
end

#start_lsnObject

Returns the LSN coordinates of the data at the start of the log group.



63
64
65
# File 'lib/innodb/log_group.rb', line 63

def start_lsn
  [@logs.first.header[:start_lsn], Innodb::Log::LOG_HEADER_SIZE]
end