Skip to content

Conversation

ycombinator
Copy link
Contributor

This PR is a (hopefully) final attempt at providing a method to reliably delete a container along with its constituent objects. The crux of the algorithm implemented by this PR is:

  1. Get the list of objects in the container.
  2. Attempt to delete them using the batch delete API.
  3. Attempt to delete the container using the container delete API.
  4. If step 3 succeeds, we are done!
  5. If step 3 results in a 409 Conflict error (indicating that the container is not actually empty), start over with step 1.
  6. If step 3 results in a 404 Not Found error (indicating that the container is not found), we are done!

Note that the existing methods to delete a container ($container->delete()) and to delete a container along with its objects ($container->delete($deleteObjects = false)) are preserved so this change is backwards compatible.

Additionally, another method to delete a container along with its objects is also provided ($container->deleteWithObjects($secondsToWait = null)). This method takes an optional timeout in seconds during which the above algorithm must complete. If this timeout is not specified, it is estimated based on the number of objects in the container.

Fixes #477.

{
// If timeout (seconds to wait) is not specified by caller, try to
// estimate it based on number of objects in container
if (is_null($secondsToWait)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency (and AFAIK a slight performance gain), I always use: null === $secondsToWait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. Changing.

@jamiehannaford
Copy link
Contributor

Apart from the timeout thing, this LGTM 👍

jamiehannaford pushed a commit that referenced this pull request Dec 4, 2014
Reliably delete a container with its objects
@jamiehannaford jamiehannaford merged commit 1b0366a into rackspace:working Dec 4, 2014
@ycombinator ycombinator deleted the del-container-recursive branch December 4, 2014 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deleting container and objects within causes 409 Conflict error
2 participants