Menu

#3 application data bug (solved) with postgres db

open
nobody
None
5
2005-01-07
2005-01-07
No

hi

setupApplication needs to be changed to what follows.

i found a subtle bug whereby the application data was
getting deleted between different children, because of
a rounding error. server.restart() returns a float,
and that is compared with an int. don't want to run
into details, but that is causing an application
restart on every new child (which clears the
application data, see below in code).

it was hard to find because the problem only manifested
itself with a specific sets of web pages in my
automated tests (using mechanize) which use application
data, and only when the part of the test that reads
from apploication data was spawned from a new child.

i also added a bug in the tracker (but it doesn't seem
used ... (dates)). this is why i'm emailing this list.

cheers,

the new code below only converts to an int, that solves
the problem, applicationStart event is only called once
for the app, and application data persists as it should.

def setupApplication():
"""
Per application initialization. We return 1 if we
are the first
webserver in this generation.
"""
if not database or server.generation() is None:
logger.info('Application variables and events
are not available.')
return 0
cursor = database.cursor()
cursor.execute("""
select count, restart_time
from draco_servers
where generation = %s
""", (server.generation(),))
row = cursor.fetchone()

serv_restart = int(server.restart())
if row and row[1] != serv_restart:
cursor.execute("""
delete from draco_servers
where generation = %s and restart_time = %s
""", (server.generation(), row[1]))
database.commit()
row = None
if not row:
try:
cursor.execute("""
insert into draco_servers
(generation, count, restart_time)
values (%s, 1, %s)
""", (server.generation(),
serv_restart))
database.commit()

# clear all application data
cursor.execute('delete from
draco_application_data')
database.commit()
return 1
except dbapi.IntegrityError:
# Another process inserted a row for this
generation
database.rollback()
cursor.execute("""
update draco_servers
set count = count + 1
where generation = %s
""", (server.generation(),))
database.commit()
return 0

Discussion


Log in to post a comment.

MongoDB Logo MongoDB