Class: Innodb::Inode
- Inherits:
-
Object
- Object
- Innodb::Inode
- 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
-
#space ⇒ Object
Returns the value of attribute space.
Class Method Summary collapse
-
.new_from_cursor(space, cursor) ⇒ Object
Construct a new Inode by reading an FSEG header from a cursor.
-
.page_number_array(size, cursor) ⇒ Object
Read an array of page numbers (32-bit integers, which may be nil) from the provided cursor.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare one Innodb::Inode to another.
-
#allocated? ⇒ Boolean
Helper method to determine if an Inode is in use.
-
#dump ⇒ Object
Dump a summary of this object for debugging purposes.
-
#each_list ⇒ Object
Iterate through all lists, yielding the list name and the list itself.
-
#each_page ⇒ Object
Iterate through the page as associated with this inode using the each_page_number method, and yield the page number and page.
-
#each_page_number ⇒ Object
Iterate through the fragment array followed by all lists, yielding the page number.
-
#fill_factor ⇒ Object
Calculate the fill factor of this fseg, in percent.
- #frag_array ⇒ Object
-
#frag_array_n_used ⇒ Object
Helper method to count non-nil fragment pages.
-
#frag_array_pages ⇒ Object
Helper method to return an array of only non-nil fragment pages.
- #free ⇒ Object
- #fseg_id ⇒ Object
- #full ⇒ Object
-
#initialize(space, data) ⇒ Inode
constructor
A new instance of Inode.
- #inspect ⇒ Object
-
#list(name) ⇒ Object
Return a list from the fseg, given its name as a symbol.
-
#lists ⇒ Object
Return an array of lists within an fseg.
- #magic_n ⇒ Object
- #not_full ⇒ Object
- #not_full_n_used ⇒ Object
- #offset ⇒ Object
-
#total_pages ⇒ Object
Calculate the total number of pages within this fseg.
-
#used_pages ⇒ Object
Calculate the total number of pages in use (not free) within this fseg.
Constructor Details
#initialize(space, data) ⇒ Inode
Returns a new instance of Inode.
61 62 63 64 |
# File 'lib/innodb/inode.rb', line 61 def initialize(space, data) @space = space @data = data end |
Instance Attribute Details
#space ⇒ Object
Returns the value of attribute space.
59 60 61 |
# File 'lib/innodb/inode.rb', line 59 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 57 |
# File 'lib/innodb/inode.rb', line 30 def self.new_from_cursor(space, cursor) data = { :offset => cursor.position, :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.
179 180 181 |
# File 'lib/innodb/inode.rb', line 179 def ==(other) fseg_id == other.fseg_id if other 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.
85 86 87 |
# File 'lib/innodb/inode.rb', line 85 def allocated? fseg_id != 0 end |
#dump ⇒ Object
Dump a summary of this object for debugging purposes.
184 185 186 |
# File 'lib/innodb/inode.rb', line 184 def dump pp @data end |
#each_list ⇒ Object
Iterate through all lists, yielding the list name and the list itself.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/innodb/inode.rb', line 129 def each_list unless block_given? return enum_for(:each_list) end lists.each do |name| yield name, list(name) end nil end |
#each_page ⇒ Object
Iterate through the page as associated with this inode using the each_page_number method, and yield the page number and page.
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/innodb/inode.rb', line 166 def each_page unless block_given? return enum_for(:each_page) end each_page_number do |page_number| yield page_number, space.page(page_number) end nil end |
#each_page_number ⇒ Object
Iterate through the fragment array followed by all lists, yielding the page number. This allows a convenient way to identify all pages that are part of this inode.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/innodb/inode.rb', line 144 def each_page_number unless block_given? return enum_for(:each_page_number) end frag_array_pages.each do |page_number| yield page_number end each_list do |fseg_name, fseg_list| fseg_list.each do |xdes| xdes.each_page_status do |page_number| yield page_number end end end nil end |
#fill_factor ⇒ Object
Calculate the fill factor of this fseg, in percent.
114 115 116 |
# File 'lib/innodb/inode.rb', line 114 def fill_factor total_pages > 0 ? 100.0 * (used_pages.to_f / total_pages.to_f) : 0.0 end |
#frag_array ⇒ Object
73 |
# File 'lib/innodb/inode.rb', line 73 def frag_array; @data[:frag_array]; end |
#frag_array_n_used ⇒ Object
Helper method to count non-nil fragment pages.
95 96 97 |
# File 'lib/innodb/inode.rb', line 95 def frag_array_n_used frag_array.inject(0) { |n, i| n += 1 if i; n } end |
#frag_array_pages ⇒ Object
Helper method to return an array of only non-nil fragment pages.
90 91 92 |
# File 'lib/innodb/inode.rb', line 90 def frag_array_pages frag_array.select { |n| ! n.nil? } end |
#free ⇒ Object
69 |
# File 'lib/innodb/inode.rb', line 69 def free; @data[:free]; end |
#fseg_id ⇒ Object
67 |
# File 'lib/innodb/inode.rb', line 67 def fseg_id; @data[:fseg_id]; end |
#full ⇒ Object
71 |
# File 'lib/innodb/inode.rb', line 71 def full; @data[:full]; end |
#inspect ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/innodb/inode.rb', line 75 def inspect "<%s space=%s, fseg=%i>" % [ self.class.name, space.inspect, fseg_id, ] end |
#list(name) ⇒ Object
Return a list from the fseg, given its name as a symbol.
124 125 126 |
# File 'lib/innodb/inode.rb', line 124 def list(name) @data[name] if lists.include? name end |
#lists ⇒ Object
Return an array of lists within an fseg.
119 120 121 |
# File 'lib/innodb/inode.rb', line 119 def lists [:free, :not_full, :full] end |
#magic_n ⇒ Object
72 |
# File 'lib/innodb/inode.rb', line 72 def magic_n; @data[:magic_n]; end |
#not_full ⇒ Object
70 |
# File 'lib/innodb/inode.rb', line 70 def not_full; @data[:not_full]; end |
#not_full_n_used ⇒ Object
68 |
# File 'lib/innodb/inode.rb', line 68 def not_full_n_used; @data[:not_full_n_used]; end |
#offset ⇒ Object
66 |
# File 'lib/innodb/inode.rb', line 66 def offset; @data[:offset]; end |
#total_pages ⇒ Object
Calculate the total number of pages within this fseg.
106 107 108 109 110 111 |
# File 'lib/innodb/inode.rb', line 106 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_pages ⇒ Object
Calculate the total number of pages in use (not free) within this fseg.
100 101 102 103 |
# File 'lib/innodb/inode.rb', line 100 def used_pages frag_array_n_used + not_full_n_used + (full.length * @space.pages_per_extent) end |