diff --git a/src/ZODB/DB.py b/src/ZODB/DB.py index 38a9edb6b..084b5f273 100644 --- a/src/ZODB/DB.py +++ b/src/ZODB/DB.py @@ -20,12 +20,13 @@ import datetime import time import warnings +import weakref +from itertools import chain from persistent.TimeStamp import TimeStamp import six import transaction -import transaction.weakset from zope.interface import implementer @@ -77,7 +78,7 @@ def __init__(self, size, timeout): # 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 # repush(), and it becomes unreachable. - self.all = transaction.weakset.WeakSet() + self.all = weakref.WeakSet() def setSize(self, size): """Change our belief about the expected maximum # of live connections. @@ -120,6 +121,9 @@ def __init__(self, size, timeout=1<<31): # in this stack. self.available = [] + def __iter__(self): + return iter(self.all) + def _append(self, c): available = self.available cactive = c._cache.cache_non_ghost_count @@ -205,10 +209,6 @@ def pop(self): assert result in self.all return result - def map(self, f): - """For every live connection c, invoke f(c).""" - self.all.map(f) - def availableGC(self): """Perform garbage collection on available connections. @@ -248,6 +248,9 @@ def __init__(self, size, timeout=1<<31): super(KeyedConnectionPool, self).__init__(size, timeout) self.pools = {} + def __iter__(self): + return chain(*self.pools.values()) + def setSize(self, v): self._size = v for pool in self.pools.values(): @@ -281,10 +284,6 @@ def pop(self, key): if pool is not None: return pool.pop() - def map(self, f): - for pool in six.itervalues(self.pools): - pool.map(f) - def availableGC(self): for key, pool in list(self.pools.items()): pool.availableGC() @@ -296,20 +295,6 @@ def clear(self): pool.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): utc_struct = dt.utctimetuple() @@ -512,8 +497,10 @@ def _connectionMap(self, f): """Call f(c) for all connections c in all pools, live and historical. """ with self._lock: - self.pool.map(f) - self.historical_pool.map(f) + for c in self.pool: + f(c) + for c in self.historical_pool: + f(c) def cacheDetail(self): """Return object counts by class accross all connections. @@ -865,36 +852,32 @@ def setCacheSize(self, size): """ with self._lock: self._cache_size = size - def setsize(c): + for c in self.pool: c._cache.cache_size = size - self.pool.map(setsize) def setCacheSizeBytes(self, size): """Reconfigure the cache total size in bytes """ with self._lock: self._cache_size_bytes = size - def setsize(c): + for c in self.pool: c._cache.cache_size_bytes = size - self.pool.map(setsize) def setHistoricalCacheSize(self, size): """Reconfigure the historical cache size (non-ghost object count) """ with self._lock: self._historical_cache_size = size - def setsize(c): + for c in self.historical_pool: c._cache.cache_size = size - self.historical_pool.map(setsize) def setHistoricalCacheSizeBytes(self, size): """Reconfigure the historical cache total size in bytes """ with self._lock: self._historical_cache_size_bytes = size - def setsize(c): + for c in self.historical_pool: c._cache.cache_size_bytes = size - self.historical_pool.map(setsize) def setPoolSize(self, size): """Reconfigure the connection pool size