[ZODB-Dev] Can Leo use zodb as a file system?

Edward K. Ream edreamleo at charter.net
Mon Sep 11 17:20:31 EDT 2006


Several of Leo's users have suggested that Leo could use the zodb instead of 
reading and writing files.  I hope a zodb guru can help me determine whether 
this project is feasible. I have spent several days writing simple prototype 
code.



I'll try to make this post as short as possible, but some background is 
needed. I'll attempt to make my assumptions explicit so they can be 
corrected as needed...



The idea is to represent a Leo outline as an entry in the zodb.  To write 
the data Leo would do::



    connection = self.db.open()

    root = connection.root()

    root[fileName] = v

    get_transaction().commit()



v is the root of a tree of Leo's vnodes and tnodes. (vnodes and tnodes 
contain all of Leo's persistent data, and vnodes and tnode both derive from 
ZODB.Persistence.Persistent.)



Similarly, to open a new Leo outline::



    v = root.get(fileName)

    c2 = c.new() # Create a new outline, whose 'commander' is c2.

    c2.setRootVnode(v) # Tell the commander that the root of the outline is 
v.



I want to know if this scheme can be used if there are multiple Leo outlines 
open. In my (zodb newbie's) mind this question 'translates' to the following 
zodb-specific questions:



1. Is it possible associate a particular connection with a particular Leo 
outline?



2. Is it possible to **leave a connection open** for as long as a particular 
Leo outline is open?



3. If multiple Leo outlines  (and multiple connections) are open, is it 
possible to define transactions that are specific to particular connection? 
In particular, does something like connection.commit() exist, and if so, how 
are connection-specific transactions defined?



The reason I ask these particular questions is this:  If my prototype opened 
an outline as above and then *closed* the connection, my prototype threw 
this exception soon after I started to use the outline:



Traceback (most recent call last):



  File "C:\prog\tigris-cvs\leo\src\leoGlobals.py", line 5010, in getScript

    elif p == c.currentPosition():



  File "C:\prog\tigris-cvs\leo\src\leoNodes.py", line 1370, in __cmp__

    if p1.childIndex() != p2.childIndex():



  File "C:\prog\tigris-cvs\leo\src\leoNodes.py", line 1580, in childIndex

    if not v or not v._back:



  File "C:\Python24\Lib\site-packages\ZODB\Connection.py", line 587, in 
setstate

    raise RuntimeError(msg)



RuntimeError: Shouldn't load state for 0x60af when the connection is closed



Here p is an instance of a Leo position, a short-lived object that *refers* 
to vnodes and tnodes but is *not* itself persistent.



So is it possible for non-persistent objects to refer to persistent objects?



Summary:



1. It appears that zodb does not update persistent objects properly when the 
connection that created those objects is closed.  I say this because of the 
traceback given above.  Thus, I assume that *long-lasting* connections are 
required to support persistent objects.  Is this assumption correct?



2. With multiple Leo outlines connected to multiple connections there must 
be some way to **save one outline without saving them all**.

(or to revert one outline without reverting them all.)  How do I define 
outline-specific transactions?



Thanks for your help.



Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edreamleo at charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------





More information about the ZODB-Dev mailing list