[Zope] ZODB.POSException.ConflictError (in custommade product)

Gitte Wange gitte at mmmanager.org
Mon Nov 3 04:12:44 EST 2003


Tirsdag 28 oktober 2003 09:13   skrev Dieter Maurer:
> Gitte Wange wrote at 2003-10-26 23:14 +0100:
>  > At 18:34 26-10-2003, Dieter Maurer wrote:
>  > >If your counter is maintained in the ZODB, the counter should
>  > >be a "BTrees.Length" instance. Otherwise, you can use whatever
>  > >data structure seems best for you.
>  >
>  > Sorry Dieter if I'm slow on this but I just don't get it ...
>  > At this moment I have a dictionary looking like this:
>  > views = {'http://mypage.com/frontpage': 10,
>  > 'http://mypage.com/article2': 3} This get's saved into ZODB and - as I
>  > understand - causes the ConflictErrors ?
>
> I said: your counter (any one of them) in the ZODB should become
> a "BTrees.Length.Length" instance. I thought, this were pretty clear.

Now it's pretty clear :-)
I updated the counts to be a BTrees.Length instance instead of just an 
integer.
Looks like it helped but we still see the error sometimes (not as often as 
before).
The code for updating the counts look like this:

def addCount(self, url):
        """
        Add a new count for an url
        """
        counts = self._counts
        if not url in counts.keys():
            counts[url] = Length(0)
        counter = counts[url]
        counter.change(1)
        counts[url] = counter
        self._counts = counts
        self._p_changed = 1

Guess the error is raised when assigning the counts to self._counts.
I have experienced before that dictinaries don't survive a restart of Zope if 
not saving them as above but maybe this can work:

def addCount(self, url):
        """
        Add a new count for an url
        """
        if not url in self._counts.keys():
            counts = self._counts
            counts[url] = Length(0)
            self._counts = counts
            self._p_changed = 1
        counter = self._counts[url]
        counter.change(1)

Would that work ?

> That said: you may want to replace the dictionary by a
> "BTrees.OOBTree.OOBTree" instance.
> This way, the conflict resolution of "OOBTrees" may prevent
> (most) concurrent writes to the mapping (when you add
> new entries to the mapping) causing exceptions.
> It may not be necessary, though, as you probably rarely add
> new entries (usually, you will count in already existing counters).

It's very rarely that I will add new entries - all existing pages already 
exist in the tool.

-- 
Gitte Wange
Technical Manager

Email: gitte at mmmanager.org
Web: http://www.mmmanager.org
Tlf: +45 36 46 20 02

> We'll tell you when we try out the code you've written ;-)
Ahha, the classic open-source sanity pill/ thorn in my side....
What You Want Is What You Should Code Yourself ( WYWIWYSCY )

    -- Tom Smith: Zope Mailing List, About using ZODB as ODBC data source.




More information about the Zope mailing list