state.py: reorder things so sqlite never does fdatasync().
It was briefly synchronous at data creation time, adding a few ms to redo startup.
This commit is contained in:
parent
e446d4dd04
commit
b5c02e410e
1 changed files with 9 additions and 4 deletions
13
state.py
13
state.py
|
|
@ -6,6 +6,13 @@ import helpers
|
||||||
SCHEMA_VER=1
|
SCHEMA_VER=1
|
||||||
TIMEOUT=60
|
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
|
_db = None
|
||||||
def db():
|
def db():
|
||||||
global _db
|
global _db
|
||||||
|
|
@ -22,7 +29,7 @@ def db():
|
||||||
raise
|
raise
|
||||||
must_create = not os.path.exists(dbfile)
|
must_create = not os.path.exists(dbfile)
|
||||||
if not must_create:
|
if not must_create:
|
||||||
_db = sqlite3.connect(dbfile, timeout=TIMEOUT)
|
_db = _connect(dbfile)
|
||||||
try:
|
try:
|
||||||
row = _db.cursor().execute("select version from Schema").fetchone()
|
row = _db.cursor().execute("select version from Schema").fetchone()
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
|
|
@ -35,7 +42,7 @@ def db():
|
||||||
_db = None
|
_db = None
|
||||||
if must_create:
|
if must_create:
|
||||||
unlink(dbfile)
|
unlink(dbfile)
|
||||||
_db = sqlite3.connect(dbfile, timeout=TIMEOUT)
|
_db = _connect(dbfile)
|
||||||
_db.execute("create table Schema "
|
_db.execute("create table Schema "
|
||||||
" (version int)")
|
" (version int)")
|
||||||
_db.execute("create table Runid "
|
_db.execute("create table Runid "
|
||||||
|
|
@ -60,8 +67,6 @@ def db():
|
||||||
vars.RUNID = _db.execute("select last_insert_rowid()").fetchone()[0]
|
vars.RUNID = _db.execute("select last_insert_rowid()").fetchone()[0]
|
||||||
os.environ['REDO_RUNID'] = str(vars.RUNID)
|
os.environ['REDO_RUNID'] = str(vars.RUNID)
|
||||||
|
|
||||||
_db.execute("pragma journal_mode = PERSIST")
|
|
||||||
_db.execute("pragma synchronous = off")
|
|
||||||
_db.commit()
|
_db.commit()
|
||||||
return _db
|
return _db
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue