|
NAMEMogileFS::Client - Client library for the MogileFS distributed file system.SYNOPSISuse MogileFS::Client; # create client object w/ server-configured namespace # and IPs of trackers $mogc = MogileFS::Client->new(domain => "foo.com::my_namespace", hosts => ['10.0.0.2:7001', '10.0.0.3:7001']); # create a file # mogile is a flat namespace. no paths. $key = "image_of_userid:$userid"; # must be configured on server $class = "user_images"; $fh = $mogc->new_file($key, $class); print $fh $data; unless ($fh->close) { die "Error writing file: " . $mogc->errcode . ": " . $mogc->errstr; } # Find the URLs that the file was replicated to. # May change over time. @urls = $mogc->get_paths($key); # no longer want it? $mogc->delete($key); DESCRIPTIONThis module is a client library for the MogileFS distributed file system. The class method 'new' creates a client object against a particular mogilefs tracker and domain. This object may then be used to store and retrieve content easily from MogileFS.METHODSnew$client = MogileFS::Client->new( %OPTIONS ); Creates a new MogileFS::Client object. Returns MogileFS::Client object on success, or dies on failure. OPTIONS:
reload$mogc->reload( %OPTIONS ) Re-init the object, like you'd just reconstructed it with 'new', but change it in-place instead. Useful if you have a system which reloads a config file, and you want to update a singleton $mogc handle's config value. last_trackerReturns a scalar of form "ip:port", representing the last mogilefsd 'tracker' server which was talked to.errstrReturns string representation of the last error that occurred. It includes the error code (same as method 'errcode') and a space before the optional English error message.This isn't necessarily guaranteed to reset after a successful operation. Only call it after another operation returns an error. errcodeReturns an error code. Not a number, but a string identifier (e.g. "no_domain") which is stable for use in error handling logic.This isn't necessarily guaranteed to reset after a successful operation. Only call it after another operation returns an error. force_disconnectForces the client to disconnect from the tracker, causing it to reconnect when the next request is made. It will reconnect to a different tracker if possible. A paranoid application may wish to do to this before retrying a failed command, on the off chance that another tracker may be working better.readonly$is_readonly = $mogc->readonly $mogc->readonly(1) Getter/setter to mark this client object as read-only. Purely a local operation/restriction, doesn't do a network operation to the mogilefsd server. new_file$mogc->new_file($key) $mogc->new_file($key, $class) $mogc->new_file($key, $class, $content_length) $mogc->new_file($key, $class, $content_length , $opts_hashref) Start creating a new filehandle with the given key, and option given class and options. Returns a filehandle you should then print to, and later close to complete the operation. NOTE: check the return value from close! If your close didn't succeed, the file didn't get saved! $opts_hashref can contain keys:
edit_file$mogc->edit_file($key, $opts_hashref) Edit the file with the the given key. NOTE: edit_file is currently EXPERIMENTAL and not recommended for production use. MogileFS is primarily designed for storing files for later retrieval, rather than editing. Use of this function may lead to poor performance and, until it has been proven mature, should be considered to also potentially cause data loss. NOTE: use of this function requires support for the DAV 'MOVE' verb and partial PUT (i.e. Content-Range in PUT) on the back-end storage servers (e.g. apache with mod_dav). Returns a seekable filehandle you can read/write to. Calling this function may invalidate some or all URLs you currently have for this key, so you should call ->get_paths again afterwards if you need them. On close of the filehandle, the new file contents will replace the previous contents (and again invalidate any existing URLs). By default, the file contents are preserved on open, but you may specify the overwrite option to zero the file first. The seek position is at the beginning of the file, but you may seek to the end to append. $opts_hashref can contain keys:
read_file$mogc->read_file($key) Read the file with the the given key. Returns a seekable filehandle you can read() from. Note that you cannot read line by line using <$fh> notation. Takes the same options as get_paths (which is called internally to get the URIs to read from). store_file$mogc->store_file($key, $class, $fh_or_filename[, $opts_hashref]) Wrapper around new_file, print, and close. Given a key, class, and a filehandle or filename, stores the file contents in MogileFS. Returns the number of bytes stored on success, undef on failure. $opts_hashref can contain keys for new_file, and also the following:
store_content$mogc->store_content($key, $class, $content[, $opts]); Wrapper around new_file, print, and close. Given a key, class, and file contents (scalar or scalarref), stores the file contents in MogileFS. Returns the number of bytes stored on success, undef on failure. get_paths@paths = $mogc->get_paths($key) @paths = $mogc->get_paths($key, $no_verify_bool); # old way @paths = $mogc->get_paths($key, { noverify => $bool }); # new way Given a key, returns an array of all the locations (HTTP URLs) that the file has been replicated to.
get_file_data$dataref = $mogc->get_file_data($key) Wrapper around get_paths & LWP, which returns scalarref of file contents in a scalarref. Don't use for large data, as it all comes back to you in one string. delete$mogc->delete($key); Delete a key from MogileFS. rename$mogc->rename($oldkey, $newkey); Rename file (key) in MogileFS from oldkey to newkey. Returns true on success, failure otherwise. file_debugmy $info_gob = $mogc->file_debug(fid => $fid); ... or ... my $info_gob = $mogc->file_debug(key => $key); Thoroughly search for any database notes about a particular fid. Searchable by raw fidid, or by domain and key. Use sparingly. Command hits the master database numerous times, and if you're using it in production something is likely very wrong. To be used with troubleshooting broken/odd files and errors from mogilefsd. file_infomy $fid = $mogc->file_info($key, { devices => 0 }); Used to return metadata about a file. Returns the domain, class, expected length, devcount, etc. Optionally device ids (not paths) can be returned as well. Should be used for informational purposes, and not usually for dynamically serving files. list_keys$keys = $mogc->list_keys($prefix, $after[, $limit]); ($after, $keys) = $mogc->list_keys($prefix, $after[, $limit]); Used to get a list of keys matching a certain prefix. $prefix specifies what you want to get a list of. $after is the item specified as a return value from this function last time you called it. $limit is optional and defaults to 1000 keys returned. In list context, returns ($after, $keys). In scalar context, returns arrayref of keys. The value $after is to be used as $after when you call this function again. When there are no more keys in the list, you will get back undef or an empty list. foreach_key$mogc->foreach_key( %OPTIONS, sub { my $key = shift; ... } ); $mogc->foreach_key( prefix => "foo:", sub { my $key = shift; ... } ); Functional interface/wrapper around list_keys. Given some %OPTIONS (currently only one, "prefix"), calls your callback for each key matching the provided prefix. update_class$mogc->update_class($key, $newclass); Update the replication class of a pre-existing file, causing the file to become more or less replicated. set_pref_ip$mogc->set_pref_ip({ "10.0.0.2" => "10.2.0.2" }); Weird option for old, weird network architecture. Sets a mapping table of preferred alternate IPs, if reachable. For instance, if trying to connect to 10.0.0.2 in the above example, the module would instead try to connect to 10.2.0.2 quickly first, then then fall back to 10.0.0.2 if 10.2.0.2 wasn't reachable. PLUGIN METHODSWRITEMEHOOKSadd_hookWRITEMEadd_backend_hookWRITEMESEE ALSO<http://www.danga.com/mogilefs/>COPYRIGHTThis module is Copyright 2003-2004 Brad Fitzpatrick, and copyright 2005-2007 Six Apart, Ltd.All rights reserved. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. WARRANTYThis is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.AUTHORSBrad Fitzpatrick <brad@danga.com>Brad Whitaker <whitaker@danga.com> Mark Smith <marksmith@danga.com>
Visit the GSP FreeBSD Man Page Interface. |