Yield the event loop between bounded history maintenance batches

This commit is contained in:
evgeny committed 2026-10-26 18:27:26 +01:00
1 parent 3a4143183d
commit a46091cb19
3 files changed
+5 -4

No files matched your search

+2 -2
View File
@@ -565,7 +565,7 @@ static void db_index_tick(void* arg) {
if (!si->enabled || !si->index.pending) return;
int rc = db_index_batch(si);
if (si->index.pending && merkle_sync_registered(si->db_sync->inst, MT_DATA_MESSAGES)) {
si->index.timer = uasync_set_timeout(si->db_sync->inst->ua, rc ? 50000 : 0, si, db_index_tick, "history_preflight");
si->index.timer = uasync_set_timeout(si->db_sync->inst->ua, rc ? 50000 : 1, si, db_index_tick, "history_preflight");
if (!si->index.timer) { db_error(si, "preflight timer"); db_sync_resume_peer_check(si->db_sync); }
}
}
@@ -920,7 +920,7 @@ static void db_ttl_tick(void* arg) {
SI_TBL(si), removed, (unsigned long long)cut);
}
schedule:
uint64_t delay = committed && removed == DB_BATCH_RECORDS ? 0 : DB_SYNC_TTL_INTERVAL * 10000ULL;
uint64_t delay = committed && removed == DB_BATCH_RECORDS ? 1 : DB_SYNC_TTL_INTERVAL * 10000ULL;
si->ttl_timer = uasync_set_timeout(si->db_sync->inst->ua, delay, si, db_ttl_tick, "history_ttl");
if (!si->ttl_timer) { db_error(si, "TTL timer"); db_sync_resume_peer_check(si->db_sync); }
}
+1 -1
View File
@@ -848,7 +848,7 @@ test_db_sync_integrity_SOURCES = test_db_sync_integrity.c
test_db_sync_integrity_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib
test_db_sync_integrity_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS)
test_db_sync_integrity_LDFLAGS = -Wl,--wrap=EVP_DigestVerifyInit -Wl,--wrap=sqlite3_exec -Wl,--wrap=uasync_set_timeout \
-Wl,--wrap=sqlite3_column_blob -Wl,--wrap=sqlite3_errcode
-Wl,--wrap=sqlite3_column_blob -Wl,--wrap=sqlite3_errcode -Wl,--wrap=chat_message_id
endif
test_merkle_sync_SOURCES = test_merkle_sync.c $(test_clock_sources)
+2 -1
View File
@@ -283,7 +283,8 @@ static void test_ttl(void) {
assert(db_sync_verify(f.si) == 0);
db_ttl_tick(f.si);
assert(db_sync_count(f.si) == 5 && f.si->index.pending && sqlite3_get_autocommit(f.db.db));
uasync_poll(f.inst.ua, 0);
uint64_t deadline = get_time_tb() + 10000;
while (db_sync_count(f.si) != 2 && get_time_tb() < deadline) uasync_poll(f.inst.ua, 1);
assert(db_sync_count(f.si) == 2 && db_sync_verify(f.si) == 0);
destroy(&f); u_free(config);
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "PASS TTL uses milliseconds and short batches, preserving fresh and individually acknowledged records");