Skip to content

Commit

Permalink
state.py: reorder things so sqlite never does fdatasync().
Browse files Browse the repository at this point in the history
It was briefly synchronous at data creation time, adding a few ms to
redo startup.
  • Loading branch information
apenwarr committed Dec 10, 2010
1 parent e446d4d commit b5c02e4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions state.py
Expand Up @@ -6,6 +6,13 @@
SCHEMA_VER=1
TIMEOUT=60

def _connect(dbfile):
_db = sqlite3.connect(dbfile, timeout=TIMEOUT)
_db.execute("pragma synchronous = off")
_db.execute("pragma journal_mode = PERSIST")
return _db


_db = None
def db():
global _db
Expand All @@ -22,7 +29,7 @@ def db():
raise
must_create = not os.path.exists(dbfile)
if not must_create:
_db = sqlite3.connect(dbfile, timeout=TIMEOUT)
_db = _connect(dbfile)
try:
row = _db.cursor().execute("select version from Schema").fetchone()
except sqlite3.OperationalError:
Expand All @@ -35,7 +42,7 @@ def db():
_db = None
if must_create:
unlink(dbfile)
_db = sqlite3.connect(dbfile, timeout=TIMEOUT)
_db = _connect(dbfile)
_db.execute("create table Schema "
" (version int)")
_db.execute("create table Runid "
Expand All @@ -60,8 +67,6 @@ def db():
vars.RUNID = _db.execute("select last_insert_rowid()").fetchone()[0]
os.environ['REDO_RUNID'] = str(vars.RUNID)

_db.execute("pragma journal_mode = PERSIST")
_db.execute("pragma synchronous = off")
_db.commit()
return _db

Expand Down

0 comments on commit b5c02e4

Please sign in to comment.