Re: Trying ZODB, background in Relational: mimic auto_increment?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Paul Calderone

    Re: Trying ZODB, background in Relational: mimic auto_increment?

    On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch" <deets@nospam.w eb.dewrote:
    >Jean-Paul Calderone wrote:
    >
    >On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham
    ><phillip.oldha m@gmail.comwrot e:
    >>[snip]
    >>>
    >>>How would one assign a unique ID to the root at that point?
    >>
    >Here's one way
    >>
    > class Sequence(Persis tence):
    > def __init__(self):
    > self.current = 0
    >>
    > def next(self):
    > self.current += 1
    > return self.current
    >>
    > ticketSequence = Sequence()
    >>
    > class Ticket(Persiste nce):
    > def __init__(self):
    > self.id = ticketSequence. next()
    >
    >Be aware that this isn't working concurrently. Depending on your
    >application, this can be mitigated using a simple threading.Lock.
    >
    ZODB has transactions. That's probably the best way to make this
    code safe for concurrent use. A threading.Lock would make threaded
    use safe, but wouldn't give you multiprocess concurrency safety.

    Jean-Paul
  • Diez B. Roggisch

    #2
    Re: Trying ZODB, background in Relational: mimic auto_increment?

    Jean-Paul Calderone schrieb:
    On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch"
    <deets@nospam.w eb.dewrote:
    >Jean-Paul Calderone wrote:
    >>
    >>On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham
    >><phillip.oldh am@gmail.comwro te:
    >>>[snip]
    >>>>
    >>>How would one assign a unique ID to the root at that point?
    >>>
    >>Here's one way
    >>>
    >> class Sequence(Persis tence):
    >> def __init__(self):
    >> self.current = 0
    >>>
    >> def next(self):
    >> self.current += 1
    >> return self.current
    >>>
    >> ticketSequence = Sequence()
    >>>
    >> class Ticket(Persiste nce):
    >> def __init__(self):
    >> self.id = ticketSequence. next()
    >>
    >Be aware that this isn't working concurrently. Depending on your
    >application, this can be mitigated using a simple threading.Lock.
    >>
    >
    ZODB has transactions. That's probably the best way to make this
    code safe for concurrent use.
    But that's a great deal more complicated! It requires merging, and while
    this of course is possible, you should have mentioned it because
    otherwise the OP might run into problems.

    Diez

    Comment

    • Christian Heimes

      #3
      Re: Trying ZODB, background in Relational: mimic auto_increment?

      Diez B. Roggisch wrote:
      But that's a great deal more complicated! It requires merging, and while
      this of course is possible, you should have mentioned it because
      otherwise the OP might run into problems.
      A lock doesn't do the job at all. ZODB supports clustering through ZEO.
      Multiple ZEO clients can be attached to a single or more ZODB servers.
      Any kind of thread based locking is local to each ZEO client.

      You have to sync a sequence generator across multiple ZEO clients, hook
      into the two phase commit protocol or use the conflict resolution hooks.
      The problem is more complex than you think.

      Christian

      Comment

      • Maric Michaud

        #4
        Re: Trying ZODB, background in Relational: mimic auto_increment?

        Le Thursday 14 August 2008 20:14:19 Christian Heimes, vous avez écrit :
        Diez B. Roggisch wrote:
        But that's a great deal more complicated! It requires merging, and while
        this of course is possible, you should have mentioned it because
        otherwise the OP might run into problems.
        >
        A lock doesn't do the job at all. ZODB supports clustering through ZEO.
        Multiple ZEO clients can be attached to a single or more ZODB servers.
        Any kind of thread based locking is local to each ZEO client.
        >
        You have to sync a sequence generator across multiple ZEO clients, hook
        into the two phase commit protocol or use the conflict resolution hooks.
        You don't have too if you manage the conflict error anywhere else in the
        program just manage the exception ConflictError and let the user retry later,
        that will not happen that much on most application.

        But,
        The problem is more complex than you think.
        >
        Not that complex, strength of ZODB is right here, this entirely covered by the
        introduction to zodb (ZODB/ZEO programming guide), see userdb and chatter
        examples.


        --
        _____________

        Maric Michaud

        Comment

        Working...