Class: Innodb::LogGroup

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

Instance Method Summary collapse

Constructor Details

#initialize(log_files) ⇒ LogGroup

Initialize group given a set of sorted log files.



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

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

Instance Method Details

#capacityObject

The log group capacity (in bytes).



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

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

#each_block(&block) ⇒ Object

Iterate through all blocks.



20
21
22
23
24
25
26
# File 'lib/innodb/log_group.rb', line 20

def each_block(&block)
  return enum_for(:each_block) unless block_given?

  each_log do |log|
    log.each_block(&block)
  end
end

#each_log(&block) ⇒ Object

Iterate through all logs.



13
14
15
16
17
# File 'lib/innodb/log_group.rb', line 13

def each_log(&block)
  return enum_for(:each_log) unless block_given?

  @logs.each(&block)
end

#log(log_no) ⇒ Object

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



34
35
36
# File 'lib/innodb/log_group.rb', line 34

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

#log_sizeObject

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



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

def log_size
  @logs.first.size
end

#logsObject

The number of log files in the group.



29
30
31
# File 'lib/innodb/log_group.rb', line 29

def logs
  @logs.count
end

#max_checkpoint_lsnObject

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



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

def max_checkpoint_lsn
  @logs.first.checkpoint.max_by(&:number).to_h.values_at(:lsn, :lsn_offset)
end

#reader(lsn_coordinates = start_lsn) ⇒ Object

Returns a LogReader using the given LSN reference coordinates.



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

def reader(lsn_coordinates = start_lsn)
  Innodb::LogReader.new(Innodb::LSN.new(*lsn_coordinates), self)
end

#record(lsn_no) ⇒ Object

Parse and return a record at a given LSN.



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

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

#sizeObject

The size of the log group (in bytes)



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

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

#start_lsnObject

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



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

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