Preserve attachment files when shutdown sees an open transaction
This commit is contained in:
1 parent
6bbd41f49f
commit
52d8ec4e49
2 files changed
+11
-3
No files matched your search
@@ -1349,6 +1349,9 @@ static void ak_recover_temps(struct UTUN_INSTANCE* inst) {
|
||||
/* После crash/отмены убрать только собственные подготовки, не имеющие сообщения.
|
||||
* Вызывается до запуска workers либо после их полного завершения. */
|
||||
static void ak_recover_preparations(struct UTUN_INSTANCE* inst) {
|
||||
if (!sqlite3_get_autocommit(CC(inst)->db)) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "attachment keys: preparation recovery deferred while transaction is open; files preserved"); return;
|
||||
}
|
||||
ak_recover_temps(inst);
|
||||
char base[MEDIA_BASE_MAX];
|
||||
if (media_index_get_base(CC(inst)->db, base)) return;
|
||||
@@ -1392,7 +1395,12 @@ static void ak_recover_preparations(struct UTUN_INSTANCE* inst) {
|
||||
|
||||
/* Отдельные локальные таблицы никогда не регистрируются в db_sync/Merkle. */
|
||||
int chat_attachment_init(struct UTUN_INSTANCE* inst) {
|
||||
if (!CC(inst) || !inst->media_async) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment keys: invalid initialization"); return -1; }
|
||||
if (!inst || !CC(inst) || !inst->media_async) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment keys: invalid initialization"); return -1;
|
||||
}
|
||||
if (!sqlite3_get_autocommit(CC(inst)->db)) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment keys: initialization rejected inside external transaction"); return -1;
|
||||
}
|
||||
if (ak_exec(inst, "CREATE TABLE IF NOT EXISTS attachment_keys("
|
||||
"channel TEXT NOT NULL,crypto_id BLOB NOT NULL CHECK(length(crypto_id)=16),message_id BLOB,author INTEGER NOT NULL,"
|
||||
"key BLOB CHECK(key IS NULL OR length(key)=32),cipher_hash BLOB,cipher_path TEXT NOT NULL,plain_path TEXT NOT NULL,"
|
||||
|
||||
@@ -28,13 +28,13 @@ struct UTUN_INSTANCE;
|
||||
|
||||
// ── Жизненный цикл модуля ──
|
||||
|
||||
// Подключить таблицы, router-сервис и обработку сохранённых задач; 0/-1.
|
||||
// Подключить таблицы, router-сервис и обработку сохранённых задач; 0/-1. Внешняя транзакция запрещена.
|
||||
int chat_attachment_init(struct UTUN_INSTANCE* inst);
|
||||
|
||||
// Запретить новые подготовки и остановить таймер; запущенные workers завершаются отдельно.
|
||||
void chat_attachment_quiesce(struct UTUN_INSTANCE* inst);
|
||||
|
||||
// После завершения workers убрать незавершённые подготовки и отключить router-сервис.
|
||||
// После workers убрать незавершённые подготовки; открытая транзакция откладывает recovery, сохраняя файлы.
|
||||
void chat_attachment_destroy(struct UTUN_INSTANCE* inst);
|
||||
|
||||
// ── Отправка и учёт вложений ──
|
||||
|
||||
Reference in new issue
Block a user