Class: Innodb::Log
- Inherits:
-
Object
- Object
- Innodb::Log
- Defined in:
- lib/innodb/log.rb
Overview
An InnoDB transaction log file.
Constant Summary collapse
- HEADER_SIZE =
4 * Innodb::LogBlock::BLOCK_SIZE
- HEADER_START =
0- DATA_START =
HEADER_START + HEADER_SIZE
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
Instance Method Summary collapse
-
#block(block_number) ⇒ Object
Return a log block with a given block number as an InnoDB::LogBlock object.
-
#each_block ⇒ Object
Iterate through all log blocks, returning the block number and an InnoDB::LogBlock object for each block.
-
#initialize(file) ⇒ Log
constructor
Open a log file.
Constructor Details
#initialize(file) ⇒ Log
Open a log file.
21 22 23 24 25 26 27 |
# File 'lib/innodb/log.rb', line 21 def initialize(file) @name = file File.open(@name) do |log| @size = log.stat.size @blocks = ((@size - DATA_START) / Innodb::LogBlock::BLOCK_SIZE) end end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
29 30 31 |
# File 'lib/innodb/log.rb', line 29 def blocks @blocks end |
Instance Method Details
#block(block_number) ⇒ Object
Return a log block with a given block number as an InnoDB::LogBlock object. Blocks are numbered after the log file header, starting from 0.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/innodb/log.rb', line 33 def block(block_number) offset = DATA_START + (block_number.to_i * Innodb::LogBlock::BLOCK_SIZE) return nil unless offset < @size return nil unless (offset + Innodb::LogBlock::BLOCK_SIZE) <= @size File.open(@name) do |log| log.seek(offset) block_data = log.read(Innodb::LogBlock::BLOCK_SIZE) Innodb::LogBlock.new(block_data) end end |
#each_block ⇒ Object
Iterate through all log blocks, returning the block number and an InnoDB::LogBlock object for each block.
46 47 48 49 50 51 |
# File 'lib/innodb/log.rb', line 46 def each_block (0...@blocks).each do |block_number| current_block = block(block_number) yield block_number, current_block if current_block end end |