Class: Innodb::UndoLog

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

Defined Under Namespace

Classes: Header, HeaderXid, UndoRecordCursor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, position) ⇒ UndoLog

Returns a new instance of UndoLog.



31
32
33
34
# File 'lib/innodb/undo_log.rb', line 31

def initialize(page, position)
  @page = page
  @position = position
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



28
29
30
# File 'lib/innodb/undo_log.rb', line 28

def page
  @page
end

#positionObject (readonly)

Returns the value of attribute position.



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

def position
  @position
end

Instance Method Details

#dumpObject



150
151
152
153
154
# File 'lib/innodb/undo_log.rb', line 150

def dump
  puts "header:"
  pp header
  puts
end

#first_undo_record_cursorObject



146
147
148
# File 'lib/innodb/undo_log.rb', line 146

def first_undo_record_cursor
  undo_record_cursor(header.log_start_offset)
end

#headerObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/innodb/undo_log.rb', line 44

def header
  @header ||= page.cursor(@position).name("header") do |c|
    header = Header.new(
      trx_id: c.name("trx_id") { c.read_uint64 },
      trx_no: c.name("trx_no") { c.read_uint64 },
      delete_mark_flag: c.name("delete_mark_flag") { (c.read_uint16 != 0) },
      log_start_offset: c.name("log_start_offset") { c.read_uint16 },
      xid_flag: c.name("xid_flag") { (c.read_uint8 != 0) },
      ddl_flag: c.name("ddl_flag") { (c.read_uint8 != 0) },
      ddl_table_id: c.name("ddl_table_id") { c.read_uint64 },
      next_log_offset: c.name("next_log_offset") { c.read_uint16 },
      prev_log_offset: c.name("prev_log_offset") { c.read_uint16 },
      history_list_node: c.name("history_list_node") { Innodb::List.get_node(c) }
    )

    if header.xid_flag
      header.xid = c.name("xid") do
        HeaderXid.new(
          format: c.name("format") { c.read_uint32 },
          trid_len: c.name("trid_len") { c.read_uint32 },
          bqual_len: c.name("bqual_len") { c.read_uint32 },
          data: c.name("data") { c.read_bytes(128) }
        )
      end
    end

    header
  end
end

#min_undo_recordObject



88
89
90
# File 'lib/innodb/undo_log.rb', line 88

def min_undo_record
  undo_record(header.log_start_offset)
end

#next_addressObject



78
79
80
# File 'lib/innodb/undo_log.rb', line 78

def next_address
  header.history_list_node.next
end

#prev_addressObject



74
75
76
# File 'lib/innodb/undo_log.rb', line 74

def prev_address
  header.history_list_node.prev
end

#size_headerObject



40
41
42
# File 'lib/innodb/undo_log.rb', line 40

def size_header
  8 + 8 + 2 + 2 + 1 + 1 + 8 + 2 + 2 + Innodb::List::NODE_SIZE + size_xa_header
end

#size_xa_headerObject



36
37
38
# File 'lib/innodb/undo_log.rb', line 36

def size_xa_header
  4 + 4 + 4 + 128
end

#undo_record(offset) ⇒ Object



82
83
84
85
86
# File 'lib/innodb/undo_log.rb', line 82

def undo_record(offset)
  new_undo_record = Innodb::UndoRecord.new(page, offset)
  new_undo_record.undo_log = self
  new_undo_record
end

#undo_record_cursor(offset, direction = :forward) ⇒ Object



142
143
144
# File 'lib/innodb/undo_log.rb', line 142

def undo_record_cursor(offset, direction = :forward)
  UndoRecordCursor.new(self, offset, direction)
end