BACKEND_QUOTA = getattr(
settings, 'PITHOS_BACKEND_QUOTA', 50 * 1024 * 1024 * 1024)
BACKEND_VERSIONING = getattr(settings, 'PITHOS_BACKEND_VERSIONING', 'auto')
+ BACKEND_FREE_VERSIONING = getattr(settings, 'PITHOS_BACKEND_FREE_VERSIONING', True)
+PITHOS_QUOTAHOLDER_URL = getattr(settings,
+ 'PITHOS_QUOTAHOLDER_URL',
+ 'http://127.0.0.1/api/quotaholder/v')
+
# Update object checksums when using hashmaps.
UPDATE_MD5 = getattr(settings, 'PITHOS_UPDATE_MD5', True)
BACKEND_BLOCK_UMASK,
BACKEND_QUEUE_MODULE, BACKEND_QUEUE_HOSTS,
BACKEND_QUEUE_EXCHANGE,
- BACKEND_QUOTA, BACKEND_VERSIONING,
+ PITHOS_QUOTAHOLDER_URL,
- BACKEND_QUOTA, BACKEND_VERSIONING,
++ BACKEND_QUOTA, BACKEND_VERSIONING,
+ BACKEND_FREE_VERSIONING,
AUTHENTICATION_URL, AUTHENTICATION_USERS,
SERVICE_TOKEN, COOKIE_NAME)
--
from pithos.backends import connect_backend
from pithos.backends.base import NotAllowedError, QuotaError, ItemNotExists, VersionNotExists
return json.dumps(l)
-
- def _get_backend():
- backend = connect_backend(db_module=BACKEND_DB_MODULE,
- db_connection=BACKEND_DB_CONNECTION,
- block_module=BACKEND_BLOCK_MODULE,
- block_path=BACKEND_BLOCK_PATH,
- block_umask=BACKEND_BLOCK_UMASK,
- queue_module=BACKEND_QUEUE_MODULE,
- queue_hosts=BACKEND_QUEUE_HOSTS,
- queue_exchange=BACKEND_QUEUE_EXCHANGE,
- quotaholder_url=PITHOS_QUOTAHOLDER_URL)
- backend.default_policy['quota'] = BACKEND_QUOTA
- backend.default_policy['versioning'] = BACKEND_VERSIONING
- return backend
-
-
- def _pooled_backend_close(backend):
- backend._pool.pool_put(backend)
-
-
- from synnefo.lib.pool import ObjectPool
- from new import instancemethod
- from select import select
- from traceback import print_exc
-
- USAGE_LIMIT = 500
+ from pithos.backends.util import PithosBackendPool
POOL_SIZE = 5
- class PithosBackendPool(ObjectPool):
- def _pool_create(self):
- backend = _get_backend()
- backend._real_close = backend.close
- backend.close = instancemethod(_pooled_backend_close, backend,
- type(backend))
- backend._pool = self
- backend._use_count = USAGE_LIMIT
- return backend
-
- def _pool_verify(self, backend):
- wrapper = backend.wrapper
- conn = wrapper.conn
- if conn.closed:
- return False
-
- if conn.in_transaction():
- conn.close()
- return False
- try:
- fd = conn.connection.connection.fileno()
- r, w, x = select([fd], (), (), 0)
- if r:
- conn.close()
- return False
- except:
- print_exc()
- return False
-
- return True
-
- def _pool_cleanup(self, backend):
- c = backend._use_count - 1
- if c < 0:
- backend._real_close()
- return True
-
- backend._use_count = c
- wrapper = backend.wrapper
- if wrapper.trans is not None:
- conn = wrapper.conn
- if conn.closed:
- wrapper.trans = None
- else:
- wrapper.rollback()
- if backend.messages:
- backend.messages = []
- return False
-
- _pithos_backend_pool = PithosBackendPool(size=POOL_SIZE)
+ _pithos_backend_pool = PithosBackendPool(size=POOL_SIZE,
+ db_module=BACKEND_DB_MODULE,
+ db_connection=BACKEND_DB_CONNECTION,
+ block_module=BACKEND_BLOCK_MODULE,
+ block_path=BACKEND_BLOCK_PATH,
+ block_umask=BACKEND_BLOCK_UMASK,
+ queue_module=BACKEND_QUEUE_MODULE,
+ queue_hosts=BACKEND_QUEUE_HOSTS,
+ queue_exchange=BACKEND_QUEUE_EXCHANGE,
++ quotaholder_url=PITHOS_QUOTAHOLDER_URL,
+ free_versioning=BACKEND_FREE_VERSIONING)
def get_backend():
def fn(self, *args, **kw):
self.wrapper.execute()
+ serials = []
+ self.serials = serials
+ self.messages = []
++
try:
- self.messages = []
ret = func(self, *args, **kw)
for m in self.messages:
self.queue.send(*m)
def __init__(self, db_module=None, db_connection=None,
block_module=None, block_path=None, block_umask=None,
queue_module=None, queue_hosts=None,
- queue_exchange=None, quotaholder_url=None):
- queue_exchange=None,
++ queue_exchange=None, quotaholder_url=None,
+ free_versioning=True):
db_module = db_module or DEFAULT_DB_MODULE
db_connection = db_connection or DEFAULT_DB_CONNECTION
block_module = block_module or DEFAULT_BLOCK_MODULE
--- /dev/null
+ # Copyright 2011-2012 GRNET S.A. All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or
+ # without modification, are permitted provided that the following
+ # conditions are met:
+ #
+ # 1. Redistributions of source code must retain the above
+ # copyright notice, this list of conditions and the following
+ # disclaimer.
+ #
+ # 2. Redistributions in binary form must reproduce the above
+ # copyright notice, this list of conditions and the following
+ # disclaimer in the documentation and/or other materials
+ # provided with the distribution.
+ #
+ # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+ #
+ # The views and conclusions contained in the software and
+ # documentation are those of the authors and should not be
+ # interpreted as representing official policies, either expressed
+ # or implied, of GRNET S.A.
+
+ from synnefo.lib.pool import ObjectPool
+ from new import instancemethod
+ from select import select
+ from traceback import print_exc
+ from pithos.backends import connect_backend
+
+ USAGE_LIMIT = 500
+
+
+ class PithosBackendPool(ObjectPool):
+ def __init__(self, size=None, db_module=None, db_connection=None,
+ block_module=None, block_path=None, block_umask=None,
+ queue_module=None, queue_hosts=None,
- queue_exchange=None,
++ queue_exchange=None, quotaholder_url=None,
+ free_versioning=True):
+ super(PithosBackendPool, self).__init__(size=size)
+ self.db_module = db_module
+ self.db_connection = db_connection
+ self.block_module = block_module
+ self.block_path = block_path
+ self.block_umask = block_umask
+ self.queue_module = queue_module
+ self.queue_hosts = queue_hosts
+ self.queue_exchange = queue_exchange
++ self.quotaholder_url = quotaholder_url
+ self.free_versioning = free_versioning
+
+ def _pool_create(self):
+ backend = connect_backend(db_module=self.db_module,
+ db_connection=self.db_connection,
+ block_module=self.block_module,
+ block_path=self.block_path,
+ block_umask=self.block_umask,
+ queue_module=self.queue_module,
+ queue_hosts=self.queue_hosts,
+ queue_exchange=self.queue_exchange,
++ quotaholder_url=self.quotaholder_url,
+ free_versioning=self.free_versioning)
+
+ backend._real_close = backend.close
+ backend.close = instancemethod(_pooled_backend_close, backend,
+ type(backend))
+ backend._pool = self
+ backend._use_count = USAGE_LIMIT
+ return backend
+
+ def _pool_verify(self, backend):
+ wrapper = backend.wrapper
+ conn = wrapper.conn
+ if conn.closed:
+ return False
+
+ if conn.in_transaction():
+ conn.close()
+ return False
+
+ try:
+ fd = conn.connection.connection.fileno()
+ r, w, x = select([fd], (), (), 0)
+ if r:
+ conn.close()
+ return False
+ except:
+ print_exc()
+ return False
+
+ return True
+
+ def _pool_cleanup(self, backend):
+ c = backend._use_count - 1
+ if c < 0:
+ backend._real_close()
+ return True
+
+ backend._use_count = c
+ wrapper = backend.wrapper
+ if wrapper.trans is not None:
+ conn = wrapper.conn
+ if conn.closed:
+ wrapper.trans = None
+ else:
+ wrapper.rollback()
+ if backend.messages:
+ backend.messages = []
+ return False
+
+
+ def _pooled_backend_close(backend):
+ backend._pool.pool_put(backend)