Include account and container usage information in case of exceeded quota
[pithos] / snf-pithos-backend / pithos / backends / modular.py
index 0d7595b..82cdfe1 100644 (file)
@@ -93,6 +93,7 @@ ULTIMATE_ANSWER = 42
 logger = logging.getLogger(__name__)
 
 
+
 def backend_method(func=None, autocommit=1):
     if func is None:
         def fn(func):
@@ -735,12 +736,29 @@ class ModularBackend(BaseBackend):
         del_size = self._apply_versioning(account, container, pre_version_id)
         size_delta = size - del_size
         if size_delta > 0:
+            #check account quota
             account_quota = long(self._get_policy(account_node)['quota'])
+            account_usage = self._get_statistics(account_node)[1]
+            if (account_quota > 0 and account_usage + size_delta > account_quota):
+                       msg = """account_quota:%d, account_usage:%d, size:%d,
+                                        del_size:%d, pre_version_id:%d""" % (account_quota,
+                                                                                                                 account_usage,
+                                                                                                                 size, del_size,
+                                                                                                                 pre_version_id)
+                # This must be executed in a transaction, so the version is never created if it fails.
+                raise QuotaError(msg)
+            
+            #check container quota
             container_quota = long(self._get_policy(container_node)['quota'])
-            if (account_quota > 0 and self._get_statistics(account_node)[1] + size_delta > account_quota) or \
-               (container_quota > 0 and self._get_statistics(container_node)[1] + size_delta > container_quota):
+            container_usage = self._get_statistics(container_node)[1]
+            if (container_quota > 0 and container_usage + size_delta > container_quota):
+                       msg = """container_quota:%d, container_usage:%d, size:%d,
+                                        del_size:%d, pre_version_id:%d""" % (container_quota,
+                                                                                                                 container_usage,
+                                                                                                                         size, del_size,
+                                                                                                                         pre_version_id)
                 # This must be executed in a transaction, so the version is never created if it fails.
-                raise QuotaError
+                raise QuotaError(msg)
         self._report_size_change(user, account, size_delta, {'action': 'object update', 'path':path})
         
         if permissions is not None: