Previous topic

Auth Server and Middleware

Next topic

Instructions for a Multiple Server Swift Installation (Ubuntu)

This Page

Pluggable Back-ends: API Documentation

Pluggable Back-end for Account Server

class swift.account.backend.AccountBroker(db_file, timeout=25, logger=None, account=None, container=None, pending_timeout=None, stale_reads_ok=False)

Encapsulates working with an account database.

create_account_stat_table(conn, put_timestamp)

Create account_stat table which is specific to the account DB. Not a part of Pluggable Back-ends, internal to the baseline code.

Parameters:
  • conn – DB connection object
  • put_timestamp – put timestamp
create_container_table(conn)

Create container table which is specific to the account DB.

Parameters:conn – DB connection object
empty()

Check if the account DB is empty.

Returns:True if the database has no active containers.
get_db_version(conn)
get_info()

Get global data for the account.

Returns:dict with keys: account, created_at, put_timestamp, delete_timestamp, container_count, object_count, bytes_used, hash, id
is_deleted()

Check if the account DB is considered to be deleted.

Returns:True if the account DB is considered to be deleted, False otherwise
is_status_deleted()

Only returns true if the status field is set to DELETED.

list_containers_iter(limit, marker, end_marker, prefix, delimiter)

Get a list of containers sorted by name starting at marker onward, up to limit entries. Entries will begin with the prefix and will not have the delimiter after the prefix.

Parameters:
  • limit – maximum number of entries to get
  • marker – marker query
  • end_marker – end marker query
  • prefix – prefix query
  • delimiter – delimiter for query
Returns:

list of tuples of (name, object_count, bytes_used, 0)

merge_items(item_list, source=None)

Merge items into the container table.

Parameters:
  • item_list – list of dictionaries of {‘name’, ‘put_timestamp’, ‘delete_timestamp’, ‘object_count’, ‘bytes_used’, ‘deleted’}
  • source – if defined, update incoming_sync with the source
put_container(name, put_timestamp, delete_timestamp, object_count, bytes_used)

Create a container with the given attributes.

Parameters:
  • name – name of the container to create
  • put_timestamp – put_timestamp of the container to create
  • delete_timestamp – delete_timestamp of the container to create
  • object_count – number of objects in the container
  • bytes_used – number of bytes used by the container

Pluggable Back-ends for Container Server

class swift.container.backend.ContainerBroker(db_file, timeout=25, logger=None, account=None, container=None, pending_timeout=None, stale_reads_ok=False)

Encapsulates working with a container database.

create_container_stat_table(conn, put_timestamp=None)

Create the container_stat table which is specific to the container DB. Not a part of Pluggable Back-ends, internal to the baseline code.

Parameters:
  • conn – DB connection object
  • put_timestamp – put timestamp
create_object_table(conn)

Create the object table which is specifc to the container DB. Not a part of Pluggable Back-ends, internal to the baseline code.

Parameters:conn – DB connection object
delete_object(name, timestamp)

Mark an object deleted.

Parameters:
  • name – object name to be deleted
  • timestamp – timestamp when the object was marked as deleted
empty()

Check if container DB is empty.

Returns:True if the database has no active objects, False otherwise
get_db_version(conn)
get_info()

Get global data for the container.

Returns:dict with keys: account, container, created_at, put_timestamp, delete_timestamp, object_count, bytes_used, reported_put_timestamp, reported_delete_timestamp, reported_object_count, reported_bytes_used, hash, id, x_container_sync_point1, and x_container_sync_point2.
is_deleted(timestamp=None)

Check if the DB is considered to be deleted.

Returns:True if the DB is considered to be deleted, False otherwise
list_objects_iter(limit, marker, end_marker, prefix, delimiter, path=None)

Get a list of objects sorted by name starting at marker onward, up to limit entries. Entries will begin with the prefix and will not have the delimiter after the prefix.

Parameters:
  • limit – maximum number of entries to get
  • marker – marker query
  • end_marker – end marker query
  • prefix – prefix query
  • delimiter – delimiter for query
  • path – if defined, will set the prefix and delimter based on the path
Returns:

list of tuples of (name, created_at, size, content_type, etag)

merge_items(item_list, source=None)

Merge items into the object table.

Parameters:
  • item_list – list of dictionaries of {‘name’, ‘created_at’, ‘size’, ‘content_type’, ‘etag’, ‘deleted’}
  • source – if defined, update incoming_sync with the source
put_object(name, timestamp, size, content_type, etag, deleted=0)

Creates an object in the DB with its metadata.

Parameters:
  • name – object name to be created
  • timestamp – timestamp of when the object was created
  • size – object size
  • content_type – object content-type
  • etag – object etag
  • deleted – if True, marks the object as deleted and sets the deteleted_at timestamp to timestamp
reported(put_timestamp, delete_timestamp, object_count, bytes_used)

Update reported stats, available with container’s get_info.

Parameters:
  • put_timestamp – put_timestamp to update
  • delete_timestamp – delete_timestamp to update
  • object_count – object_count to update
  • bytes_used – bytes_used to update
set_x_container_sync_points(sync_point1, sync_point2)

Disk File Interface for Swift Object Server

class swift.obj.diskfile.DiskFile(path, device, partition, account, container, obj, logger, disk_chunk_size=65536, bytes_per_sync=536870912, iter_hook=None, threadpool=None, obj_dir='objects', mount_check=False)

Manage object files on disk.

Parameters:
  • path – path to devices on the node
  • device – device name
  • partition – partition on the device the object lives in
  • account – account name for the object
  • container – container name for the object
  • obj – object name for the object
  • disk_chunk_size – size of chunks on file reads
  • bytes_per_sync – number of bytes between fdatasync calls
  • iter_hook – called when __iter__ returns a chunk
  • threadpool – thread pool in which to do blocking operations
app_iter_range(start, stop)

Returns an iterator over the data file for range (start, stop)

app_iter_ranges(ranges, content_type, boundary, size)

Returns an iterator over the data file for a set of ranges

close(verify_file=True)

Close the file. Will handle quarantining file if necessary.

Parameters:verify_file – Defaults to True. If false, will not check file to see if it needs quarantining.
create(*args, **kwds)

Context manager to create a file. We create a temporary file first, and then return a DiskWriter object to encapsulate the state.

Parameters:size – optional initial size of file to explicitly allocate on disk
Raises DiskFileNoSpace:
 if a size is specified and allocation fails
delete(timestamp)

Simple short hand for marking an object as deleted. Provides a layer of abstraction.

Parameters:timestamp – time stamp to mark the object deleted at
get_data_file_size()

Returns the os.path.getsize for the file. Raises an exception if this file does not match the Content-Length stored in the metadata. Or if self.data_file does not exist.

Returns:

file size as an int

Raises:
  • DiskFileError – on file size mismatch.
  • DiskFileNotExist – on file not existing (including deleted)
get_metadata()

Provide the metadata for an object as a dictionary.

Returns:object’s metadata dictionary
is_deleted()

Check if the file is deleted.

Returns:True if the file doesn’t exist or has been flagged as deleted.
is_expired()

Check if the file is expired.

Returns:True if the file has an X-Delete-At in the past
open(verify_close=False)

Open the file and read the metadata.

This method must populate the _metadata attribute.

Parameters:verify_close – force implicit close to verify_file, no effect on explicit close.
Raises DiskFileCollision:
 on md5 collision
put_metadata(metadata, tombstone=False)

Short hand for putting metadata to .meta and .ts files.

Parameters:
  • metadata – dictionary of metadata to be written
  • tombstone – whether or not we are writing a tombstone
quarantine()

In the case that a file is corrupted, move it to a quarantined area to allow replication to fix it.

Returns:if quarantine is successful, path to quarantined directory otherwise None
class swift.obj.diskfile.DiskWriter(disk_file, fd, tmppath, threadpool)

Encapsulation of the write context for servicing PUT REST API requests. Serves as the context manager object for DiskFile’s create() method.

put(metadata, extension='.data')

Finalize writing the file on disk, and renames it from the temp file to the real location. This should be called after the data has been written to the temp file.

Parameters:
  • metadata – dictionary of metadata to be written
  • extension – extension to be used when making the file
write(chunk)

Write a chunk of data into the temporary file.

Parameters:chunk – the chunk of data to write as a string object
swift.obj.diskfile.get_hashes(partition_dir, recalculate=None, do_listdir=False, reclaim_age=604800)

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:
  • partition_dir – absolute path of partition to get hashes for
  • recalculate – list of suffixes which should be recalculated when got
  • do_listdir – force existence check for all hashes in the partition
  • reclaim_age – age at which to remove tombstones
Returns:

tuple of (number of suffix dirs hashed, dictionary of hashes)

swift.obj.diskfile.hash_cleanup_listdir(hsh_path, reclaim_age=604800)

List contents of a hash directory and clean up any old files.

Parameters:
  • hsh_path – object hash path
  • reclaim_age – age in seconds at which to remove tombstones
Returns:

list of files remaining in the directory, reverse sorted

swift.obj.diskfile.hash_suffix(path, reclaim_age)

Performs reclamation and returns an md5 of all (remaining) files.

Parameters:

reclaim_age – age in seconds at which to remove tombstones

Raises:
  • PathNotDir – if given path is not a valid directory
  • OSError – for non-ENOTDIR errors
swift.obj.diskfile.invalidate_hash(suffix_dir)

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
swift.obj.diskfile.quarantine_renamer(device_path, corrupted_file_path)

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
swift.obj.diskfile.read_metadata(fd)

Helper function to read the pickled metadata from an object file.

Parameters:fd – file descriptor to load the metadata from
Returns:dictionary of metadata
swift.obj.diskfile.write_metadata(fd, metadata)

Helper function to write pickled metadata for an object file.

Parameters:
  • fd – file descriptor to write the metadata
  • metadata – metadata to write