Class: Innodb::HistoryList::UndoRecordCursor

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

Instance Method Summary collapse

Constructor Details

#initialize(history, undo_record, direction = :forward) ⇒ UndoRecordCursor

Returns a new instance of UndoRecordCursor.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/innodb/history_list.rb', line 15

def initialize(history, undo_record, direction = :forward)
  @history = history
  @undo_record = undo_record

  # rubocop:disable Style/IfUnlessModifier
  case undo_record
  when :min
    @undo_log_cursor = history.list.list_cursor(:min, direction)
    if (@undo_log = @undo_log_cursor.node)
      @undo_record_cursor = @undo_log.undo_record_cursor(:min, direction)
    end
  when :max
    @undo_log_cursor = history.list.list_cursor(:max, direction)
    if (@undo_log = @undo_log_cursor.node)
      @undo_record_cursor = @undo_log.undo_record_cursor(:max, direction)
    end
  else
    raise "Not implemented"
  end
  # rubocop:enable Style/IfUnlessModifier
end

Instance Method Details

#each_undo_recordObject



83
84
85
86
87
88
89
# File 'lib/innodb/history_list.rb', line 83

def each_undo_record
  return enum_for(:each_undo_record) unless block_given?

  while (rec = undo_record)
    yield rec
  end
end

#move_cursor(page, undo_record) ⇒ Object



52
53
54
55
# File 'lib/innodb/history_list.rb', line 52

def move_cursor(page, undo_record)
  @undo_log = page
  @undo_log_cursor = @undo_log.undo_record_cursor(undo_record, @direction)
end

#next_undo_recordObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/innodb/history_list.rb', line 57

def next_undo_record
  if (rec = @undo_record_cursor.undo_record)
    return rec
  end

  if (undo_log = @undo_log_cursor.node)
    @undo_log = undo_log
    @undo_record_cursor = @undo_log.undo_record_cursor(:min, @direction)
  end

  @undo_record_cursor.undo_record
end

#prev_undo_recordObject



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/innodb/history_list.rb', line 70

def prev_undo_record
  if (rec = @undo_log_cursor.undo_record)
    return rec
  end

  if (undo_log = @undo_log_cursor.node)
    @undo_log = undo_log
    @undo_record_cursor = @undo_log.undo_record_cursor(:max, @direction)
  end

  @undo_record_cursor.undo_record
end

#undo_recordObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/innodb/history_list.rb', line 37

def undo_record
  return nil unless @undo_record_cursor

  if (rec = @undo_record_cursor.undo_record)
    return rec
  end

  case @direction
  when :forward
    next_undo_record
  when :backward
    prev_undo_record
  end
end