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.



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

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

  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
end

Instance Method Details

#each_undo_recordObject



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

def each_undo_record
  unless block_given?
    return enum_for(:each_undo_record)
  end

  while rec = undo_record
    yield rec
  end
end

#move_cursor(page, undo_record) ⇒ Object



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

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

#next_undo_recordObject



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

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



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

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



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

def undo_record
  unless @undo_record_cursor
    return nil
  end

  if rec = @undo_record_cursor.undo_record
    return rec
  end

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