Skip to content

Commit

Permalink
Merge pull request #1590 from MonsieurNicolas/maintenanceTx
Browse files Browse the repository at this point in the history
Adjustment to automatic maintenance

Reviewed-by: jonjove
  • Loading branch information
latobarita authored Mar 8, 2018
2 parents 74cae1e + deb728a commit bd4940e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docs/stellar-core_example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ CATCHUP_RECENT=1024
# This limits the number that will be active at a time.
MAX_CONCURRENT_SUBPROCESSES=10

# AUTOMATIC_MAINTENANCE_PERIOD (integer, seconds) default 3600
# AUTOMATIC_MAINTENANCE_PERIOD (integer, seconds) default 14400
# Interval between automatic maintenance executions
# Set to 0 to disable automatic maintenance
AUTOMATIC_MAINTENANCE_PERIOD=3600
AUTOMATIC_MAINTENANCE_PERIOD=14400

# AUTOMATIC_MAINTENANCE_COUNT (integer) default 50000
# Number of unneeded rows in each table that will be removed during one
# Number of unneeded ledgers in each table that will be removed during one
# maintenance run.
# Set to 0 to disable automatic maintenance
AUTOMATIC_MAINTENANCE_COUNT=5000
Expand Down
5 changes: 4 additions & 1 deletion src/database/DatabaseUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ deleteOldEntriesHelper(soci::session& sess, uint32_t ledgerSeq, uint32_t count,
st.execute(true);
if (st.got_data() && gotMin == soci::i_ok)
{
uint32 m = std::min(curMin + count, ledgerSeq);
uint64 m64 =
std::min<uint64>(static_cast<uint64>(curMin) + count, ledgerSeq);
// safe to cast down as it's at most ledgerSeq
uint64 m = static_cast<uint32>(m64);
sess << "DELETE FROM " << tableName << " WHERE " << ledgerSeqColumn
<< " <= " << m;
}
Expand Down
4 changes: 4 additions & 0 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,13 @@ void
LedgerManagerImpl::deleteOldEntries(Database& db, uint32_t ledgerSeq,
uint32_t count)
{
soci::transaction txscope(db.getSession());
db.clearPreparedStatementCache();
LedgerHeaderFrame::deleteOldEntries(db, ledgerSeq, count);
TransactionFrame::deleteOldEntries(db, ledgerSeq, count);
HerderPersistence::deleteOldEntries(db, ledgerSeq, count);
db.clearPreparedStatementCache();
txscope.commit();
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/main/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Config::Config() : NODE_SEED(SecretKey::random())
MANUAL_CLOSE = false;
CATCHUP_COMPLETE = false;
CATCHUP_RECENT = 0;
AUTOMATIC_MAINTENANCE_PERIOD = std::chrono::seconds{3600};
AUTOMATIC_MAINTENANCE_PERIOD = std::chrono::seconds{14400};
AUTOMATIC_MAINTENANCE_COUNT = 50000;
ARTIFICIALLY_GENERATE_LOAD_FOR_TESTING = false;
ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING = false;
Expand Down
7 changes: 5 additions & 2 deletions src/main/Maintainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ Maintainer::Maintainer(Application& app) : mApp{app}, mTimer{mApp}
void
Maintainer::start()
{
if (mApp.getConfig().AUTOMATIC_MAINTENANCE_PERIOD.count() > 0 &&
mApp.getConfig().AUTOMATIC_MAINTENANCE_COUNT > 0)
auto& c = mApp.getConfig();
if (c.AUTOMATIC_MAINTENANCE_PERIOD.count() > 0 &&
c.AUTOMATIC_MAINTENANCE_COUNT > 0)
{
scheduleMaintenance();
}
}

void
Expand Down

0 comments on commit bd4940e

Please sign in to comment.