DB.py 22.3 KB
Newer Older
Jim Fulton's avatar
alpha1  
Jim Fulton committed
1
##############################################################################
2 3 4 5 6 7 8
# 
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
# 
# Copyright (c) Digital Creations.  All rights reserved.
# 
# This license has been certified as Open Source(tm).
Jim Fulton's avatar
alpha1  
Jim Fulton committed
9 10 11 12 13
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
# 1. Redistributions in source code must retain the above copyright
#    notice, this list of conditions, and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions, and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# 3. Digital Creations requests that attribution be given to Zope
#    in any manner possible. Zope includes a "Powered by Zope"
#    button that is installed by default. While it is not a license
#    violation to remove this button, it is requested that the
#    attribution remain. A significant investment has been put
#    into Zope, and this effort will continue if the Zope community
#    continues to grow. This is one way to assure that growth.
# 
# 4. All advertising materials and documentation mentioning
#    features derived from or use of this software must display
#    the following acknowledgement:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    In the event that the product being advertised includes an
#    intact Zope distribution (with copyright and license included)
#    then this clause is waived.
# 
# 5. Names associated with Zope or Digital Creations must not be used to
#    endorse or promote products derived from this software without
#    prior written permission from Digital Creations.
# 
# 6. Modified redistributions of any form whatsoever must retain
#    the following acknowledgment:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    Intact (re-)distributions of any official Zope release do not
#    require an external acknowledgement.
# 
# 7. Modifications are encouraged but must be packaged separately as
#    patches to official Zope releases.  Distributions that do not
#    clearly separate the patches from the original work must be clearly
#    labeled as unofficial distributions.  Modifications which do not
#    carry the name Zope may be packaged in any form, as long as they
#    conform to all of the clauses above.
# 
# 
# Disclaimer
# 
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# 
# 
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations.  Specific
# attributions are listed in the accompanying credits file.
# 
Jim Fulton's avatar
alpha1  
Jim Fulton committed
84 85 86
##############################################################################
"""Database objects

87 88
$Id: DB.py,v 1.27 2001/04/12 19:53:04 jim Exp $"""
__version__='$Revision: 1.27 $'[11:-2]
Jim Fulton's avatar
alpha1  
Jim Fulton committed
89

Jim Fulton's avatar
Jim Fulton committed
90
import cPickle, cStringIO, sys, POSException, UndoLogCompatible
Jim Fulton's avatar
alpha1  
Jim Fulton committed
91 92 93
from Connection import Connection
from bpthread import allocate_lock
from Transaction import Transaction
94
from referencesf import referencesf
95
from time import time, ctime
Jim Fulton's avatar
Jim Fulton committed
96
from zLOG import LOG, ERROR
Jim Fulton's avatar
Jim Fulton committed
97

98
StringType=type('')
Jim Fulton's avatar
alpha1  
Jim Fulton committed
99

Jim Fulton's avatar
Jim Fulton committed
100
class DB(UndoLogCompatible.UndoLogCompatible):
Jim Fulton's avatar
alpha1  
Jim Fulton committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    """The Object Database

    The Object database coordinates access to and interaction of one
    or more connections, which manage object spaces.  Most of the actual work
    of managing objects is done by the connections.
    """

    def __init__(self, storage,
                 pool_size=7,
                 cache_size=400,
                 cache_deactivate_after=60,
                 version_pool_size=3,
                 version_cache_size=100,
                 version_cache_deactivate_after=10,
                 ):
        """Create an object database.

        The storage for the object database must be passed in.
        Optional arguments are:

        pool_size -- The size of the pool of object spaces.

        """

        # Allocate locks:
        l=allocate_lock()
        self._a=l.acquire
        self._r=l.release

130
        # Setup connection pools and cache info
Jim Fulton's avatar
alpha1  
Jim Fulton committed
131 132 133 134 135 136 137 138 139
        self._pools={},[]
        self._temps=[]
        self._pool_size=pool_size
        self._cache_size=cache_size
        self._cache_deactivate_after=cache_deactivate_after
        self._version_pool_size=version_pool_size
        self._version_cache_size=version_cache_size
        self._version_cache_deactivate_after=version_cache_deactivate_after

140 141
        self._miv_cache={}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
        # Setup storage
        self._storage=storage
        storage.registerDB(self, None)
        if not hasattr(storage,'tpc_vote'): storage.tpc_vote=lambda *args: None
        try: storage.load('\0\0\0\0\0\0\0\0','')
        except:
            import PersistentMapping
            file=cStringIO.StringIO()
            p=cPickle.Pickler(file,1)
            p.dump((PersistentMapping.PersistentMapping,None))
            p.dump({'_container': {}})
            t=Transaction()
            t.description='initial database creation'
            storage.tpc_begin(t)
            storage.store('\0\0\0\0\0\0\0\0', None, file.getvalue(), '', t)
            storage.tpc_vote(t)
            storage.tpc_finish(t)

Jim Fulton's avatar
alpha1  
Jim Fulton committed
160
        # Pass through methods:
161
        for m in ('history',
162
                  'supportsUndo', 'supportsVersions', 'undoLog',
163
                  'versionEmpty', 'versions'):
Jim Fulton's avatar
alpha1  
Jim Fulton committed
164
            setattr(self, m, getattr(storage, m))
Jim Fulton's avatar
Jim Fulton committed
165 166 167

        if hasattr(storage, 'undoInfo'):
            self.undoInfo=storage.undoInfo
168
            
Jim Fulton's avatar
alpha1  
Jim Fulton committed
169 170 171

    def _cacheMean(self, attr):
        m=[0,0]
172
        def f(con, m=m, attr=attr):
Jim Fulton's avatar
alpha1  
Jim Fulton committed
173 174 175 176 177 178 179 180
            t=getattr(con._cache,attr)
            m[0]=m[0]+t
            m[1]=m[1]+1

        self._connectionMap(f)
        if m[1]: m=m[0]/m[1]
        else: m=None
        return m
181 182 183 184 185

    def _classFactory(self, connection, location, name,
                      _silly=('__doc__',), _globals={}):
        return getattr(__import__(location, _globals, _globals, _silly),
                       name)
Jim Fulton's avatar
alpha1  
Jim Fulton committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199
            
    def _closeConnection(self, connection):
        """Return a connection to the pool"""
        self._a()
        try:
            version=connection._version
            pools,pooll=self._pools
            pool, allocated, pool_lock = pools[version]
            pool.append(connection)
            if len(pool)==1:
                # Pool now usable again, unlock it.
                pool_lock.release()
        finally: self._r()
        
200
    def _connectionMap(self, f):
Jim Fulton's avatar
alpha1  
Jim Fulton committed
201 202 203 204 205 206 207 208 209
        self._a()
        try:
            pools,pooll=self._pools
            for pool, allocated in pooll:
                for cc in allocated: f(cc)

            temps=self._temps
            if temps:
                t=[]
Jim Fulton's avatar
Jim Fulton committed
210
                rc=sys.getrefcount
Jim Fulton's avatar
alpha1  
Jim Fulton committed
211 212 213 214 215 216
                for cc in temps:
                    if rc(cc) > 3: f(cc)
                self._temps=t
        finally: self._r()

    def abortVersion(self, version):
217
        AbortVersion(self, version)
Jim Fulton's avatar
alpha1  
Jim Fulton committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285

    def cacheDetail(self):
        """Return information on objects in the various caches

        Organized by class."""

        detail={}
        def f(con,detail=detail,have_detail=detail.has_key):
            for oid, ob in con._cache.items():
                c="%s.%s" % (ob.__class__.__module__, ob.__class__.__name__)
                if have_detail(c): detail[c]=detail[c]+1
                else: detail[c]=1
        
        self._connectionMap(f)
        detail=detail.items()
        detail.sort()
        return detail

    def cacheExtremeDetail(self):
        detail=[]
        def f(con, detail=detail, rc=sys.getrefcount):
            for oid, ob in con._cache.items():
                id=oid
                if hasattr(ob,'__dict__'):
                    d=ob.__dict__
                    if d.has_key('id'):
                        id="%s (%s)" % (oid, d['id'])
                    elif d.has_key('__name__'):
                        id="%s (%s)" % (oid, d['__name__'])
    
                detail.append({
                    'oid': id,
                    'klass': "%s.%s" % (ob.__class__.__module__,
                                        ob.__class__.__name__),
                    'rc': rc(ob)-4,
                    'references': con.references(oid),
                    })

        self._connectionMap(f)
        return detail

    def cacheFullSweep(self, value):
        self._connectionMap(lambda c, v=value: c._cache.full_sweep(v))

    def cacheLastGCTime(self):
        m=[0]
        def f(con, m=m):
            t=con._cache.cache_last_gc_time
            if t > m[0]: m[0]=t

        self._connectionMap(f)
        return m[0]

    def cacheMinimize(self, value):
        self._connectionMap(lambda c, v=value: c._cache.minimize(v))

    def cacheMeanAge(self): return self._cacheMean('cache_mean_age')
    def cacheMeanDeac(self): return self._cacheMean('cache_mean_deac')
    def cacheMeanDeal(self): return self._cacheMean('cache_mean_deal')

    def cacheSize(self):
        m=[0]
        def f(con, m=m):
            m[0]=m[0]+len(con._cache)

        self._connectionMap(f)
        return m[0]

Jim Fulton's avatar
Jim Fulton committed
286 287
    def close(self): self._storage.close()

Jim Fulton's avatar
alpha1  
Jim Fulton committed
288
    def commitVersion(self, source, destination=''):
289
        CommitVersion(self, source, destination)
Jim Fulton's avatar
alpha1  
Jim Fulton committed
290 291 292

    def exportFile(self, oid, file=None):
        raise 'Not yet implemented'
293 294 295
                           
    def getCacheDeactivateAfter(self): return self._cache_deactivate_after
    def getCacheSize(self): return self._cache_size
Jim Fulton's avatar
alpha1  
Jim Fulton committed
296 297 298

    def getName(self): return self._storage.getName()

299 300
    def getPoolSize(self): return self._pool_size

Jim Fulton's avatar
alpha1  
Jim Fulton committed
301 302
    def getSize(self): return self._storage.getSize()

303 304 305 306 307 308
    def getVersionCacheDeactivateAfter(self):
        return self._version_cache_deactivate_after
    def getVersionCacheSize(self): return self._version_cache_size

    def getVersionPoolSize(self): return self._version_pool_size

Jim Fulton's avatar
alpha1  
Jim Fulton committed
309 310 311
    def importFile(self, file):
        raise 'Not yet implemented'

312 313
    def invalidate(self, oid, connection=None, version='',
                   rc=sys.getrefcount):
Jim Fulton's avatar
alpha1  
Jim Fulton committed
314 315 316 317 318 319 320 321 322 323
        """Invalidate references to a given oid.

        This is used to indicate that one of the connections has committed a
        change to the object.  The connection commiting the change should be
        passed in to prevent useless (but harmless) messages to the
        connection.
        """
        if connection is not None: version=connection._version
        self._a()
        try:
324 325 326 327 328 329 330 331

            # Update modified in version cache
            h=hash(oid)%131
            cache=self._miv_cache
            o=cache.get(h, None)
            if o and o[0]==oid: del cache[h]

            # Notify connections
Jim Fulton's avatar
alpha1  
Jim Fulton committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345
            pools,pooll=self._pools
            for pool, allocated in pooll:
                for cc in allocated:
                    if (cc is not connection and
                        (not version or cc._version==version)):
                        if rc(cc) <= 3:
                            cc.close()
                        cc.invalidate(oid)

            temps=self._temps
            if temps:
                t=[]
                for cc in temps:
                    if rc(cc) > 3:
346 347
                        if (cc is not connection and
                            (not version or cc._version==version)):
Jim Fulton's avatar
alpha1  
Jim Fulton committed
348 349 350 351 352 353
                            cc.invalidate(oid)
                        t.append(cc)
                    else: cc.close()
                self._temps=t
        finally: self._r()

354 355 356 357 358
    def invalidateMany(self, oids=None, version=''):
        if oids is None: self.invalidate(None, version=version)
        else:
            for oid in oids: self.invalidate(oid, version=version)

359 360 361 362 363 364 365 366 367 368
    def modifiedInVersion(self, oid):
        h=hash(oid)%131
        cache=self._miv_cache
        o=cache.get(h, None)
        if o and o[0]==oid:
            return o[1]
        v=self._storage.modifiedInVersion(oid)
        cache[h]=oid, v
        return v

Jim Fulton's avatar
alpha1  
Jim Fulton committed
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
    def objectCount(self): return len(self._storage)
        
    def open(self, version='', transaction=None, temporary=0, force=None,
             waitflag=1):
        """Return a object space (AKA connection) to work in

        The optional version argument can be used to specify that a
        version connection is desired.

        The optional transaction argument can be provided to cause the
        connection to be automatically closed when a transaction is
        terminated.  In addition, connections per transaction are
        reused, if possible.

        Note that the connection pool is managed as a stack, to increate the
        likelihood that the connection's stack will include useful objects.
        """
386 387 388
        if type(version) is not StringType:
            raise POSException.Unimplemented, 'temporary versions'
        
Jim Fulton's avatar
alpha1  
Jim Fulton committed
389 390 391 392 393 394
        self._a()
        try:

            if transaction is not None:
                connections=transaction._connections
                if connections:
395
                    if connections.has_key(version) and not temporary:
Jim Fulton's avatar
alpha1  
Jim Fulton committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
                        return connections[version]
                else:
                    transaction._connections=connections={}
                transaction=transaction._connections
                    

            if temporary:
                # This is a temporary connection.
                # We won't bother with the pools.  This will be
                # a one-use connection.
                c=Connection(
                    version=version,
                    cache_size=self._version_cache_size,
                    cache_deactivate_after=
                    self._version_cache_deactivate_after)
                c._setDB(self)
                self._temps.append(c)
                if transaction is not None: transaction[id(c)]=c
                return c


            pools,pooll=self._pools
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443

            # pools is a mapping object:
            #
            #   {version -> (pool, allocated, lock)
            #
            # where:
            #
            #   pool is the connection pool for the version,
            #   allocated is a list of all of the allocated
            #     connections, and
            #   lock is a lock that is used to block when a pool is
            #     empty and no more connections can be allocated.
            #
            # pooll is a list of all of the pools and allocated for
            # use in cases where we need to iterate over all
            # connections or all inactive connections.

            # Pool locks are tricky.  Basically, the lock needs to be
            # set whenever the pool becomes empty so that threads are
            # forced to wait until the pool gets a connection it it.
            # The lock is acquired when the (empty) pool is
            # created. The The lock is acquired just prior to removing
            # the last connection from the pool and just after adding
            # a connection to an empty pool.

            
Jim Fulton's avatar
alpha1  
Jim Fulton committed
444 445 446 447 448 449 450 451 452 453 454 455
            if pools.has_key(version):
                pool, allocated, pool_lock = pools[version]
            else:
                pool, allocated, pool_lock = pools[version] = (
                    [], [], allocate_lock())
                pooll.append((pool, allocated))
                pool_lock.acquire()


            if not pool:
                c=None
                if version:
456
                    if self._version_pool_size > len(allocated) or force:
Jim Fulton's avatar
alpha1  
Jim Fulton committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
                        c=Connection(
                            version=version,
                            cache_size=self._version_cache_size,
                            cache_deactivate_after=
                            self._version_cache_deactivate_after)
                        allocated.append(c)
                        pool.append(c)
                elif self._pool_size > len(allocated) or force:
                    c=Connection(
                        version=version,
                        cache_size=self._cache_size,
                        cache_deactivate_after=
                        self._cache_deactivate_after)
                    allocated.append(c)
                    pool.append(c)
                    
                if c is None:
                    if waitflag:
                        self._r()
                        pool_lock.acquire()
                        self._a()
478 479 480 481
                        if len(pool) > 1:
                            # Note that the pool size will normally be 1 here,
                            # but it could be higher due to a race condition.
                            pool_lock.release()
Jim Fulton's avatar
alpha1  
Jim Fulton committed
482 483 484 485
                    else: return

            elif len(pool)==1:
                # Taking last one, lock the pool
486 487 488 489 490
                # Note that another thread might grab the lock
                # before us, so we might actually block, however,
                # when we get the lock back, there *will* be a
                # connection in the pool.
                self._r()
Jim Fulton's avatar
alpha1  
Jim Fulton committed
491
                pool_lock.acquire()
492
                self._a()
493 494 495 496
                if len(pool) > 1:
                    # Note that the pool size will normally be 1 here,
                    # but it could be higher due to a race condition.
                    pool_lock.release()
Jim Fulton's avatar
alpha1  
Jim Fulton committed
497 498 499 500 501 502 503 504 505 506 507 508

            c=pool[-1]
            del pool[-1]
            c._setDB(self)
            for pool, allocated in pooll:
                for cc in pool:
                    cc._incrgc()

            if transaction is not None: transaction[version]=c
            return c

        finally: self._r()
509 510 511 512

    def connectionDebugInfo(self):
        r=[]
        pools,pooll=self._pools
513
        t=time()
514 515
        for version, (pool, allocated, lock) in pools.items():
            for c in allocated:
516
                o=c._opened
Jim Fulton's avatar
Jim Fulton committed
517 518 519 520 521 522
                d=c._debug_info
                if d:
                    if len(d)==1: d=d[0]
                else: d=''
                d="%s (%s)" % (d, len(c._cache))
                
523
                r.append({
524
                    'opened': o and ("%s (%.2fs)" % (ctime(o), t-o)),
Jim Fulton's avatar
Jim Fulton committed
525
                    'info': d,
526 527 528
                    'version': version,
                    })
        return r
Jim Fulton's avatar
alpha1  
Jim Fulton committed
529
        
530 531 532
    def pack(self, t=None, days=0):
        if t is None: t=time()
        t=t-(days*86400)
Jim Fulton's avatar
Jim Fulton committed
533 534 535 536
        try: self._storage.pack(t,referencesf)
        except:
            LOG("ZODB", ERROR, "packing", error=sys.exc_info())
            raise
Jim Fulton's avatar
alpha1  
Jim Fulton committed
537
                           
538 539 540 541 542 543 544 545 546
    def setCacheDeactivateAfter(self, v):
        self._cache_deactivate_after=v
        for c in self._pools[0][''][1]:
            c._cache.cache_age=v

    def setCacheSize(self, v):
        self._cache_size=v
        for c in self._pools[0][''][1]:
            c._cache.cache_size=v
547 548 549 550

    def setClassFactory(self, factory):
        self._classFactory=factory

Jim Fulton's avatar
alpha1  
Jim Fulton committed
551
    def setPoolSize(self, v): self._pool_size=v
552
    
Jim Fulton's avatar
alpha1  
Jim Fulton committed
553 554
    def setVersionCacheDeactivateAfter(self, v):
        self._version_cache_deactivate_after=v
555 556 557 558 559 560 561 562
        for ver in self._pools[0].keys():
            if ver:
                for c in self._pools[0][ver][1]:
                    c._cache.cache_age=v

    def setVersionCacheSize(self, v):
        self._version_cache_size=v
        for ver in self._pools[0].keys():
563
            if ver:
564 565 566
                for c in self._pools[0][ver][1]:
                    c._cache.cache_size=v
        
Jim Fulton's avatar
alpha1  
Jim Fulton committed
567
    def setVersionPoolSize(self, v): self._version_pool_size=v
Jim Fulton's avatar
Jim Fulton committed
568 569

    def cacheStatistics(self): return () # :(
Jim Fulton's avatar
alpha1  
Jim Fulton committed
570

571
    def undo(self, id):
572 573 574 575 576 577 578 579 580 581 582 583 584 585
        storage=self._storage
        try: supportsTransactionalUndo = storage.supportsTransactionalUndo
        except AttributeError:
            supportsTransactionalUndo=0
        else:
            supportsTransactionalUndo=supportsTransactionalUndo()

        if supportsTransactionalUndo:
            # new style undo
            TransactionalUndo(self, id)
        else:
            # fall back to old undo
            for oid in storage.undo(id):
                self.invalidate(oid)
586

Jim Fulton's avatar
alpha1  
Jim Fulton committed
587 588 589
    def versionEmpty(self, version):
        return self._storage.versionEmpty(version)

590 591 592 593 594 595 596 597 598 599 600 601
class CommitVersion:
    """An object that will see to version commit

    in cooperation with a transaction manager.
    """
    def __init__(self, db, version, dest=''):
        self._db=db
        s=db._storage
        self._version=version
        self._dest=dest
        self.tpc_abort=s.tpc_abort
        self.tpc_begin=s.tpc_begin
602
        self.tpc_vote=s.tpc_vote
603 604 605 606 607 608 609 610
        self.tpc_finish=s.tpc_finish
        get_transaction().register(self)

    def abort(self, reallyme, t): pass

    def commit(self, reallyme, t):
        db=self._db
        dest=self._dest
611 612 613 614 615 616
        oids=db._storage.commitVersion(self._version, dest, t)
        for oid in oids: db.invalidate(oid, version=dest)
        if dest:
            # the code above just invalidated the dest version.
            # now we need to invalidate the source!
            for oid in oids: db.invalidate(oid, version=self._version)
Jim Fulton's avatar
alpha1  
Jim Fulton committed
617
    
618 619 620 621 622 623 624 625 626
class AbortVersion(CommitVersion):
    """An object that will see to version abortion

    in cooperation with a transaction manager.
    """

    def commit(self, reallyme, t):
        db=self._db
        version=self._version
627 628
        oids = db._storage.abortVersion(version, t)
        for oid in oids:
629
            db.invalidate(oid, version=version)
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646


class TransactionalUndo(CommitVersion):
    """An object that will see to transactional undo

    in cooperation with a transaction manager.
    """
    
    # I'm lazy. I'm reusing __init__ and abort and reusing the
    # version attr for the transavtion id. There's such a strong
    # similarity of rythm, that I think it's justified.

    def commit(self, reallyme, t):
        db=self._db
        oids=db._storage.transactionalUndo(self._version, t)
        for oid in oids:
            db.invalidate(oid)