add lock_for_insert routine but comment out for now (hangs)

This commit is contained in:
sqlcoder 2009-07-28 21:19:31 +01:00
parent 5d5a6ed39d
commit 12e1da0a5e
3 changed files with 20 additions and 20 deletions

View File

@ -506,6 +506,14 @@ class Database:
# however the calling prog requires. Main aims: # however the calling prog requires. Main aims:
# - existing static routines from fpdb_simple just modified # - existing static routines from fpdb_simple just modified
def lock_for_insert(self):
"""Lock tables in MySQL to try to speed inserts up"""
try:
self.get_cursor().execute(self.sql.query['lockForInsert'])
except:
print "Error during fdb.lock_for_insert:", str(sys.exc_value)
#end def lock_for_insert
def storeHands(self, backend, site_hand_no, gametype_id def storeHands(self, backend, site_hand_no, gametype_id
,hand_start_time, names, tableName, maxSeats, hudCache ,hand_start_time, names, tableName, maxSeats, hudCache

View File

@ -1562,6 +1562,13 @@ class Sql:
else: # assume postgres else: # assume postgres
self.query['analyze'] = "vacuum analyze" self.query['analyze'] = "vacuum analyze"
if db_server == 'mysql':
self.query['lockForInsert'] = """
lock tables hands write, handsplayers write, handsactions write, players write, hudcache write
"""
else: # assume postgres
self.query['lockForInsert'] = ""
if __name__== "__main__": if __name__== "__main__":
# just print the default queries and exit # just print the default queries and exit
s = Sql(game = 'razz', type = 'ptracks') s = Sql(game = 'razz', type = 'ptracks')

View File

@ -84,7 +84,7 @@ class Importer:
self.fdb.db.rollback() # make sure all locks are released self.fdb.db.rollback() # make sure all locks are released
self.NEWIMPORT = False self.NEWIMPORT = False
self.allow_hudcache_rebuild = True; self.allow_hudcache_rebuild = False;
#Set functions #Set functions
def setCallHud(self, value): def setCallHud(self, value):
@ -199,7 +199,7 @@ class Importer:
self.fdb.afterBulkImport() self.fdb.afterBulkImport()
else: else:
print "No need to rebuild indexes." print "No need to rebuild indexes."
if self.settings['dropHudCache'] == 'drop': if self.allow_hudcache_rebuild and self.settings['dropHudCache'] == 'drop':
self.database.rebuild_hudcache() self.database.rebuild_hudcache()
else: else:
print "No need to rebuild hudcache." print "No need to rebuild hudcache."
@ -323,24 +323,6 @@ class Importer:
filter_name = filter.replace("ToFpdb", "") filter_name = filter.replace("ToFpdb", "")
# Example code for using threads & queues: (maybe for obj and import_fpdb_file??)
#def worker():
# while True:
# item = q.get()
# do_work(item)
# q.task_done()
#
#q = Queue()
#for i in range(num_worker_threads):
# t = Thread(target=worker)
# t.setDaemon(True)
# t.start()
#
#for item in source():
# q.put(item)
#
#q.join() # block until all tasks are done
mod = __import__(filter) mod = __import__(filter)
obj = getattr(mod, filter_name, None) obj = getattr(mod, filter_name, None)
if callable(obj): if callable(obj):
@ -397,6 +379,9 @@ class Importer:
self.pos_in_file[file] = inputFile.tell() self.pos_in_file[file] = inputFile.tell()
inputFile.close() inputFile.close()
# fix fdb and database cursors before using this:
#self.database.lock_for_insert() # ok when using one thread
try: # sometimes we seem to be getting an empty self.lines, in which case, we just want to return. try: # sometimes we seem to be getting an empty self.lines, in which case, we just want to return.
firstline = self.lines[0] firstline = self.lines[0]
except: except: