class Innodb::Inode

Constants

FRAG_ARRAY_N_SLOTS

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

FRAG_SLOT_SIZE

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

LISTS
MAGIC_N_VALUE

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

SIZE

The size (in bytes) of an Inode entry.

Attributes

header[RW]
space[RW]

Public Class Methods

new(space, header) click to toggle source
# File lib/innodb/inode.rb, line 72
def initialize(space, header)
  @space = space
  @header = header
end
new_from_cursor(space, cursor) click to toggle source

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

# File lib/innodb/inode.rb, line 53
def self.new_from_cursor(space, cursor)
  Innodb::Inode.new(
    space,
    Header.new(
      offset: cursor.position,
      fseg_id: cursor.name("fseg_id") { cursor.read_uint64 },
      not_full_n_used: cursor.name("not_full_n_used") { cursor.read_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.read_uint32 },
      frag_array: cursor.name("frag_array") { page_number_array(FRAG_ARRAY_N_SLOTS, cursor) }
    )
  )
end
page_number_array(size, cursor) click to toggle source

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

# File lib/innodb/inode.rb, line 44
def self.page_number_array(size, cursor)
  size.times.map do |n|
    cursor.name("page[#{n}]") do |c|
      Innodb::Page.maybe_undefined(c.read_uint32)
    end
  end
end

Public Instance Methods

==(other) click to toggle source

Compare one Innodb::Inode to another.

# File lib/innodb/inode.rb, line 177
def ==(other)
  fseg_id == other.fseg_id if other
end
allocated?() click to toggle source

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

# File lib/innodb/inode.rb, line 96
def allocated?
  fseg_id != 0
end
dump() click to toggle source

Dump a summary of this object for debugging purposes.

# File lib/innodb/inode.rb, line 182
def dump
  pp header
end
each_list() { |name, list(name)| ... } click to toggle source

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

# File lib/innodb/inode.rb, line 137
def each_list
  return enum_for(:each_list) unless block_given?

  LISTS.each do |name|
    yield name, list(name)
  end

  nil
end
each_page() { |page_number, page| ... } click to toggle source

Iterate through the page as associated with this inode using the each_page_number method, and yield the page number and page.

# File lib/innodb/inode.rb, line 166
def each_page
  return enum_for(:each_page) unless block_given?

  each_page_number do |page_number|
    yield page_number, space.page(page_number)
  end

  nil
end
each_page_number(&block) click to toggle source

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.

# File lib/innodb/inode.rb, line 150
def each_page_number(&block)
  return enum_for(:each_page_number) unless block_given?

  frag_array_pages.each(&block)

  each_list do |_fseg_name, fseg_list|
    fseg_list.each do |xdes|
      xdes.each_page_status(&block)
    end
  end

  nil
end
fill_factor() click to toggle source

Calculate the fill factor of this fseg, in percent.

# File lib/innodb/inode.rb, line 125
def fill_factor
  total_pages.positive? ? 100.0 * (used_pages.to_f / total_pages) : 0.0
end
frag_array_n_used() click to toggle source

Helper method to count non-nil fragment pages.

# File lib/innodb/inode.rb, line 106
def frag_array_n_used
  frag_array_pages.count
end
frag_array_pages() click to toggle source

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

# File lib/innodb/inode.rb, line 101
def frag_array_pages
  frag_array.compact
end
inspect() click to toggle source
# File lib/innodb/inode.rb, line 86
def inspect
  "<%s space=%s, fseg=%i>" % [
    self.class.name,
    space.inspect,
    fseg_id,
  ]
end
list(name) click to toggle source

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

# File lib/innodb/inode.rb, line 130
def list(name)
  return unless LISTS.include?(name)

  header[name]
end
total_pages() click to toggle source

Calculate the total number of pages within this fseg.

# File lib/innodb/inode.rb, line 117
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() click to toggle source

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

# File lib/innodb/inode.rb, line 111
def used_pages
  frag_array_n_used + not_full_n_used +
    (full.length * @space.pages_per_extent)
end