def __init__(self, conn, table, nohist):
self.conn = conn
self.nohist = nohist
+ self.dirty = False
if nohist:
self.table = "%s_nohist" % table
else:
self.conn.commit()
self._execute("BEGIN EXCLUSIVE TRANSACTION")
+ def sync_if_dirty(self):
+ if self.dirty:
+ self.sync()
+ self.dirty = False
+
def _getValueHist(self, version, pkgarch, checksum):
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
+ self.dirty = True
+
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
row=data.fetchone()
logger.error(str(exc))
self.conn.rollback()
+ self.dirty = True
+
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
row=data.fetchone()
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
+ self.dirty = True
+
data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
row = data.fetchone()
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
+ self.dirty = True
+
data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=? AND value>=?;" % self.table,
(version,pkgarch,checksum,value))
row=data.fetchone()
def work_forever(self,):
self.quit = False
self.timeout = 0.5
+ iter_count = 1
+ # With 60 iterations between syncs and a 0.5 second timeout between
+ # iterations, this will sync if dirty every ~30 seconds.
+ iterations_between_sync = 60
logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
(self.dbfile, self.host, self.port, str(os.getpid())))
self.handlerthread.start()
while not self.quit:
self.handle_request()
+ iter_count = (iter_count + 1) % iterations_between_sync
+ if iter_count == 0:
+ self.table.sync_if_dirty()
self.table.sync()
logger.info("PRServer: stopping...")