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.
18 19 20 21 22 23 24 |
# File 'lib/innodb/log.rb', line 18 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.
26 27 28 |
# File 'lib/innodb/log.rb', line 26 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.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/innodb/log.rb', line 30 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.
43 44 45 46 47 48 |
# File 'lib/innodb/log.rb', line 43 def each_block (0...@blocks).each do |block_number| current_block = block(block_number) yield block_number, current_block if current_block end end |