Included Modules

MogileFS::MogileFS

MogileFS file manipulation client.

Create a new instance that will communicate with these trackers:
hosts = %w[192.168.1.69:6001 192.168.1.70:6001]
mg = MogileFS::MogileFS.new(:domain => 'test', :hosts => hosts)

# Stores "A bunch of text to store" into 'some_key' with a class of 'text'.
mg.store_content('some_key', 'text', "A bunch of text to store")

# Retrieve data from 'some_key' as a string
data = mg.get_file_data('some_key')

# Store the contents of 'image.jpeg' into the key 'my_image' with a
# class of 'image'.
mg.store_file('my_image', 'image', 'image.jpeg')

# Store the contents of 'image.jpeg' into the key 'my_image' with a
# class of 'image' using an open IO object.
File.open('image.jpeg') { |fp| mg.store_file('my_image', 'image', fp) }

# Retrieve the contents of 'my_image' into '/path/to/huge_file'
# without slurping the entire contents into memory:
mg.get_file_data('my_image', '/path/to/huge_file')

# Remove the key 'my_image' and 'some_key'.
mg.delete('my_image')
mg.delete('some_key')

Attributes

domain[RW]

The domain of keys for this MogileFS client.

get_file_data_timeout[RW]

The timeout for get_file_data (per-read() system call). Defaults to five seconds.

new_file_max_time[RW]

The maximum allowed time for creating a new_file. Defaults to 1 hour.

Public Class Methods

new(args = {}) view method source

Creates a new MogileFS::MogileFS instance. args must include a key :domain specifying the domain of this client.

Optional parameters for args:

:get_file_data_timeout => Numeric

See get_file_data_timeout

:new_file_max_time => Numeric

See new_file_max_time

:fail_timeout => Numeric

Delay before retrying a failed tracker backends. Defaults to 5 seconds.

:timeout => Numeric

Timeout for tracker backend responses. Defaults to 3 seconds.

Public Instance Methods

delete(key) view method source

Removes key.

each_key(prefix = "", &block) view method source

Enumerates keys, limited by optional prefix

exist?(key) view method source

Returns true if key exists, false if not

file_debug(args) view method source

Given an Integer fid or String key and domain, thorougly search the database for all occurences of a particular fid.

Use this sparingly, this command hits the master database numerous times and is very expensive. This is not for production use, only troubleshooting and debugging.

Searches for fid=666:

client.file_debug(666)

Search for key=foo using the default domain for this object:

client.file_debug("foo")

Search for key=foo in domain=“bar”:

client.file_debug(:key => "foo", :domain => "bar")
file_info(key, args = nil) view method source

Return metadata about a file as a hash. Returns the domain, class, length, devcount, etc. as keys. Optionally, device ids (not paths) can be returned as well if :devices is specified and true.

This should only be used for informational purposes, and not usually for dynamically serving files.

mg.file_info("bar")

Returns:

{
  "domain" => "foo",
  "key" => "bar",
  "class" => "default",
  "devcount" => 2,
  "length => 666
}
get_file_data(key, dst = nil, copy_length = nil, src_offset = nil) view method source

Retrieves the contents of key. If dst is specified, dst should be an IO-like object capable of receiving the write method or a path name. copy_length may be specified to limit the number of bytes to retrieve, and src_offset can be specified to specified the start position of the copy.

get_paths(key, *args) view method source

Get the paths (URLs as strings) for key. If args is specified, it may contain:

  • :noverify -> boolean, whether or not the tracker checks (default: true)

  • :pathcount -> a positive integer of URLs to retrieve (default: 2)

  • :zone -> “alt” or nil (default: nil)

:noverify defaults to true because this client library is capable of verifying paths for readability itself. It is also faster and more reliable to verify paths on the client.

get_uris(key, *args) view method source

Get the URIs for key (paths) as URI::HTTP objects

list_keys(prefix = "", after = nil, limit = 1000, &block) view method source

Lists keys starting with prefix following after up to limit. If after is nil the list starts at the beginning.

new_file(key, args = nil, bytes = nil) view method source

Creates a new file key in the domain of this object.

bytes is the expected size of the file if known in advance

It operates like File.open(…, “w”) and may take an optional block, yielding an IO-like object with support for the methods documented in MogileFS::NewFile::Writer.

This atomically replaces existing data stored as key when the block exits or when the returned object is closed.

args may contain the following options:

:content_length => Integer

This has the same effect as the (deprecated) bytes parameter.

:largefile => :stream, :content_range or :tempfile

See MogileFS::NewFile for more information on this

:class => String

The MogileFS storage class of the object.

rename(from, to) view method source

Renames a key from to key to.

Returns the size of key.

store_content(key, klass, content, opts = nil) view method source

Stores content into key in class klass, where content is a String This atomically replaces existing data stored as key

store_file(key, klass, file, opts = nil) view method source

Copies the contents of file into key in class klass. file can be either a path name (String or Pathname object) or an IO-like object that responds to read or readpartial. Returns size of file stored. This atomically replaces existing data stored as key

Originally generated with the Darkfish Rdoc Generator 2, modified by wrongdoc.