constantinSch commited on
Commit
2f95f36
·
1 Parent(s): 737a546

Improve SQLite connection handling for compatibility with FUSE-mounted storage

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -38,12 +38,18 @@ app = Flask(__name__)
38
  # ---------------------------------------------------------------------------
39
 
40
  def get_db() -> sqlite3.Connection:
41
- """Open a SQLite connection with row factory and WAL mode."""
 
 
 
 
 
42
  DB_PATH.parent.mkdir(parents=True, exist_ok=True)
43
  db = sqlite3.connect(str(DB_PATH), timeout=DB_TIMEOUT_SECONDS)
44
  db.row_factory = sqlite3.Row
45
  db.execute(f"PRAGMA busy_timeout = {int(DB_TIMEOUT_SECONDS * 1000)}")
46
- db.execute("PRAGMA journal_mode=WAL")
 
47
  db.execute("""
48
  CREATE TABLE IF NOT EXISTS annotations (
49
  eval_id TEXT PRIMARY KEY,
@@ -193,6 +199,13 @@ def annotate():
193
  ),
194
  )
195
  db.commit()
 
 
 
 
 
 
 
196
  finally:
197
  db.close()
198
  return jsonify({"status": "ok"})
 
38
  # ---------------------------------------------------------------------------
39
 
40
  def get_db() -> sqlite3.Connection:
41
+ """Open a SQLite connection with row factory.
42
+
43
+ Uses DELETE journal mode instead of WAL for compatibility with
44
+ FUSE-mounted persistent storage on Hugging Face Spaces where mmap
45
+ (required by WAL's shared-memory file) is unreliable.
46
+ """
47
  DB_PATH.parent.mkdir(parents=True, exist_ok=True)
48
  db = sqlite3.connect(str(DB_PATH), timeout=DB_TIMEOUT_SECONDS)
49
  db.row_factory = sqlite3.Row
50
  db.execute(f"PRAGMA busy_timeout = {int(DB_TIMEOUT_SECONDS * 1000)}")
51
+ db.execute("PRAGMA journal_mode=DELETE")
52
+ db.execute("PRAGMA synchronous=FULL")
53
  db.execute("""
54
  CREATE TABLE IF NOT EXISTS annotations (
55
  eval_id TEXT PRIMARY KEY,
 
199
  ),
200
  )
201
  db.commit()
202
+ # Verify the write persisted (guards against silent FUSE write failures)
203
+ row = db.execute(
204
+ "SELECT eval_id FROM annotations WHERE eval_id = ?",
205
+ (data["eval_id"],),
206
+ ).fetchone()
207
+ if not row:
208
+ return jsonify({"error": "write verification failed"}), 500
209
  finally:
210
  db.close()
211
  return jsonify({"status": "ok"})