Archived community.zenoss.org | full text search
Skip navigation
44356 Views 5 Replies Latest reply: Jan 21, 2010 2:13 PM by chickenandbeans RSS
chickenandbeans Rank: White Belt 11 posts since
Aug 11, 2009
Currently Being Moderated

Jan 12, 2010 9:32 AM

dmd = ZenScriptBase(connect=True).dmd multiple connections

I've written a few scripts using dmd = ZenScriptBase(connect=True).dmd, let's call them script1.py and script2.py.

I'm trying to pipe the output of script1 to script2. This results in a conflict error:

 

 

 

Traceback (most recent call last):
  File "./script1.py", line 13, in ?
    dmd = ZenScriptBase(connect=True,noopts=True).dmd
  File "/opt/zenoss/zenoss/Products/ZenUtils/ZenScriptBase.py", line 39, in __init__
    self.connect()
  File "/opt/zenoss/zenoss/Products/ZenUtils/ZenScriptBase.py", line 57, in connect
    commit()
  File "/opt/zenoss/zenoss/lib/python/transaction/_manager.py", line 93, in commit
    return self.get().commit()
  File "/opt/zenoss/zenoss/lib/python/transaction/_transaction.py", line 325, in commit
    self._commitResources()
  File "/opt/zenoss/zenoss/lib/python/transaction/_transaction.py", line 424, in _commitResources
    rm.commit(self)
  File "/opt/zenoss/zenoss/lib/python/ZODB/Connection.py", line 541, in commit
    self._commit(transaction)
  File "/opt/zenoss/zenoss/lib/python/ZODB/Connection.py", line 578, in _commit
    raise ConflictError(object=obj)
ZODB.POSException.ConflictError: database conflict error (oid 0x0cd5, class Products.ZenModel.DataRoot.DataRoot)

 

 

*nix box:

COMMAND 1: script1.py | script2.py = db conflict error

COMMAND2: script1.py > script1.out && cat script1.out | script2.py = works!

 

The difference between command 1 and command 2 is the number of connections, two and one respectively. Since the two scripts are connecting the same way... perhaps it's connection/locking issue? Has anyone created a zendmd script that accepts piped data in this way?

  • mrchippy ZenossEmployee 34 posts since
    May 12, 2008

    Conflict errors arise because two things are done to the database and the database doesn't know how to determine the "winner".  For example, if you have two connections open and one sets a = 1, then the other sets a = 2 and issues a commit().  If the first connection tries to commit now, the conflict exception gets thrown because the db doesn't know how to make sure data will be consistent.  There are three ways to try to avoid this in this simple example-- (1) issue a commit on connection one before connection two tries to modify the object; (2) issue a sync() call before changing the object in connection 2 (sync replaces your local objects with their current state in the db); (3) don't commit anything.  It sounds like #3 worked for you in your script.  Did you not need anything in the database to change?  Was it only retrieving information from the db?

     

    In your original message, the scripta | scriptb fails because the connections are open simultaneously.   In the second, the first script closes its connection before the second one starts.

     

    Can you post the scripts?

More Like This

  • Retrieving data ...

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points