OpenStack Storage (Swift)
Go to file
Samuel Merritt 1c88d2cb81 Fix up get_account_info and get_container_info
get_account_info used to work like this:

  * make an account HEAD request

  * ignore the response

  * get the account info by digging around in the request environment,
    where it had been deposited by elves or something

Not actually elves, but the proxy's GETorHEAD_base method would take
the HEAD response and cache it in the response environment, which was
the same object as the request environment, thus enabling
get_account_info to find it.

This was extraordinarily brittle. If a WSGI middleware were to
shallow-copy the request environment, then any middlewares to its left
could not use get_account_info, as the left middleware's request
environment would no longer be identical to the response environment
down in GETorHEAD_base.

Now, get_account_info works like this:

  * make an account HEAD request.

  * if the account info is in the request environment, return it. This
    is an optimization to avoid a double-set in memcached.

  * else, compute the account info from the response headers, store it
    in caches, and return it.

This is much easier to think about; get_account_info can get and cache
account info all on its own; the cache check and cache set are right
next to each other.

All the above is true for get_container_info as well.

get_info() is still around, but it's just a shim. It was trying to
unify get_account_info and get_container_info to exploit the
commonalities, but the number of times that "if container:" showed up
in get_info and its helpers really indicated that something was
wrong. I'd rather have two functions with some duplication than one
function with no duplication but a bunch of "if container:" branches.

Other things of note:

  * a HEAD request to a deleted account returns 410, but
    get_account_info would return 404 since the 410 came from the
    account controller *after* GETorHEAD_base ran. Now
    get_account_info returns 410 as well.

  * cache validity period (recheck_account_existence and
    recheck_container_existence) is now communicated to
    get_account_info via an X-Backend header. This way,
    get_account_info doesn't need a reference to the
    swift.proxy.server.Application object.

  * both logged swift_source values are now correct for
    get_container_info calls; before, on a cold cache,
    get_container_info would call get_account_info but not pass along
    swift_source, resulting in get_account_info logging "GET_INFO" as
    the source. Amusingly, there was a unit test asserting this bogus
    behavior.

  * callers that modify the return value of get_account_info or of
    get_container_info don't modify what's stored in swift.infocache.

  * get_account_info on an account that *can* be autocreated but has
    not been will return a 200, same as a HEAD request. The old
    behavior was a 404 from get_account_info but a 200 from
    HEAD. Callers can tell the difference by looking at
    info['account_really_exists'] if they need to know the difference
    (there is one call site that needs to know, in container
    PUT). Note: this is for all accounts when the proxy's
    "account_autocreate" setting is on.

Change-Id: I5167714025ec7237f7e6dd4759c2c6eb959b3fca
2016-05-13 10:40:56 -07:00
bin Merge "swift-[account|container]-info when disk is full" 2016-04-22 17:31:09 +00:00
doc Merge "Allow fallocate_reserve to be a percentage" 2016-05-12 08:18:39 +00:00
etc Merge "Allow fallocate_reserve to be a percentage" 2016-05-12 08:18:39 +00:00
examples Add a user variable to templates 2013-09-17 11:46:04 +10:00
swift Fix up get_account_info and get_container_info 2016-05-13 10:40:56 -07:00
test Fix up get_account_info and get_container_info 2016-05-13 10:40:56 -07:00
.alltests Script for running unit, func and probe tests at once 2015-10-13 09:10:09 +02:00
.coveragerc Fix .coveragrc to prevent nose tests error 2015-09-21 10:06:29 +01:00
.functests Modify functional tests to use ostestr/testr 2015-12-15 22:30:44 +00:00
.gitignore Add .eggs/* to .gitignore 2016-03-22 11:53:49 +00:00
.gitreview Add .gitreview config file for gerrit. 2011-10-24 15:05:49 -04:00
.mailmap Update mailmap, resolve identity crisis 2016-04-29 05:00:36 -05:00
.manpages Script for checking sanity of manpages 2016-02-10 14:16:56 -08:00
.probetests Allow specify arguments to .probetests script 2013-12-24 01:18:19 -08:00
.testr.conf Fix func test --until-failure and --no-discover options 2015-12-16 15:28:25 +00:00
.unittests Fix coverage report for newer versions of coverage 2014-04-24 16:50:03 +00:00
AUTHORS 2.7.0 authors and changelog updates 2016-03-23 15:26:41 -07:00
babel.cfg add pybabel setup.py commands and initial .pot 2011-01-27 00:01:24 +00:00
bandit.yaml Adding bandit for security static analysis testing in swift 2015-07-31 07:37:33 +05:30
CHANGELOG 2.7.0 authors and changelog updates 2016-03-23 15:26:41 -07:00
CONTRIBUTING.rst Rework the contributor docs 2016-05-05 22:02:47 -07:00
LICENSE Convert LICENSE to use unix style line endings. 2012-12-19 12:48:27 -05:00
MANIFEST.in Convert README.md to README.rst 2016-04-12 17:46:56 -05:00
README.rst Rework the contributor docs 2016-05-05 22:02:47 -07:00
requirements.txt Bump PyECLib requirement to >= 1.2.0 2016-02-12 15:00:46 +00:00
REVIEW_GUIDELINES.rst Fix minor typos in review guidelines 2016-04-29 04:01:39 -05:00
setup.cfg Refactor server side copy as middleware 2016-05-11 14:55:51 -04:00
setup.py taking the global reqs that we can 2014-05-21 09:37:22 -07:00
test-requirements.txt Modify functional tests to use ostestr/testr 2015-12-15 22:30:44 +00:00
tox.ini Merge "clear pycache and remove all pyc/pyo before starting unit test" 2016-03-16 11:38:22 +00:00

Swift

A distributed object storage system designed to scale from a single machine to thousands of servers. Swift is optimized for multi-tenancy and high concurrency. Swift is ideal for backups, web and mobile content, and any other unstructured data that can grow without bound.

Swift provides a simple, REST-based API fully documented at http://docs.openstack.org/.

Swift was originally developed as the basis for Rackspace's Cloud Files and was open-sourced in 2010 as part of the OpenStack project. It has since grown to include contributions from many companies and has spawned a thriving ecosystem of 3rd party tools. Swift's contributors are listed in the AUTHORS file.

Docs

To build documentation install sphinx (pip install sphinx), run python setup.py build_sphinx, and then browse to /doc/build/html/index.html. These docs are auto-generated after every commit and available online at http://docs.openstack.org/developer/swift/.

For Developers

Getting Started

Swift is part of OpenStack and follows the code contribution, review, and testing processes common to all OpenStack projects.

If you would like to start contributing, check out these notes to help you get started.

The best place to get started is the "SAIO - Swift All In One". This document will walk you through setting up a development cluster of Swift in a VM. The SAIO environment is ideal for running small-scale tests against swift and trying out new features and bug fixes.

Tests

There are three types of tests included in Swift's source tree.

  1. Unit tests
  2. Functional tests
  3. Probe tests

Unit tests check that small sections of the code behave properly. For example, a unit test may test a single function to ensure that various input gives the expected output. This validates that the code is correct and regressions are not introduced.

Functional tests check that the client API is working as expected. These can be run against any endpoint claiming to support the Swift API (although some tests require multiple accounts with different privilege levels). These are "black box" tests that ensure that client apps written against Swift will continue to work.

Probe tests are "white box" tests that validate the internal workings of a Swift cluster. They are written to work against the "SAIO - Swift All In One" dev environment. For example, a probe test may create an object, delete one replica, and ensure that the background consistency processes find and correct the error.

You can run unit tests with .unittests, functional tests with .functests, and probe tests with .probetests. There is an additional .alltests script that wraps the other three.

Code Organization

  • bin/: Executable scripts that are the processes run by the deployer
  • doc/: Documentation
  • etc/: Sample config files
  • examples/: Config snippets used in the docs
  • swift/: Core code
    • account/: account server
    • cli/: code that backs some of the CLI tools in bin/
    • common/: code shared by different modules
      • middleware/: "standard", officially-supported middleware
      • ring/: code implementing Swift's ring
    • container/: container server
    • locale/: internationalization (translation) data
    • obj/: object server
    • proxy/: proxy server
  • test/: Unit, functional, and probe tests

Data Flow

Swift is a WSGI application and uses eventlet's WSGI server. After the processes are running, the entry point for new requests is the Application class in swift/proxy/server.py. From there, a controller is chosen, and the request is processed. The proxy may choose to forward the request to a back- end server. For example, the entry point for requests to the object server is the ObjectController class in swift/obj/server.py.

For Deployers

Deployer docs are also available at http://docs.openstack.org/developer/swift/. A good starting point is at http://docs.openstack.org/developer/swift/deployment\_guide.html

There is an ops runbook that gives information about how to diagnose and troubleshoot common issues when running a Swift cluster.

You can run functional tests against a swift cluster with .functests. These functional tests require /etc/swift/test.conf to run. A sample config file can be found in this source tree in test/sample.conf.

For Client Apps

For client applications, official Python language bindings are provided at http://github.com/openstack/python-swiftclient.

Complete API documentation at http://docs.openstack.org/api/openstack-object-storage/1.0/content/

There is a large ecosystem of applications and libraries that support and work with OpenStack Swift. Several are listed on the associated projects page.


For more information come hang out in #openstack-swift on freenode.

Thanks,

The Swift Development Team