Revision 761c2b3c snf-pithos-app/pithos/api/util.py
b/snf-pithos-app/pithos/api/util.py | ||
---|---|---|
56 | 56 |
RangeNotSatisfiable, InternalServerError, NotImplemented) |
57 | 57 |
from pithos.api.short_url import encode_url |
58 | 58 |
from pithos.api.settings import (BACKEND_DB_MODULE, BACKEND_DB_CONNECTION, |
59 |
BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH, |
|
60 |
BACKEND_BLOCK_UMASK, |
|
61 |
BACKEND_QUEUE_MODULE, BACKEND_QUEUE_CONNECTION, |
|
62 |
BACKEND_QUOTA, BACKEND_VERSIONING, |
|
63 |
AUTHENTICATION_URL, AUTHENTICATION_USERS, |
|
64 |
SERVICE_TOKEN, COOKIE_NAME) |
|
59 |
BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH, |
|
60 |
BACKEND_BLOCK_UMASK, |
|
61 |
BACKEND_QUEUE_MODULE, BACKEND_QUEUE_HOSTS, |
|
62 |
BACKEND_QUEUE_EXCHANGE, |
|
63 |
PITHOS_QUOTAHOLDER_URL, |
|
64 |
BACKEND_QUOTA, BACKEND_VERSIONING, |
|
65 |
AUTHENTICATION_URL, AUTHENTICATION_USERS, |
|
66 |
SERVICE_TOKEN, COOKIE_NAME) |
|
65 | 67 |
|
66 | 68 |
from pithos.backends import connect_backend |
67 | 69 |
from pithos.backends.base import NotAllowedError, QuotaError, ItemNotExists, VersionNotExists |
... | ... | |
808 | 810 |
|
809 | 811 |
from synnefo.lib.pool import ObjectPool |
810 | 812 |
from new import instancemethod |
813 |
from select import select |
|
814 |
from traceback import print_exc |
|
811 | 815 |
|
812 | 816 |
USAGE_LIMIT = 500 |
813 | 817 |
POOL_SIZE = 5 |
... | ... | |
823 | 827 |
return backend |
824 | 828 |
|
825 | 829 |
def _pool_verify(self, backend): |
826 |
return 1 |
|
830 |
wrapper = backend.wrapper |
|
831 |
conn = wrapper.conn |
|
832 |
if conn.closed: |
|
833 |
return False |
|
834 |
|
|
835 |
if conn.in_transaction(): |
|
836 |
conn.close() |
|
837 |
return False |
|
838 |
|
|
839 |
try: |
|
840 |
fd = conn.connection.connection.fileno() |
|
841 |
r, w, x = select([fd], (), (), 0) |
|
842 |
if r: |
|
843 |
conn.close() |
|
844 |
return False |
|
845 |
except: |
|
846 |
print_exc() |
|
847 |
return False |
|
848 |
|
|
849 |
return True |
|
827 | 850 |
|
828 | 851 |
def _pool_cleanup(self, backend): |
829 | 852 |
c = backend._use_count - 1 |
... | ... | |
832 | 855 |
return True |
833 | 856 |
|
834 | 857 |
backend._use_count = c |
835 |
if backend.wrapper.trans is not None: |
|
836 |
backend.wrapper.rollback() |
|
858 |
wrapper = backend.wrapper |
|
859 |
if wrapper.trans is not None: |
|
860 |
conn = wrapper.conn |
|
861 |
if conn.closed: |
|
862 |
wrapper.trans = None |
|
863 |
else: |
|
864 |
wrapper.rollback() |
|
837 | 865 |
if backend.messages: |
838 | 866 |
backend.messages = [] |
839 | 867 |
return False |
Also available in: Unified diff