db_location
anomaly_match.prediction.db_location
¶
Resolve where the live predictions.db lives and keep the session durable.
WAL-mode SQLite always keeps its -wal/-shm sidecars next to the main
.db file, so the whole database must sit on fast local storage to avoid
the WAL bloat a network filesystem (NFS) suffers under a continuous UI reader
(a slow read pins a reader snapshot, no checkpoint can advance past it, and the
WAL grows without bound — it reached 11 GB in practice).
This module is the single source of truth for the live DB path. When
output_dir is on a network filesystem it transparently relocates the DB to a
local-disk scratch directory; :func:prediction_db_path is a pure function of
the config, so every process (the prediction subprocess, the UI poller, the
orchestrating Session) resolves the same location regardless of call order.
:func:prepare_local_db and :func:snapshot_db_to_session keep the portable
session directory seeded and durable around a relocated run.
is_network_filesystem(path)
¶
Report whether path is backed by a known network filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Filesystem path to classify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
the type cannot be determined (e.g. non-Linux platforms). |
Source code in anomaly_match/prediction/db_location.py
prediction_db_path(cfg, output_dir=None)
¶
Return the path to the live predictions.db for cfg.
Pure function of the config — all writers and readers call this so they agree on one location. See the module docstring for the relocation policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Session configuration (DotMap). |
required | |
output_dir
|
str | None
|
Override for the session dir (e.g. a UI chooser selection);
defaults to |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Absolute-or-relative path to |
Source code in anomaly_match/prediction/db_location.py
is_relocated(cfg, output_dir=None)
¶
Whether the live DB lives outside the session dir (in local scratch).
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in anomaly_match/prediction/db_location.py
session_db_path(cfg, output_dir=None)
¶
Path to the durable predictions.db snapshot in the session dir.
This is the portable copy that survives a relocated run (see
:func:snapshot_db_to_session); it equals :func:prediction_db_path when
the DB is not relocated. Centralises the filename so callers don't hard-code
it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Session configuration (DotMap). |
required | |
output_dir
|
str | None
|
Override for the session dir; defaults to |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Path to |
Source code in anomaly_match/prediction/db_location.py
prepare_local_db(cfg)
¶
Create the local scratch dir and seed it from any session snapshot.
Call once before launching prediction subprocesses. No-op when the DB is not relocated. The seed lets a fresh pod resume a run whose durable copy lives in the (networked) session directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Session configuration; |
required |
Source code in anomaly_match/prediction/db_location.py
snapshot_db_to_session(cfg)
¶
Copy the live local DB back into the session dir for durability.
No-op when the DB is not relocated (it already lives in the session). Safe to call between chunks: the chunk subprocess has exited, so the local DB has no open writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Session configuration; the DB is copied into |
required |