Skip to content

Commit

Permalink
Change scheduled DB passivations to use RegistryBookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Apr 8, 2024
1 parent 21f28f5 commit 8154056
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 111 deletions.
15 changes: 0 additions & 15 deletions src/gridcoin/beacon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,21 +1391,6 @@ BeaconRegistry::BeaconDB &BeaconRegistry::GetBeaconDB()
return m_beacon_db;
}

// This is static and called by the scheduler.
void BeaconRegistry::RunDBPassivation()
{
TRY_LOCK(cs_main, locked_main);

if (!locked_main)
{
return;
}

BeaconRegistry& beacons = GetBeaconRegistry();

beacons.PassivateDB();
}

template<> const std::string BeaconRegistry::BeaconDB::KeyType()
{
return std::string("beacon");
Expand Down
7 changes: 1 addition & 6 deletions src/gridcoin/beacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ class BeaconRegistry : public IContractHandler
//!
//! \return The number of elements passivated.
//!
uint64_t PassivateDB();
uint64_t PassivateDB() override;

//!
//! \brief This function walks the linked beacon entries back (using the m_previous_hash member) from a provided
Expand All @@ -795,11 +795,6 @@ class BeaconRegistry : public IContractHandler
//!
bool SetNeedsIsContractCorrection(bool flag);

//!
//! \brief A static function that is called by the scheduler to run the beacon database passivation.
//!
static void RunDBPassivation();

//!
//! \brief Specializes the template RegistryDB for the ScraperEntry class
//!
Expand Down
15 changes: 15 additions & 0 deletions src/gridcoin/contract/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef GRIDCOIN_CONTRACT_HANDLER_H
#define GRIDCOIN_CONTRACT_HANDLER_H

#include <cstdint>
#include <string>

class CBlockIndex;
Expand Down Expand Up @@ -153,6 +154,20 @@ struct IContractHandler
//! \param height
//!
virtual void SetDBHeight(int& height);

//!
//! \brief Passivates the elements in the underlying db, which means remove from memory elements in the
//! historical map that are not referenced by any of the in memory maps. The backing store of
//! the element removed from memory is retained and will be transparently restored if find()
//! is called on the hash key for the element.
//!
//! \return The number of elements passivated.
//!
virtual uint64_t PassivateDB()
{
// The default method here does nothing.
return uint64_t {0};
};
};

} // namespace GRC
Expand Down
17 changes: 12 additions & 5 deletions src/gridcoin/gridcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,8 @@ void ScheduleRegistriesPassivation(CScheduler& scheduler)
{
// Run registry database passivation every 5 minutes. This is a very thin call most of the time.
// Please see the PassivateDB function and passivate_db.
// TODO: Turn into a loop using extension of RegistryBookmarks
scheduler.scheduleEvery(BeaconRegistry::RunDBPassivation, std::chrono::minutes{5});
scheduler.scheduleEvery(ScraperRegistry::RunDBPassivation, std::chrono::minutes{5});
scheduler.scheduleEvery(ProtocolRegistry::RunDBPassivation, std::chrono::minutes{5});
scheduler.scheduleEvery(Whitelist::RunDBPassivation, std::chrono::minutes{5});

scheduler.scheduleEvery(RunDBPassivation, std::chrono::minutes{5});
}
} // Anonymous namespace

Expand Down Expand Up @@ -608,3 +605,13 @@ skip:;
return true;
}

void GRC::RunDBPassivation()
{
LOCK(cs_main);

for (const auto& contract_type : RegistryBookmarks::CONTRACT_TYPES_WITH_REG_DB) {
Registry& registry = RegistryBookmarks::GetRegistryWithDB(contract_type);

registry.PassivateDB();
}
}
6 changes: 6 additions & 0 deletions src/gridcoin/gridcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ void ScheduleBackgroundJobs(CScheduler& scheduler);
//! \return \c true if no errors occurred.
//!
bool CleanConfig();

//!
//! \brief Function to allow cycling through DB passivation for all contract types backed
//! with registry db.
//!
void RunDBPassivation();
} // namespace GRC

#endif // GRIDCOIN_GRIDCOIN_H
15 changes: 0 additions & 15 deletions src/gridcoin/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,21 +541,6 @@ Whitelist::ProjectEntryDB &Whitelist::GetProjectDB()
return m_project_db;
}

// This is static and called by the scheduler.
void Whitelist::RunDBPassivation()
{
TRY_LOCK(cs_main, locked_main);

if (!locked_main)
{
return;
}

Whitelist& project_entries = GetWhitelist();

project_entries.PassivateDB();
}

template<> const std::string Whitelist::ProjectEntryDB::KeyType()
{
return std::string("project");
Expand Down
9 changes: 2 additions & 7 deletions src/gridcoin/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,19 +603,14 @@ class Whitelist : public IContractHandler
void ResetInMemoryOnly();

//!
//! \brief Passivates the elements in the scraper db, which means remove from memory elements in the
//! \brief Passivates the elements in the project db, which means remove from memory elements in the
//! historical map that are not referenced by m_projects. The backing store of the element removed
//! from memory is retained and will be transparently restored if find() is called on the hash key
//! for the element.
//!
//! \return The number of elements passivated.
//!
uint64_t PassivateDB();

//!
//! \brief A static function that is called by the scheduler to run the project entry database passivation.
//!
static void RunDBPassivation();
uint64_t PassivateDB() override;

//!
//! \brief Specializes the template RegistryDB for the ScraperEntry class. Note that std::set<ProjectEntry> is not
Expand Down
15 changes: 0 additions & 15 deletions src/gridcoin/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,21 +528,6 @@ ProtocolRegistry::ProtocolEntryDB &ProtocolRegistry::GetProtocolEntryDB()
return m_protocol_db;
}

// This is static and called by the scheduler.
void ProtocolRegistry::RunDBPassivation()
{
TRY_LOCK(cs_main, locked_main);

if (!locked_main)
{
return;
}

ProtocolRegistry& protocol_entries = GetProtocolRegistry();

protocol_entries.PassivateDB();
}

template<> const std::string ProtocolRegistry::ProtocolEntryDB::KeyType()
{
return std::string("protocol");
Expand Down
7 changes: 1 addition & 6 deletions src/gridcoin/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,7 @@ class ProtocolRegistry : public IContractHandler
//!
//! \return The number of elements passivated.
//!
uint64_t PassivateDB();

//!
//! \brief A static function that is called by the scheduler to run the protocol entry database passivation.
//!
static void RunDBPassivation();
uint64_t PassivateDB() override;

//!
//! \brief Specializes the template RegistryDB for the ProtocolEntry class. Note that std::set<ProtocolEntry>
Expand Down
15 changes: 0 additions & 15 deletions src/gridcoin/scraper/scraper_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,21 +573,6 @@ ScraperRegistry::ScraperEntryDB &ScraperRegistry::GetScraperDB()
return m_scraper_db;
}

// This is static and called by the scheduler.
void ScraperRegistry::RunDBPassivation()
{
TRY_LOCK(cs_main, locked_main);

if (!locked_main)
{
return;
}

ScraperRegistry& scraper_entries = GetScraperRegistry();

scraper_entries.PassivateDB();
}

template<> const std::string ScraperRegistry::ScraperEntryDB::KeyType()
{
return std::string("scraper");
Expand Down
7 changes: 1 addition & 6 deletions src/gridcoin/scraper/scraper_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,7 @@ class ScraperRegistry : public IContractHandler
//!
//! \return The number of elements passivated.
//!
uint64_t PassivateDB();

//!
//! \brief A static function that is called by the scheduler to run the scraper entry database passivation.
//!
static void RunDBPassivation();
uint64_t PassivateDB() override;

//!
//! \brief Specializes the template RegistryDB for the ScraperEntry class. Note that std::set<ScraperEntry> is
Expand Down
15 changes: 0 additions & 15 deletions src/gridcoin/sidestake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,21 +1164,6 @@ SideStakeRegistry::SideStakeDB &SideStakeRegistry::GetSideStakeDB()
return m_sidestake_db;
}

// This is static and called by the scheduler.
void SideStakeRegistry::RunDBPassivation()
{
TRY_LOCK(cs_main, locked_main);

if (!locked_main)
{
return;
}

SideStakeRegistry& SideStake_entries = GetSideStakeRegistry();

SideStake_entries.PassivateDB();
}

template<> const std::string SideStakeRegistry::SideStakeDB::KeyType()
{
return std::string("SideStake");
Expand Down
7 changes: 1 addition & 6 deletions src/gridcoin/sidestake.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,19 +830,14 @@ class SideStakeRegistry : public IContractHandler
//!
//! \return The number of elements passivated.
//!
uint64_t PassivateDB();
uint64_t PassivateDB() override;

//!
//! \brief This method parses the config file for local sidestakes. It is based on the original GetSideStakingStatusAndAlloc()
//! that was in miner.cpp prior to the implementation of the SideStake class.
//!
void LoadLocalSideStakesFromConfig();

//!
//! \brief A static function that is called by the scheduler to run the sidestake entry database passivation.
//!
static void RunDBPassivation();

//!
//! \brief Specializes the template RegistryDB for the SideStake class. Note that std::set<MandatorySideStake>
//! is not actually used.
Expand Down

0 comments on commit 8154056

Please sign in to comment.