Commit cf6c6f3c authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

pithos: Fix container quota violation control

Pithos backend before performing the quota violation checks
creates a new version of object and updates the
usage of the ancestor nodes (the container).

In Postgresql SELECT does see the effects
of previous updates executed within its own transaction
even though they are not yet committed.
(regardless of the Transaction Isolation Level)
http://www.postgresql.org/docs/8.4/static/transaction-iso.html

As a result, during the quota checks the backend sees
the updated usage of the container,
so it should not add to this the size difference.
parent 7fd0d111
......@@ -875,6 +875,7 @@ class ModularBackend(BaseBackend):
account_path, account_node = self._lookup_account(account, True)
container_path, container_node = self._lookup_container(
account, container)
path, node = self._put_object_node(
container_path, container_node, name)
pre_version_id, dest_version_id = self._put_version_duplicate(user, node, src_node=src_node, size=size, type=type, hash=hash, checksum=checksum, is_copy=is_copy)
......@@ -887,30 +888,35 @@ class ModularBackend(BaseBackend):
del_size = self._apply_versioning(account, container, pre_version_id)
size_delta = size - del_size
if not self.using_external_quotaholder: # Check account quota.
if size_delta > 0:
if size_delta > 0:
# Check account quota.
if not self.using_external_quotaholder:
account_quota = long(
self._get_policy(account_node, is_account_policy=True
)['quota']
)
account_usage = self._get_statistics(account_node)[1] + size_delta
account_usage = self._get_statistics(account_node)[1]
if (account_quota > 0 and account_usage > account_quota):
raise QuotaError('account quota exceeded: limit: %s, usage: %s' % (
account_quota, account_usage
))
# Check container quota.
container_quota = long(
self._get_policy(container_node, is_account_policy=False
)['quota']
)
container_usage = self._get_statistics(container_node)[1] + size_delta
if (container_quota > 0 and container_usage > container_quota):
# This must be executed in a transaction, so the version is
# never created if it fails.
raise QuotaError('container quota exceeded: limit: %s, usage: %s' % (
container_quota, container_usage
))
raise QuotaError(
'Account quota exceeded: limit: %s, usage: %s' % (
account_quota, account_usage
)
)
# Check container quota.
container_quota = long(
self._get_policy(container_node, is_account_policy=False
)['quota']
)
container_usage = self._get_statistics(container_node)[1]
if (container_quota > 0 and container_usage > container_quota):
# This must be executed in a transaction, so the version is
# never created if it fails.
raise QuotaError(
'Container quota exceeded: limit: %s, usage: %s' % (
container_quota, container_usage
)
)
self._report_size_change(user, account, size_delta,
{'action': 'object update', 'path': path,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment