Class: Innodb::Inode

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

Constant Summary collapse

FRAG_ARRAY_N_SLOTS =

The number of “slots” (each representing one page) in the fragment array within each Inode entry.

32
FRAG_SLOT_SIZE =

The size (in bytes) of each slot in the fragment array.

4
MAGIC_N_VALUE =

A magic number which helps determine if an Inode structure is in use and populated with valid data.

97937874
SIZE =

The size (in bytes) of an Inode entry.

(16 + (3 * Innodb::List::BASE_NODE_SIZE) +
(FRAG_ARRAY_N_SLOTS * FRAG_SLOT_SIZE))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(space, data) ⇒ Inode

Returns a new instance of Inode.



60
61
62
63
# File 'lib/innodb/inode.rb', line 60

def initialize(space, data)
  @space = space
  @data = data
end

Instance Attribute Details

#spaceObject

Returns the value of attribute space.



58
59
60
# File 'lib/innodb/inode.rb', line 58

def space
  @space
end

Class Method Details

.new_from_cursor(space, cursor) ⇒ Object

Construct a new Inode by reading an FSEG header from a cursor.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/innodb/inode.rb', line 30

def self.new_from_cursor(space, cursor)
  data = {
    :fseg_id => cursor.name("fseg_id") {
      cursor.get_uint64
    },
    :not_full_n_used => cursor.name("not_full_n_used") {
      cursor.get_uint32
    },
    :free => cursor.name("list[free]") { 
      Innodb::List::Xdes.new(space, Innodb::List.get_base_node(cursor))
    },
    :not_full => cursor.name("list[not_full]") { 
      Innodb::List::Xdes.new(space, Innodb::List.get_base_node(cursor))
    },
    :full => cursor.name("list[full]") { 
      Innodb::List::Xdes.new(space, Innodb::List.get_base_node(cursor))
    },
    :magic_n => cursor.name("magic_n") {
      cursor.get_uint32
    },
    :frag_array => cursor.name("frag_array") { 
      page_number_array(FRAG_ARRAY_N_SLOTS, cursor)
    },
  }

  Innodb::Inode.new(space, data)
end

.page_number_array(size, cursor) ⇒ Object

Read an array of page numbers (32-bit integers, which may be nil) from the provided cursor.



21
22
23
24
25
26
27
# File 'lib/innodb/inode.rb', line 21

def self.page_number_array(size, cursor)
  size.times.map do |n|
    cursor.name("page[#{n}]") do |c|
      Innodb::Page.maybe_undefined(c.get_uint32)
    end
  end
end

Instance Method Details

#==(other) ⇒ Object

Compare one Innodb::Inode to another.



126
127
128
# File 'lib/innodb/inode.rb', line 126

def ==(other)
  fseg_id == other.fseg_id
end

#allocated?Boolean

Helper method to determine if an Inode is in use. Inodes that are not in use have an fseg_id of 0.

Returns:



75
76
77
# File 'lib/innodb/inode.rb', line 75

def allocated?
  fseg_id != 0
end

#dumpObject

Dump a summary of this object for debugging purposes.



131
132
133
# File 'lib/innodb/inode.rb', line 131

def dump
  pp @data
end

#each_listObject

Iterate through all lists, yielding the list name and the list itself.



119
120
121
122
123
# File 'lib/innodb/inode.rb', line 119

def each_list
  lists.each do |name|
    yield name, list(name)
  end
end

#fill_factorObject

Calculate the fill factor of this fseg, in percent.



104
105
106
# File 'lib/innodb/inode.rb', line 104

def fill_factor
  total_pages > 0 ? 100.0 * (used_pages.to_f / total_pages.to_f) : 0.0
end

#frag_arrayObject



71
# File 'lib/innodb/inode.rb', line 71

def frag_array;       @data[:frag_array];       end

#frag_array_n_usedObject

Helper method to count non-nil fragment pages.



85
86
87
# File 'lib/innodb/inode.rb', line 85

def frag_array_n_used
  frag_array.inject(0) { |n, i| n += 1 if i; n }
end

#frag_array_pagesObject

Helper method to return an array of only non-nil fragment pages.



80
81
82
# File 'lib/innodb/inode.rb', line 80

def frag_array_pages
  frag_array.select { |n| ! n.nil? }
end

#freeObject



67
# File 'lib/innodb/inode.rb', line 67

def free;             @data[:free];             end

#fseg_idObject



65
# File 'lib/innodb/inode.rb', line 65

def fseg_id;          @data[:fseg_id];          end

#fullObject



69
# File 'lib/innodb/inode.rb', line 69

def full;             @data[:full];             end

#list(name) ⇒ Object

Return a list from the fseg, given its name as a symbol.



114
115
116
# File 'lib/innodb/inode.rb', line 114

def list(name)
  @data[name] if lists.include? name
end

#listsObject

Return an array of lists within an fseg.



109
110
111
# File 'lib/innodb/inode.rb', line 109

def lists
  [:free, :not_full, :full]
end

#magic_nObject



70
# File 'lib/innodb/inode.rb', line 70

def magic_n;          @data[:magic_n];          end

#not_fullObject



68
# File 'lib/innodb/inode.rb', line 68

def not_full;         @data[:not_full];         end

#not_full_n_usedObject



66
# File 'lib/innodb/inode.rb', line 66

def not_full_n_used;  @data[:not_full_n_used];  end

#total_pagesObject

Calculate the total number of pages within this fseg.



96
97
98
99
100
101
# File 'lib/innodb/inode.rb', line 96

def total_pages
  frag_array_n_used +
    (free.length * @space.pages_per_extent) +
    (not_full.length * @space.pages_per_extent) +
    (full.length * @space.pages_per_extent)
end

#used_pagesObject

Calculate the total number of pages in use (not free) within this fseg.



90
91
92
93
# File 'lib/innodb/inode.rb', line 90

def used_pages
  frag_array_n_used + not_full_n_used
    (full.length * @space.pages_per_extent)
end