Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(db): close the review findings on the durability setting
Alexander Eichhorn0a945ad821fd
diff --git a/docs/src/content/docs/configuration/invokeai-yaml.mdx b/docs/src/content/docs/configuration/invokeai-yaml.mdxindex 8337858a1e..0984a019cf 100644--- a/docs/src/content/docs/configuration/invokeai-yaml.mdx+++ b/docs/src/content/docs/configuration/invokeai-yaml.mdx@@ -236,7 +236,7 @@ db_synchronous: full # default valueThe setting can also be given as the `INVOKEAI_DB_SYNCHRONOUS` environment variable.-**`normal` cannot corrupt the database.** InvokeAI runs SQLite in WAL mode, and WAL guarantees a consistent database either way. What `normal` gives up is the *most recent transactions* if the machine loses power or the OS crashes mid-write — a just-written image record or a queue status. The image file itself is already on disk and can be recovered by the orphan scan; the row pointing at it is what would be missing.+**`normal` cannot corrupt the database.** InvokeAI runs SQLite in WAL mode, and WAL guarantees a consistent database either way. What `normal` gives up is the *most recent transactions* if the machine loses power or the OS crashes mid-write — a just-written image record or a queue status. The image file itself survives on disk, but nothing rebuilds the row, and the gallery is driven by the database: the image is simply gone from it. The gallery orphan scan does not heal this — it *archives* record-less files out of `outputs/` so you can delete them or re-import them, which takes the separate `invokeai/frontend/install/import_images.py` script.Measured on a copy of a real library, 300 single-row inserts each committed on its own:diff --git a/docs/src/generated/settings.json b/docs/src/generated/settings.jsonindex ff1f4a4312..f4267a71e6 100644--- a/docs/src/generated/settings.json+++ b/docs/src/generated/settings.json@@ -202,6 +202,20 @@"type": "<class 'pathlib.Path'>","validation": {}},+ {+ "category": "PATHS",+ "default": "full",+ "description": "SQLite durability setting. `full` (the default) flushes every commit to disk. `normal` acknowledges commits without waiting for that flush - measured at roughly 12x shorter commits on an SSD - and cannot corrupt the database, because WAL guarantees consistency either way. What it gives up is the most recent transactions on a power loss or OS crash: a just-written image record or queue status, not the image file itself.",+ "env_var": "INVOKEAI_DB_SYNCHRONOUS",+ "literal_values": [+ "full",+ "normal"+ ],+ "name": "db_synchronous",+ "required": false,+ "type": "typing.Literal['full', 'normal']",+ "validation": {}+ },{"category": "PATHS","default": "outputs",diff --git a/invokeai/app/services/shared/sqlite/sqlite_database.py b/invokeai/app/services/shared/sqlite/sqlite_database.pyindex c2a9f7c5a7..cfd788888a 100644--- a/invokeai/app/services/shared/sqlite/sqlite_database.py+++ b/invokeai/app/services/shared/sqlite/sqlite_database.py@@ -65,7 +65,7 @@ class SqliteDatabase:self._conn.execute("PRAGMA busy_timeout = 5000;") # 5 seconds# Durability. SQLite's own default is `full`, which fsyncs on every commit; `normal` under WAL- # trades the last transactions on a power loss or OS crash for roughly 6x shorter commits. It+ # trades the last transactions on a power loss or OS crash for roughly 12x shorter commits. It# cannot corrupt the database -- that is WAL's guarantee either way. Shorter commits matter# twice here, because every write holds the lock that serialises all database work.#diff --git a/invokeai/app/util/user_management.py b/invokeai/app/util/user_management.pyindex 9c9c738f86..e9c7808279 100644--- a/invokeai/app/util/user_management.py+++ b/invokeai/app/util/user_management.py@@ -107,7 +107,7 @@ def _add_user_interactive() -> bool:try:config = get_config()- db = SqliteDatabase(config.db_path, InvokeAILogger.get_logger())+ db = SqliteDatabase(config.db_path, InvokeAILogger.get_logger(), synchronous=config.db_synchronous)user_service = UserService(db)user_data = UserCreateRequest(email=email, display_name=display_name, password=password, is_admin=is_admin)@@ -148,7 +148,7 @@ def _add_user_cli(email: str, password: str, display_name: str | None = None, istry:config = get_config()- db = SqliteDatabase(config.db_path, InvokeAILogger.get_logger())+ db = SqliteDatabase(config.db_path, InvokeAILogger.get_logger(), synchronous=config.db_synchronous)user_service = UserService(db)user_data = UserCreateRequest(email=email, display_name=display_name, password=password, is_admin=is_admin)@@ -224,7 +224,7 @@ def _delete_user_interactive() -> bool:try:config = get_config()logger = InvokeAILogger.get_logger(config=config)- db = SqliteDatabase(config.db_path, logger)+ db = SqliteDatabase(config.db_path, logger, synchronous=config.db_synchronous)user_service = UserService(db)user = user_service.get_by_email(email)@@ -272,7 +272,7 @@ def _delete_user_cli(email: str, force: bool = False) -> bool:try:config = get_config()logger = InvokeAILogger.get_logger(config=config)- db = SqliteDatabase(config.db_path, logger)+ db = SqliteDatabase(config.db_path, logger, synchronous=config.db_synchronous)user_service = UserService(db)user = user_service.get_by_email(email)@@ -348,7 +348,7 @@ def _list_users_table() -> bool:config = get_config()logger = InvokeAILogger.get_logger(config=config)- db = SqliteDatabase(config.db_path, logger)+ db = SqliteDatabase(config.db_path, logger, synchronous=config.db_synchronous)user_service = UserService(db)try:@@ -388,7 +388,7 @@ def _list_users_json() -> bool:config = get_config()logger = InvokeAILogger.get_logger(config=config)- db = SqliteDatabase(config.db_path, logger)+ db = SqliteDatabase(config.db_path, logger, synchronous=config.db_synchronous)user_service = UserService(db)try:@@ -463,7 +463,7 @@ def _modify_user_interactive() -> bool:try:config = get_config()- db = SqliteDatabase(config.db_path, InvokeAILogger.get_logger())+ db = SqliteDatabase(config.db_path, InvokeAILogger.get_logger(), synchronous=config.db_synchronous)user_service = UserService(db)user = user_service.get_by_email(email)@@ -564,7 +564,7 @@ def _modify_user_cli(try:config = get_config()- db = SqliteDatabase(config.db_path, InvokeAILogger.get_logger())+ db = SqliteDatabase(config.db_path, InvokeAILogger.get_logger(), synchronous=config.db_synchronous)user_service = UserService(db)user = user_service.get_by_email(email)