Object Server for Swift
Bases: object
Implements the WSGI application for the Swift Object Server.
Handle HTTP DELETE requests for the Swift Object Server.
Handle HTTP GET requests for the Swift Object Server.
Handle HTTP HEAD requests for the Swift Object Server.
Handle HTTP POST requests for the Swift Object Server.
Handle HTTP PUT requests for the Swift Object Server.
Handle REPLICATE requests for the Swift Object Server. This is used by the object replicator to get hashes for directories.
Sends or saves an async update.
Parameters: |
|
---|
Update the container when objects are updated.
Parameters: |
|
---|
Update the expiring objects container when objects are updated.
Parameters: |
|
---|
Utility method for instantiating a DiskFile object supporting a given REST API.
An implementation of the object server that wants to use a different DiskFile class would simply over-ride this method to provide that behavior.
Implementation specific setup. This method is called at the very end by the constructor to allow a specific implementation to modify existing attributes or add its own attributes.
Parameters: | conf – WSGI configuration parameter |
---|
paste.deploy app factory for creating WSGI object server apps
Bases: swift.common.daemon.Daemon
Replicate objects.
Encapsulates most logic and data needed by the object replication process. Each call to .replicate() performs one replication pass. It’s up to the caller to do this in a loop.
Check to see if the ring has been updated
Returns: | boolean indicating whether or not the ring has changed |
---|
Returns a sorted list of jobs (dictionaries) that specify the partitions, nodes, etc to be rsynced.
In testing, the pool.waitall() call very occasionally failed to return. This is an attempt to make sure the replicator finishes its replication pass in some eventuality.
Loop that runs in the background during replication. It periodically logs progress.
Utility function that kills all coroutines currently running.
Run a replication pass
Synchronize local suffix directories from a partition with a remote node.
Parameters: |
|
---|---|
Returns: | boolean indicating success or failure |
Logs various stats for the currently running replication pass.
High-level method that replicates a single partition.
Parameters: | job – a dict containing info about the partition to be replicated |
---|
High-level method that replicates a single partition that doesn’t belong on this node.
Parameters: | job – a dict containing info about the partition to be replicated |
---|
Bases: swift.common.daemon.Daemon
Update object information in container listings.
Get the container ring. Load it, if it hasn’t been yet.
If there are async pendings on the device, walk each one and update.
Parameters: | device – path to device |
---|
Perform the object update to the container
Parameters: |
|
---|
Process the object information to be updated and update.
Parameters: |
|
---|
Run the updater continuously.
Run the updater once.
random() -> x in the interval [0, 1).
Bases: object
Walk through file system to audit object
Entrypoint to object_audit, with a failsafe generic exception handler.
Audits the given object path.
Parameters: |
|
---|
Based on config’s object_size_stats will keep track of how many objects fall into the specified ranges. For example with the following:
object_size_stats = 10, 100, 1024
and your system has 3 objects of sizes: 5, 20, and 10000 bytes the log will look like: {“10”: 1, “100”: 1, “1024”: 0, “OVER”: 1}
Disk File Interface for the Swift Object Server
The DiskFile, DiskFileWriter and DiskFileReader classes combined define the on-disk abstraction layer for supporting the object server REST API interfaces (excluding REPLICATE). Other implementations wishing to provide an alternative backend for the object server must implement the three classes. An example alternative implementation can be found in the mem_server.py and mem_diskfile.py modules along size this one.
The DiskFileManager is a reference implemenation specific class and is not part of the backend API.
The remaining methods in this module are considered implementation specifc and are also not considered part of the backend API.
Bases: object
Manage object files.
This specific implementation manages object files on a disk formatted with a POSIX-compliant file system that supports extended attributes as metadata on a file or directory.
Note
The arguments to the constructor are considered implementation specific. The API does not define the constructor arguments.
Parameters: |
|
---|
Context manager to create a file. We create a temporary file first, and then return a DiskFileWriter object to encapsulate the state.
Note
An implementation is not required to perform on-disk preallocations even if the parameter is specified. But if it does and it fails, it must raise a DiskFileNoSpace exception.
Parameters: | size – optional initial size of file to explicitly allocate on disk |
---|---|
Raises DiskFileNoSpace: | |
if a size is specified and allocation fails |
Delete the object.
This implementation creates a tombstone file using the given timestamp, and removes any older versions of the object file. Any file that has an older timestamp than timestamp will be deleted.
Note
An implementation is free to use or ignore the timestamp parameter.
Parameters: | timestamp – timestamp to compare with each file |
---|---|
Raises DiskFileError: | |
this implementation will raise the same errors as the create() method. |
Provide the metadata for a previously opened object as a dictionary.
Returns: | object’s metadata dictionary |
---|---|
Raises DiskFileNotOpen: | |
if the swift.obj.diskfile.DiskFile.open() method was not previously invoked |
Open the object.
This implementation opens the data file representing the object, reads the associated metadata in the extended attributes, additionally combining metadata from fast-POST .meta files.
Note
An implementation is allowed to raise any of the following exceptions, but is only required to raise DiskFileNotExist when the object representation does not exist.
Raises: |
|
---|---|
Returns: | itself for use as a context manager |
Return the metadata for an object without requiring the caller to open the object first.
Returns: | metadata dictionary for an object |
---|---|
Raises DiskFileError: | |
this implementation will raise the same errors as the open() method. |
Return a swift.common.swob.Response class compatible “app_iter” object as defined by swift.obj.diskfile.DiskFileReader.
For this implementation, the responsibility of closing the open file is passed to the swift.obj.diskfile.DiskFileReader object.
Parameters: |
|
---|---|
Returns: | a swift.obj.diskfile.DiskFileReader object |
Write a block of metadata to an object without requiring the caller to create the object first. Supports fast-POST behavior semantics.
Parameters: | metadata – dictionary of metadata to be associated with the object |
---|---|
Raises DiskFileError: | |
this implementation will raise the same errors as the create() method. |
Bases: object
Management class for devices, providing common place for shared parameters and methods not provided by the DiskFile class (which primarily services the object server REST API layer).
The get_diskfile() method is how this implementation creates a DiskFile object.
Note
This class is reference implementation specific and not part of the pluggable on-disk backend API.
Note
TODO(portante): Not sure what the right name to recommend here, as “manager” seemed generic enough, though suggestions are welcome.
Parameters: |
|
---|
Construct the path to a device without checking if it is mounted.
Parameters: | device – name of target device |
---|---|
Returns: | full path to the device |
Return the path to a device, checking to see that it is a proper mount point based on a configuration parameter.
Parameters: | device – name of target device |
---|---|
Returns: | full path to the device, None if the path to the device is not a proper mount point. |
Bases: object
Encapsulation of the WSGI read context for servicing GET REST API requests. Serves as the context manager object for the swift.obj.diskfile.DiskFile class’s swift.obj.diskfile.DiskFile.reader() method.
Note
The quarantining behavior of this method is considered implementation specific, and is not required of the API.
Note
The arguments to the constructor are considered implementation specific. The API does not define the constructor arguments.
Parameters: |
|
---|
Returns an iterator over the data file for range (start, stop)
Returns an iterator over the data file for a set of ranges
Close the open file handle if present.
For this specific implementation, this method will handle quarantining the file if necessary.
Bases: object
Encapsulation of the write context for servicing PUT REST API requests. Serves as the context manager object for the swift.obj.diskfile.DiskFile class’s swift.obj.diskfile.DiskFile.create() method.
Note
It is the responsibility of the swift.obj.diskfile.DiskFile.create() method context manager to close the open file descriptor.
Note
The arguments to the constructor are considered implementation specific. The API does not define the constructor arguments.
Parameters: |
|
---|
Finalize writing the file on disk.
For this implementation, this method is responsible for renaming the temporary file to the final name and directory location. This method should be called after the final call to swift.obj.diskfile.DiskFileWriter.write().
Parameters: | metadata – dictionary of metadata to be associated with the object |
---|
Write a chunk of data to disk. All invocations of this method must come before invoking the :func:
For this implementation, the data is written into a temporary file.
Parameters: | chunk – the chunk of data to write as a string object |
---|---|
Returns: | the total number of bytes written to an object |
Get a list of hashes for the suffix dir. do_listdir causes it to mistrust the hash cache for suffix existence at the (unexpectedly high) cost of a listdir. reclaim_age is just passed on to hash_suffix.
Parameters: |
|
---|---|
Returns: | tuple of (number of suffix dirs hashed, dictionary of hashes) |
List contents of a hash directory and clean up any old files.
Parameters: |
|
---|---|
Returns: | list of files remaining in the directory, reverse sorted |
Performs reclamation and returns an md5 of all (remaining) files.
Parameters: | reclaim_age – age in seconds at which to remove tombstones |
---|---|
Raises: |
|
Invalidates the hash for a suffix_dir in the partition’s hashes file.
Parameters: | suffix_dir – absolute path to suffix dir whose hash needs invalidating |
---|
In the case that a file is corrupted, move it to a quarantined area to allow replication to fix it.
Params device_path: | |
---|---|
The path to the device the corrupted file is on. | |
Params corrupted_file_path: | |
The path to the file you want quarantined. | |
Returns: | path (str) of directory the file was moved to |
Raises OSError: | re-raises non errno.EEXIST / errno.ENOTEMPTY exceptions from rename |
Helper function to read the pickled metadata from an object file.
Parameters: | fd – file descriptor to load the metadata from |
---|---|
Returns: | dictionary of metadata |
Helper function to write pickled metadata for an object file.
Parameters: |
|
---|