mò Tã¸Ec@sSdZdkZdkZdkZdkZdklZlZdkZdkl Z dk l Z dk l Z dklZdk lZdklZd klZdkZeid ƒZd efd „ƒYZd efd„ƒYZeiƒZdadefd„ƒYZdefd„ƒYZdefd„ƒYZ defd„ƒYZ!dS(s=Database objects $Id: DB.py 69549 2006-08-15 23:35:21Z jim $N(stimesctime(s find_global(sz64(s Connection(s referencesf(sWeakSet(s implements(s IDatabasesZODB.DBt_ConnectionPoolcBsPtZdZd„Zd„Zd„Zd„Zed„Zd„Z d„Z RS(stManage a pool of connections. CAUTION: Methods should be called under the protection of a lock. This class does no locking of its own. There's no limit on the number of connections this can keep track of, but a warning is logged if there are more than pool_size active connections, and a critical problem if more than twice pool_size. New connections are registered via push(). This will log a message if "too many" connections are active. When a connection is explicitly closed, tell the pool via repush(). That adds the connection to a stack of connections available for reuse, and throws away the oldest stack entries if the stack is too large. pop() pops this stack. When a connection is obtained via pop(), the pool holds only a weak reference to it thereafter. It's not necessary to inform the pool if the connection goes away. A connection handed out by pop() counts against pool_size only so long as it exists, and provided it isn't repush()'ed. A weak reference is retained so that DB methods like connectionDebugInfo() can still gather statistics. cCs"||_tƒ|_g|_dS(N(t pool_sizetselftWeakSettallt available(RR((t&/data/zmath/zope/lib/python/ZODB/DB.pyt__init__>s  cCs||_|iƒdS(N(RRt _reduce_size(RR((Rt set_pool_sizeSs cCsÃ||ijpt‚||ijpt‚|idtƒ|ii|ƒ|ii|ƒt |iƒ|i }}||jo;t i}|d|jo t i}n|d||ƒndS(Nt strictly_lessis8DB.open() has %s open connections with a pool_size of %s(tcRRtAssertionErrorRRtTruetaddtappendtlenRtntlimittloggertwarntreportertcritical(RR RRR((RtpushZs   cCsR||ijpt‚||ijpt‚|idtƒ|ii|ƒdS(NR (R RRR RRR R(RR ((RtrepushkscCsa|it|ƒ}xGt|iƒ|jo0|iidƒ}|i i |ƒ|i ƒqWdS(Ni( RRtboolR ttargetRRtpopR Rtremovet _resetCache(RR R R((RRts  cCs>d}|io*|iiƒ}||ijpt‚n|S(N(tNonetresultRRRRR (RR((RR‹s  cCs|ii|ƒdS(N(RRtmaptf(RR!((RR •s( t__name__t __module__t__doc__RR RRtFalseRRR (((RR$s      tDBcBs³tZdZeeƒeZeZddddded„Z d„Z d„Z ed „Z d „Z d „Zd „Zd „Zd„Zd„Zd„Zd„Zded„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zedd„Zd„Zd„Zd„Z de!ee!d„Z"d „Z#d!„Z$d"„Z%ed#d$„Z&d%„Z'd&„Z(d'„Z)d(„Z*d)„Z+d*„Z,e-d+„Z.ed,„Z/d-„Z0RS(.sFThe Object Database ------------------- The DB class coordinates the activities of multiple database Connection instances. Most of the work is done by the Connections created via the open method. The DB instance manages a pool of connections. If a connection is closed, it is returned to the pool and its object cache is preserved. A subsequent call to open() will reuse the connection. There is no hard limit on the pool size. If more than `pool_size` connections are opened, a warning is logged, and if more than twice that many, a critical problem is logged. The class variable 'klass' is used by open() to create database connections. It is set to Connection, but a subclass could override it to provide a different connection implementation. The database provides a few methods intended for application code -- open, close, undo, and pack -- and a large collection of methods for inspecting the database and its connections' caches. :Cvariables: - `klass`: Class used by L{open} to create database connections :Groups: - `User Methods`: __init__, open, close, undo, pack, classFactory - `Inspection Methods`: getName, getSize, objectCount, getActivityMonitor, setActivityMonitor - `Connection Pool Methods`: getPoolSize, getVersionPoolSize, removeVersionPool, setPoolSize, setVersionPoolSize - `Transaction Methods`: invalidate - `Other Methods`: lastTransaction, connectionDebugInfo - `Version Methods`: modifiedInVersion, abortVersion, commitVersion, versionEmpty - `Cache Inspection Methods`: cacheDetail, cacheExtremeDetail, cacheFullSweep, cacheLastGCTime, cacheMinimize, cacheSize, cacheDetailSize, getCacheSize, getVersionCacheSize, setCacheSize, setVersionCacheSize ii�iidtunnamedcCs)tiƒ} | i|_| i|_h|_||_ ||_ ||_||_h|_||_|i|dƒt|dƒpd„|_ny|itdƒWnËtj o¿dkl}|ƒ}tiƒ} t!i"| dƒ} | i$|i%dfƒ| i$|i&ƒƒt'i(ƒ} d| _*|i+| ƒ|i,td| i-ƒd| ƒ|i| ƒ|i.| ƒnX|djo h}n||_/||_0||jot1d|ƒ‚n|||ìst(sPersistentMappingisinitial database creations%database_name %r already in databasesthistoryt supportsUndotsupportsVersionstundoLogt versionEmptytversionstundoInfoN(6t threadingtRLocktxtacquireRt_atreleaset_rt_poolsRt _pool_sizet cache_sizet _cache_sizetversion_pool_sizet_version_pool_sizetversion_cache_sizet_version_cache_sizet _miv_cachetstoraget_storaget registerDBRthasattrR(tloadtz64tKeyErrortpersistent.mappingtPersistentMappingtroott cStringIOtStringIOtfiletcPickletPicklertptdumpt __class__t __getstate__t transactiont Transactionttt descriptiont tpc_begintstoretgetvaluet tpc_finisht databasest database_namet ValueErrortmtsetattrtgetattrR2(RRCRR<R>R@R_R^RKRORaRRRXR5RL((RRÆsR                       cCsµ|iƒz™|i|jpt‚d|_|i}|dj o|i |ƒn|i }y|i |}Wn$tj o|iiƒdSnX|i|ƒWd|iƒXdS(sXReturn a connection to the pool. connection._db must be self on entry. N(RR7t connectiont_dbR Rt_openedt_activity_monitortamtclosedConnectiont_versiontversionR:tpoolRIt__dict__tclearRR9(RRdRhRkRl((Rt _returnToPools"       cCsG|iƒz+x$|iiƒD]}|i|ƒqWWd|iƒXdS(N(RR7R:tvaluesRlR R!R9(RR!Rl((Rt_connectionMap4s cCs7|djotiƒ}n|it||ƒƒdS(N(ttxnRRVtgettregistert AbortVersionRRk(RRkRr((Rt abortVersion<s cCs9h}|d„}|i|ƒ|iƒ}|iƒ|S(sYReturn information on objects in the various caches Organized by class. cCs’x‹|iiƒD]z\}}t|iddƒ}|o d|pd}d||iif}||jo||cd7tZdZd„Zd„Zed„Zd„Zd„ZRS(s9Transaction participation for a version or undo resource.cCsr||_|iii|_|iii|_|iii|_tiƒzt |_ t d7a Wdti ƒXdS(Ni( tdbRReRDR(R]t tpc_aborttresource_counter_lockR6tresource_countert_countR8(RRØ((RR¶s   cCsd|iiiƒ|ifS(Ns%s:%016x(RReRDtsortKeyRÜ(R((RRÝÉscCs.|otdƒ‚n|iii|ƒdS(Ns doesn't support sub-transactions(tsubR`RReRDRZRr(RRrRÞ((RRZÌscCsdS(N((RtobjRr((RtabortÔscCsdS(N((RRßRr((Rtcommit×s( R"R#R$RRÝR%RZRàRá(((RR׳s     RšcBstZdd„Zd„ZRS(NR+cCs,tt|ƒi|ƒ||_||_dS(N( tsuperRšRRRØRkRjtdestt_dest(RRØRkRã((RRÜs cCsŒ|i}|iii|i|i|ƒ\}}t i |dƒ}|ii ||d|iƒ|io |ii ||d|iƒndS(NiRk( RRäRãReRDR�RjRXR¦R§tdicttfromkeysR¥(RR{RXRãR§R¦((RRáás  (R"R#RRá(((RRšÚs RucBstZd„Zd„ZRS(NcCs#tt|ƒi|ƒ||_dS(N(RâRuRRRØRkRj(RRØRk((RRïscCsM|iii|i|ƒ\}}|ii|t i |dƒd|iƒdS(NiRk( RReRDRvRjRXR¦R§R¥RåRæ(RR{RXR§R¦((RRáós! (R"R#RRá(((RRuís RÒcBstZd„Zd„ZRS(NcCs#tt|ƒi|ƒ||_dS(N(RâRÒRRRØR¦t_tid(RRØR¦((RRûscCsD|iii|i|ƒ\}}|ii|t i |dƒƒdS(Ni( RReRDRÓRçRXR¦R§R¥RåRæ(RR{RXR§R¦((RRáÿs!(R"R#RRá(((RRÒùs ("R$RPRMRŠR3R½R»tloggingt ZODB.brokenRÇt ZODB.utilsRHtZODB.ConnectionRÖtZODB.serializeRÄRtzope.interfaceRÔtZODB.interfacesRÕRVt getLoggerRtobjectRR&tLockRÚRÛR×RšRuRÒ(RMR&RRuRRÄRÇRHRPRšRŠRÖRÕRRÔRVRèR»R×RÚR3RÒR½((Rt?s.          tÿÿ '