Commit 98dc5f1e authored by Julien Muchembled's avatar Julien Muchembled Committed by Julien Muchembled

Use weakref.WeakSet rather than transaction.weakset.WeakSet

parent f60d4208
...@@ -20,12 +20,13 @@ import logging ...@@ -20,12 +20,13 @@ import logging
import datetime import datetime
import time import time
import warnings import warnings
import weakref
from itertools import chain
from persistent.TimeStamp import TimeStamp from persistent.TimeStamp import TimeStamp
import six import six
import transaction import transaction
import transaction.weakset
from zope.interface import implementer from zope.interface import implementer
...@@ -77,7 +78,7 @@ class AbstractConnectionPool(object): ...@@ -77,7 +78,7 @@ class AbstractConnectionPool(object):
# A weak set of all connections we've seen. A connection vanishes # A weak set of all connections we've seen. A connection vanishes
# from this set if pop() hands it out, it's not reregistered via # from this set if pop() hands it out, it's not reregistered via
# repush(), and it becomes unreachable. # repush(), and it becomes unreachable.
self.all = transaction.weakset.WeakSet() self.all = weakref.WeakSet()
def setSize(self, size): def setSize(self, size):
"""Change our belief about the expected maximum # of live connections. """Change our belief about the expected maximum # of live connections.
...@@ -120,6 +121,9 @@ class ConnectionPool(AbstractConnectionPool): ...@@ -120,6 +121,9 @@ class ConnectionPool(AbstractConnectionPool):
# in this stack. # in this stack.
self.available = [] self.available = []
def __iter__(self):
return iter(self.all)
def _append(self, c): def _append(self, c):
available = self.available available = self.available
cactive = c._cache.cache_non_ghost_count cactive = c._cache.cache_non_ghost_count
...@@ -205,10 +209,6 @@ class ConnectionPool(AbstractConnectionPool): ...@@ -205,10 +209,6 @@ class ConnectionPool(AbstractConnectionPool):
assert result in self.all assert result in self.all
return result return result
def map(self, f):
"""For every live connection c, invoke f(c)."""
self.all.map(f)
def availableGC(self): def availableGC(self):
"""Perform garbage collection on available connections. """Perform garbage collection on available connections.
...@@ -248,6 +248,9 @@ class KeyedConnectionPool(AbstractConnectionPool): ...@@ -248,6 +248,9 @@ class KeyedConnectionPool(AbstractConnectionPool):
super(KeyedConnectionPool, self).__init__(size, timeout) super(KeyedConnectionPool, self).__init__(size, timeout)
self.pools = {} self.pools = {}
def __iter__(self):
return chain(*self.pools.values())
def setSize(self, v): def setSize(self, v):
self._size = v self._size = v
for pool in self.pools.values(): for pool in self.pools.values():
...@@ -281,10 +284,6 @@ class KeyedConnectionPool(AbstractConnectionPool): ...@@ -281,10 +284,6 @@ class KeyedConnectionPool(AbstractConnectionPool):
if pool is not None: if pool is not None:
return pool.pop() return pool.pop()
def map(self, f):
for pool in six.itervalues(self.pools):
pool.map(f)
def availableGC(self): def availableGC(self):
for key, pool in list(self.pools.items()): for key, pool in list(self.pools.items()):
pool.availableGC() pool.availableGC()
...@@ -296,20 +295,6 @@ class KeyedConnectionPool(AbstractConnectionPool): ...@@ -296,20 +295,6 @@ class KeyedConnectionPool(AbstractConnectionPool):
pool.clear() pool.clear()
self.pools.clear() self.pools.clear()
@property
def test_all(self):
result = set()
for pool in six.itervalues(self.pools):
result.update(pool.all)
return frozenset(result)
@property
def test_available(self):
result = []
for pool in six.itervalues(self.pools):
result.extend(pool.available)
return tuple(result)
def toTimeStamp(dt): def toTimeStamp(dt):
utc_struct = dt.utctimetuple() utc_struct = dt.utctimetuple()
...@@ -512,8 +497,10 @@ class DB(object): ...@@ -512,8 +497,10 @@ class DB(object):
"""Call f(c) for all connections c in all pools, live and historical. """Call f(c) for all connections c in all pools, live and historical.
""" """
with self._lock: with self._lock:
self.pool.map(f) for c in self.pool:
self.historical_pool.map(f) f(c)
for c in self.historical_pool:
f(c)
def cacheDetail(self): def cacheDetail(self):
"""Return object counts by class accross all connections. """Return object counts by class accross all connections.
...@@ -865,36 +852,32 @@ class DB(object): ...@@ -865,36 +852,32 @@ class DB(object):
""" """
with self._lock: with self._lock:
self._cache_size = size self._cache_size = size
def setsize(c): for c in self.pool:
c._cache.cache_size = size c._cache.cache_size = size
self.pool.map(setsize)
def setCacheSizeBytes(self, size): def setCacheSizeBytes(self, size):
"""Reconfigure the cache total size in bytes """Reconfigure the cache total size in bytes
""" """
with self._lock: with self._lock:
self._cache_size_bytes = size self._cache_size_bytes = size
def setsize(c): for c in self.pool:
c._cache.cache_size_bytes = size c._cache.cache_size_bytes = size
self.pool.map(setsize)
def setHistoricalCacheSize(self, size): def setHistoricalCacheSize(self, size):
"""Reconfigure the historical cache size (non-ghost object count) """Reconfigure the historical cache size (non-ghost object count)
""" """
with self._lock: with self._lock:
self._historical_cache_size = size self._historical_cache_size = size
def setsize(c): for c in self.historical_pool:
c._cache.cache_size = size c._cache.cache_size = size
self.historical_pool.map(setsize)
def setHistoricalCacheSizeBytes(self, size): def setHistoricalCacheSizeBytes(self, size):
"""Reconfigure the historical cache total size in bytes """Reconfigure the historical cache total size in bytes
""" """
with self._lock: with self._lock:
self._historical_cache_size_bytes = size self._historical_cache_size_bytes = size
def setsize(c): for c in self.historical_pool:
c._cache.cache_size_bytes = size c._cache.cache_size_bytes = size
self.historical_pool.map(setsize)
def setPoolSize(self, size): def setPoolSize(self, size):
"""Reconfigure the connection pool size """Reconfigure the connection pool size
......
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