Database code for Swift
Bases: swift.common.db.DatabaseBroker
Encapsulates working with a account database.
Check if the accont DB can be deleted.
Returns: | True if the account can be deleted, False otherwise |
---|
Create account_stat table which is specific to the account DB.
Parameters: |
|
---|
Create container table which is specific to the account DB.
Parameters: | conn – DB connection object |
---|
Check if the account DB is empty.
Returns: | True if the database has no active containers. |
---|
Get the put_timestamp of a container.
Parameters: | container_name – container name |
---|---|
Returns: | put_timestamp of the container |
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 |
---|
Check if the account DB is considered to be deleted.
Returns: | True if the account DB is considered to be deleted, False otherwise |
---|
Only returns true if the status field is set to DELETED.
Get a list of containerss 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: |
|
---|---|
Returns: | list of tuples of (name, object_count, bytes_used, 0) |
Merge items into the container table.
Parameters: |
|
---|
Create a container with the given attributes.
Parameters: |
|
---|
Delete rows from the container table that are marked deleted and whose created_at timestamp is < container_timestamp. Also deletes rows from incoming_sync and outgoing_sync where the updated_at timestamp is < sync_timestamp.
In addition, this calls the DatabaseBroker’s :func:_reclaim method.
Parameters: |
|
---|
Update the put_timestamp. Only modifies it if it is greater than the current timestamp.
Parameters: | timestamp – put timestamp |
---|
Timeout for trying to connect to a DB
Bases: swift.common.db.DatabaseBroker
Encapsulates working with a container database.
Create the container_stat table which is specific to the container DB.
Parameters: |
|
---|
Create the object table which is specifc to the container DB.
Parameters: | conn – DB connection object |
---|
Mark an object deleted.
Parameters: |
|
---|
Check if the DB is empty.
Returns: | True if the database has no active objects, False otherwise |
---|
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. If include_metadata is set, metadata is included as a key pointing to a dict of tuples of the metadata |
---|
Check if the DB is considered to be deleted.
Returns: | True if the DB is considered to be deleted, False otherwise |
---|
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: |
|
---|---|
Returns: | list of tuples of (name, created_at, size, content_type, etag) |
Merge items into the object table.
Parameters: |
|
---|
Creates an object in the DB with its metadata.
Parameters: |
|
---|
Delete rows from the object table that are marked deleted and whose created_at timestamp is < object_timestamp. Also deletes rows from incoming_sync and outgoing_sync where the updated_at timestamp is < sync_timestamp.
In addition, this calls the DatabaseBroker’s :func:_reclaim method.
Parameters: |
|
---|
Update reported stats.
Parameters: |
|
---|
Update the put_timestamp. Only modifies it if it is greater than the current timestamp.
Parameters: | timestamp – put timestamp |
---|
Whether calls will be made to preallocate disk space for database files.
Bases: object
Encapsulates working with a database.
Mark the DB as deleted
Parameters: | timestamp – delete timestamp |
---|
Use with the “with” statement; returns a database connection.
Get a list of objects in the database between start and end.
Parameters: |
|
---|---|
Returns: | list of objects between start and end |
Get information about the DB required for replication.
Returns: | dict containing keys: hash, id, created_at, put_timestamp, delete_timestamp, count, max_row, and metadata |
---|
Gets the most recent sync point for a server from the sync table.
Parameters: |
|
---|---|
Returns: | the sync point, or -1 if the id doesn’t exist. |
Get a serialized copy of the sync table.
Parameters: | incoming – if True, get the last incoming sync, otherwise get the last outgoing sync |
---|---|
Returns: | list of {‘remote_id’, ‘sync_point’} |
Create the DB
Parameters: | put_timestamp – timestamp of initial PUT request |
---|
Use with the “with” statement; locks a database.
Merge a list of sync points with the incoming sync table.
Parameters: |
|
---|
Used in replication to handle updating timestamps.
Parameters: |
|
---|
Returns the metadata dict for the database. The metadata dict values are tuples of (value, timestamp) where the timestamp indicates when that key was set to that value.
Re-id the database. This should be called after an rsync.
Parameters: | remote_id – the ID of the remote database being rsynced in |
---|
Checks the exception info to see if it indicates a quarantine situation (malformed or corrupted database). If not, the original exception will be reraised. If so, the database will be quarantined and a new sqlite3.DatabaseError will be raised indicating the action taken.
Removes any empty metadata values older than the timestamp
Updates the metadata dict for the database. The metadata dict values are tuples of (value, timestamp) where the timestamp indicates when that key was set to that value. Key/values will only be overwritten if the timestamp is newer. To delete a key, set its value to (‘’, timestamp). These empty keys will eventually be removed by :func:reclaim
Bases: sqlite3.DatabaseError
More friendly error messages for DB Errors.
Bases: sqlite3.Connection
SQLite DB Connection handler that plays well with eventlet.
Max number of pending entries
Pickle protocol to use
Each entry in the account and container databases is XORed by the 128-bit hash on insert or delete. This serves as a rolling, order-independent hash of the contents. (check + XOR)
Parameters: |
|
---|---|
Returns: | a hex representation of the new hash value |
This should only be used when you need a real dict, i.e. when you’re going to serialize the results.
Returns a properly configured SQLite database connection.
Parameters: |
|
---|---|
Returns: | DB connection object |
Bases: swift.common.bufferedhttp.BufferedHTTPConnection
Helper to simplify REPLICATEing to a remote server.
Make an HTTP REPLICATE request
Parameters: | args – list of json-encodable objects |
---|---|
Returns: | httplib response object |
Bases: swift.common.daemon.Daemon
Implements the logic for directing db replication.
Extract the device name from an object path. Returns “UNKNOWN” if the path could not be extracted successfully for some reason.
Parameters: | object_file – the path to a database file. |
---|
Generator to walk the data dirs in a round robin manner, evenly hitting each device on the system.
Parameters: | datadirs – a list of paths to walk |
---|
Replicate dbs under the given root in an infinite loop.
Run a replication pass once.
Bases: object
Handle Replication RPC calls. TODO(redbo): document please :)
In the case that a corrupt file is found, move it to a quarantined area to allow replication to fix it.
Parameters: |
|
---|