Class: Innodb::LSN

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

Overview

A Log Sequence Number and its byte offset into the log group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lsn, offset) ⇒ LSN

Initialize coordinates.



12
13
14
15
# File 'lib/innodb/lsn.rb', line 12

def initialize(lsn, offset)
  @lsn_no = lsn
  @lsn_offset = offset
end

Instance Attribute Details

#lsn_noObject (readonly) Also known as: no

The Log Sequence Number.



6
7
8
# File 'lib/innodb/lsn.rb', line 6

def lsn_no
  @lsn_no
end

Instance Method Details

#advance(count_lsn_no, group) ⇒ Object

Advance by a given LSN amount.



24
25
26
27
# File 'lib/innodb/lsn.rb', line 24

def advance(count_lsn_no, group)
  new_lsn_no = @lsn_no + count_lsn_no
  reposition(new_lsn_no, group)
end

#delta(length) ⇒ Object

Returns the LSN delta for the given amount of data.



35
36
37
38
39
40
# File 'lib/innodb/lsn.rb', line 35

def delta(length)
  fragment = (@lsn_no % LOG_BLOCK_SIZE) - LOG_BLOCK_HEADER_SIZE
  raise "Invalid fragment #{fragment} for LSN #{@lsn_no}" unless
    fragment.between?(0, LOG_BLOCK_DATA_SIZE - 1)
  length + (fragment + length) / LOG_BLOCK_DATA_SIZE * LOG_BLOCK_FRAME_SIZE
end

#location(group) ⇒ Object

Returns the location coordinates of this LSN.



30
31
32
# File 'lib/innodb/lsn.rb', line 30

def location(group)
  location_of(@lsn_offset, group)
end

#record?(group) ⇒ Boolean

Whether LSN might point to log record data.

Returns:

  • (Boolean)


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

def record?(group)
  data_offset?(@lsn_offset, group)
end

#reposition(new_lsn_no, group) ⇒ Object

Place LSN in a new position.



18
19
20
21
# File 'lib/innodb/lsn.rb', line 18

def reposition(new_lsn_no, group)
  new_offset = offset_of(@lsn_no, @lsn_offset, new_lsn_no, group)
  @lsn_no, @lsn_offset = [new_lsn_no, new_offset]
end