m TEc@sSdZdkZdkZdkZdkZdklZlZdkZdkl Z dk l Z dk l Z dklZdk lZdklZd klZdkZeid Zd efd YZd efdYZeiZdadefdYZdefdYZdefdYZ defdYZ!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_ConnectionPoolcBsPtZdZdZdZdZdZedZdZ dZ 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||_|idS(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}||ijptn|S(N(tNonetresultRRRRR (RR((RRs  cCs|ii|dS(N(RRtmaptf(RR!((RR s( t__name__t __module__t__doc__RR RRtFalseRRR (((RR$s      tDBcBstZdZeeeZeZdddddedZ dZ dZ ed Z d Z d Zd Zd ZdZdZdZdZdedZdZdZdZdZdZdZdZeddZdZdZdZ de!ee!dZ"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 iiiidtunnamedcCs)ti} | i|_| i|_h|_||_ ||_ ||_||_h|_||_|i|dt|dpd|_ny|itdWntj odkl}|}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((RRsR                       cCs|iz|i|jptd|_|i}|dj o|i |n|i }y|i |}Wn$tj o|iidSnX|i|Wd|iXdS(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|iz+x$|iiD]}|i|qWWd|iXdS(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. cCsx|iiD]z\}}t|idd}|o d|pd}d||iif}||jo||cd7tZdZdZdZedZdZdZRS(s9Transaction participation for a version or undo resource.cCsr||_|iii|_|iii|_|iii|_tizt |_ t d7a Wdti XdS(Ni( tdbRReRDR(R]t tpc_aborttresource_counter_lockR6tresource_countert_countR8(RR((RRs   cCsd|iii|ifS(Ns%s:%016x(RReRDtsortKeyR(R((RRscCs.|otdn|iii|dS(Ns doesn't support sub-transactions(tsubR`RReRDRZRr(RRrR((RRZscCsdS(N((RtobjRr((RtabortscCsdS(N((RRRr((Rtcommits( R"R#R$RRR%RZRR(((RRs     RcBstZddZdZRS(NR+cCs,tt|i|||_||_dS(N( tsuperRRRRRkRjtdestt_dest(RRRkR((RRs cCs|i}|iii|i|i|\}}t i |d}|ii ||d|i|io |ii ||d|indS(NiRk( RRRReRDRRjRXRRtdicttfromkeysR(RR{RXRRR((RRs  (R"R#RR(((RRs RucBstZdZdZRS(NcCs#tt|i|||_dS(N(RRuRRRRkRj(RRRk((RRscCsM|iii|i|\}}|ii|t i |dd|idS(NiRk( RReRDRvRjRXRRRRR(RR{RXRR((RRs! (R"R#RR(((RRus RcBstZdZdZRS(NcCs#tt|i|||_dS(N(RRRRRRt_tid(RRR((RRscCsD|iii|i|\}}|ii|t i |ddS(Ni( RReRDRRRXRRRRR(RR{RXRR((RRs!(R"R#RR(((RRs ("R$RPRMRR3RRtloggingt ZODB.brokenRt ZODB.utilsRHtZODB.ConnectionRtZODB.serializeRRtzope.interfaceRtZODB.interfacesRRVt getLoggerRtobjectRR&tLockRRRRRuR(RMR&RRuRRRRHRPRRRRRRRVRRRRR3RR((Rt?s.          t '