[Zope-dev] Re: circular referenced persistent objects

2004-04-12 Thread Casey Duncan
On Sat, 10 Apr 2004 14:11:56 -0500
[EMAIL PROTECTED] wrote:

 I have the following setup (unrelated lines are omitted):
 
 class Deliverer(Folder):
 def manage_afterAdd(self, item, container):
 if item is self:
 self.__ac_local_roles__ = dr_localroles(self)
 
 class dr_localroles(Persistent):
 def __init__(self, dr):
 self.dr = dr
 
 dr_localroles implements a few methods of the dictionary interface, so
 I can always check the effective settings via the Security/local roles
 zmi page. In order to computing roles, dr_localroles requires its
 parent object instance (Deliverer), that's why I store a reference to
 it as an attribute.
 Question:
  - Is there a way for dr_localroles to refer its parent without
  holding
 a reference to it or using weak reference?

Yes, use acquisition. Make dr_localroles inherit from
Acquisition.Implicit or Acquisition.Explicit.

  - Is there an equivalent of sys.getrefcount for ZODB persistent
 objects?

Cycles like this will not be a problem for ZODB. When either object is
deleted it will no longer be reachable from the root, regardless of
cycles between them. When the database is packed, unreachable objects
are removed.
 
 Also a note for the archives:
 I wanted to make sure that if I delete a Deliverer object, it will
 indeed be removed from ZODB. 

Once you pack, yes.

 For this I got the oid of the object,
 deleted it and than tried to get it back via the oid. The trick is,
 that you'll only get a POSKeyError if you pack the database and flush
 the cache. This latter one was not obvious for me.

Such tricks are not necessary and cause your app to rely too much on the
curent implementation of ZODB. Just let the database take care of this
for you.

In any case, there is a (new) persistent weakref class in ZODB 3.3 which
allows you to weakly refer to other persistent objects without causing
them to stay in the database like normal references do.

-Casey


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


RE: [Zope-dev] Re: circular referenced persistent objects

2004-04-12 Thread zope
Casey,

Thanks for the clarification.

   - Is there an equivalent of sys.getrefcount for ZODB persistent
  objects?

This is still a question. Is there any way, to determine how many times
a zodb persistent object is referenced? sys.getrefcount seems to tell me
only those references which are currently loaded in the memory.
Also another very interesting question is that who referring to a
specific object.

  For this I got the oid of the object,
  deleted it and than tried to get it back via the oid. The trick is,
  that you'll only get a POSKeyError if you pack the database 
 and flush
  the cache. This latter one was not obvious for me.
 
 Such tricks are not necessary and cause your app to rely too 
 much on the
 curent implementation of ZODB. Just let the database take care of this
 for you.

I used this trick only for exploring ZODB behavior. The application
doesn't do any nasty tricks.

Regards,
Sandor


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: circular referenced persistent objects

2004-04-12 Thread Casey Duncan
On Mon, 12 Apr 2004 10:57:43 -0500
[EMAIL PROTECTED] wrote:

 Casey,
 
 Thanks for the clarification.
 
- Is there an equivalent of sys.getrefcount for ZODB persistent
   objects?
 
 This is still a question. Is there any way, to determine how many
 times a zodb persistent object is referenced? sys.getrefcount seems to
 tell me only those references which are currently loaded in the
 memory. Also another very interesting question is that who referring
 to a specific object.

Not from a given object. You would need to walk the forward references
(which are tracked) of all the objects to find this out. I posted some
code to do this from any starting object in the ZODB a long time ago.
Search the mail archives if you're interested.
 
   For this I got the oid of the object,
   deleted it and than tried to get it back via the oid. The trick
   is, that you'll only get a POSKeyError if you pack the database 
  and flush
   the cache. This latter one was not obvious for me.
  
  Such tricks are not necessary and cause your app to rely too 
  much on the
  curent implementation of ZODB. Just let the database take care of
  this for you.
 
 I used this trick only for exploring ZODB behavior. The application
 doesn't do any nasty tricks.

ok.

-Casey

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


RE: [Zope-dev] Re: circular referenced persistent objects

2004-04-12 Thread Tim Peters
[Sandor]
 This is still a question. Is there any way, to determine how many
 times a zodb persistent object is referenced?

ZODB itself doesn't keep track of that, although it's possible to write a
storage that does.  FileStorage does not.  BerkeleyStorage did (past tense
because Zope Corp has given up on BerkeleyStorage for now).

 sys.getrefcount seems to tell me only those references which are
 currently loaded in the memory.

Yes, sys.getrefcount() is a Python builtin, and only knows about in-memory
Python objects.  Python (and its builtins) doesn't know anything about
persistence.

 Also another very interesting question is that who referring
 to a specific object.

Like at the start, it would be possible to write a storage that saves away
that kind of inverted index, but I don't know of any that do.

Given a particular flavor of storage, and detailed knowledge of its
implementation, you can write scripts to crawl over the storage and compute
anything you like.  For FileStorage, the standard tools fsrefs.py and
fsdump.py illustrate two ways of picking apart an .fs file.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )