3
3
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
4
4
5
5
#include " main/Maintainer.h"
6
+ #include " herder/HerderPersistence.h"
7
+ #include " ledger/LedgerHeaderUtils.h"
6
8
#include " ledger/LedgerManager.h"
7
9
#include " main/Application.h"
8
10
#include " main/Config.h"
25
27
Maintainer::start ()
26
28
{
27
29
ZoneScoped;
30
+ releaseAssert (threadIsMain ());
28
31
auto & c = mApp .getConfig ();
29
32
if (c.AUTOMATIC_MAINTENANCE_PERIOD .count () > 0 &&
30
33
c.AUTOMATIC_MAINTENANCE_COUNT > 0 )
@@ -51,6 +54,7 @@ Maintainer::start()
51
54
void
52
55
Maintainer::scheduleMaintenance ()
53
56
{
57
+ releaseAssert (threadIsMain ());
54
58
mTimer .expires_from_now (mApp .getConfig ().AUTOMATIC_MAINTENANCE_PERIOD );
55
59
mTimer .async_wait ([this ]() { tick (); }, VirtualTimer::onFailureNoop);
56
60
}
59
63
Maintainer::tick ()
60
64
{
61
65
ZoneScoped;
66
+ releaseAssert (threadIsMain ());
62
67
performMaintenance (mApp .getConfig ().AUTOMATIC_MAINTENANCE_COUNT );
63
68
scheduleMaintenance ();
64
69
}
67
72
Maintainer::performMaintenance (uint32_t count)
68
73
{
69
74
ZoneScoped;
75
+ releaseAssert (threadIsMain ());
76
+
70
77
LOG_INFO (DEFAULT_LOG, " Performing maintenance" );
71
78
auto logSlow = LogSlowExecution (
72
79
" Performing maintenance" , LogSlowExecution::Mode::AUTOMATIC_RAII,
@@ -88,6 +95,25 @@ Maintainer::performMaintenance(uint32_t count)
88
95
89
96
CLOG_INFO (History, " Trimming history <= ledger {}" , lmin);
90
97
91
- mApp .getLedgerManager ().deleteOldEntries (mApp .getDatabase (), lmin, count);
98
+ // Cleanup SCP history, always from main
99
+ HerderPersistence::deleteOldEntries (mApp .getDatabase ().getRawSession (),
100
+ lmin, count);
101
+
102
+ if (mApp .getConfig ().parallelLedgerClose ())
103
+ {
104
+ // Cleanup headers from background, to avoid conflicts with closing
105
+ // ledgers
106
+ mApp .postOnLedgerCloseThread (
107
+ [&db = mApp .getDatabase (), lmin, count]() {
108
+ auto session = std::make_unique<soci::session>(db.getPool ());
109
+ LedgerHeaderUtils::deleteOldEntries (*session, lmin, count);
110
+ },
111
+ " maintenance: deleteOldEntries" );
112
+ }
113
+ else
114
+ {
115
+ LedgerHeaderUtils::deleteOldEntries (mApp .getDatabase ().getRawSession (),
116
+ lmin, count);
117
+ }
92
118
}
93
119
}
0 commit comments