Streamline ILoadManager interface

This commit is contained in:
Vinnie Falco
2013-07-03 06:22:39 -07:00
parent 7a1bc5435e
commit 47ceb0440d
5 changed files with 55 additions and 42 deletions

View File

@@ -1347,9 +1347,6 @@
<ClInclude Include="..\..\src\cpp\ripple\ripple_IHashRouter.h"> <ClInclude Include="..\..\src\cpp\ripple\ripple_IHashRouter.h">
<Filter>[1] Ripple\ripple_app\_misc</Filter> <Filter>[1] Ripple\ripple_app\_misc</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\cpp\ripple\ripple_ILoadManager.h">
<Filter>[1] Ripple\ripple_app\_misc</Filter>
</ClInclude>
<ClInclude Include="..\..\src\cpp\ripple\ripple_InfoSub.h"> <ClInclude Include="..\..\src\cpp\ripple\ripple_InfoSub.h">
<Filter>[1] Ripple\ripple_app\_misc</Filter> <Filter>[1] Ripple\ripple_app\_misc</Filter>
</ClInclude> </ClInclude>
@@ -1533,6 +1530,9 @@
<ClInclude Include="..\..\src\cpp\ripple\WalletAddTransactor.h"> <ClInclude Include="..\..\src\cpp\ripple\WalletAddTransactor.h">
<Filter>[1] Ripple\ripple_app\_transactions</Filter> <Filter>[1] Ripple\ripple_app\_transactions</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\cpp\ripple\ripple_ILoadManager.h">
<Filter>[1] Ripple\ripple_app\_main</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="..\..\src\cpp\ripple\ripple.proto" /> <CustomBuild Include="..\..\src\cpp\ripple\ripple.proto" />

View File

@@ -31,6 +31,10 @@ WEBSOCKET TODO
RIPPLE TODO RIPPLE TODO
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
- Remove dependence on JobQueue, LoadFeeTrack, and NetworkOPs from LoadManager
by providing an observer (beast::ListenerList or Listeners). This way
LoadManager does not need stopThread() function.
- Move everything in src/cpp/ripple into ripple_app and sort them into - Move everything in src/cpp/ripple into ripple_app and sort them into
subdirectories within the module as per the project filters. subdirectories within the module as per the project filters.
* Make sure there are no pending commits from David * Make sure there are no pending commits from David

View File

@@ -266,7 +266,20 @@ private:
}; };
Application::Application () Application::Application ()
//
// VFALCO NOTE Change this to control whether or not the Application
// object is destroyed on exit
//
#if 1
// Application object will be deleted on exit. If the code doesn't exit
// cleanly this could cause hangs or crashes on exit.
//
: SharedSingleton <Application> (SingletonLifetime::persistAfterCreation) : SharedSingleton <Application> (SingletonLifetime::persistAfterCreation)
#else
// This will make it so that the Application object is not deleted on exit.
//
: SharedSingleton <Application> (SingletonLifetime::neverDestroyed)
#endif
, mIOService ((theConfig.NODE_SIZE >= 2) ? 2 : 1) , mIOService ((theConfig.NODE_SIZE >= 2) ? 2 : 1)
, mIOWork (mIOService) , mIOWork (mIOService)
, mAuxWork (mAuxService) , mAuxWork (mAuxService)
@@ -308,6 +321,21 @@ Application::Application ()
HashMaps::getInstance ().initializeNonce <size_t> (); HashMaps::getInstance ().initializeNonce <size_t> ();
} }
Application::~Application ()
{
// VFALCO TODO Wrap these in ScopedPointer
delete mTxnDB;
delete mLedgerDB;
delete mWalletDB;
delete mHashNodeDB;
delete mNetNodeDB;
delete mPathFindDB;
delete mHashNodeLDB;
if (mEphemeralLDB != nullptr)
delete mEphemeralLDB;
}
// VFALCO TODO Tidy these up into some class with accessors. // VFALCO TODO Tidy these up into some class with accessors.
// //
extern const char* RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], extern const char* RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[],
@@ -666,10 +694,18 @@ void Application::run ()
if (mWSPrivateDoor) if (mWSPrivateDoor)
mWSPrivateDoor->stop (); mWSPrivateDoor->stop ();
getApp().getLoadManager().stopThread(); // VFALCO TODO Try to not have to do this early, by using observers to
// eliminate LoadManager's dependency inversions.
//
// This deletes the object and therefore, stops the thread.
m_loadManager = nullptr;
mSweepTimer.cancel(); mSweepTimer.cancel();
WriteLog (lsINFO, Application) << "Done."; WriteLog (lsINFO, Application) << "Done.";
// VFALCO NOTE This is a sign that something is wrong somewhere, it
// shouldn't be necessary to sleep until some flag is set.
while (mShutdown) while (mShutdown)
boost::this_thread::sleep (boost::posix_time::milliseconds (100)); boost::this_thread::sleep (boost::posix_time::milliseconds (100));
} }
@@ -705,21 +741,6 @@ void Application::sweep ()
mSweepTimer.async_wait (BIND_TYPE (&Application::sweep, this)); mSweepTimer.async_wait (BIND_TYPE (&Application::sweep, this));
} }
Application::~Application ()
{
// VFALCO TODO Wrap these in ScopedPointer
delete mTxnDB;
delete mLedgerDB;
delete mWalletDB;
delete mHashNodeDB;
delete mNetNodeDB;
delete mPathFindDB;
delete mHashNodeLDB;
if (mEphemeralLDB != nullptr)
delete mEphemeralLDB;
}
void Application::startNewLedger () void Application::startNewLedger ()
{ {
// New stuff. // New stuff.

View File

@@ -208,23 +208,27 @@ class ILoadManager
public: public:
/** Create a new manager. /** Create a new manager.
The manager thread begins running immediately.
@note The thresholds for warnings and punishments are in @note The thresholds for warnings and punishments are in
the ctor-initializer the ctor-initializer
*/ */
static ILoadManager* New (); static ILoadManager* New ();
/** Destroy the manager.
The destructor returns only after the thread has stopped.
*/
virtual ~ILoadManager () { } virtual ~ILoadManager () { }
/** Start the associated thread. /** Start the associated thread.
This is here to prevent the deadlock detector from activating during This is here to prevent the deadlock detector from activating during
a lengthy program initialization. a lengthy program initialization.
@note In stand-alone mode, this might not get called.
*/ */
// VFALCO TODO Simplify the two stage initialization to one stage (construction). // VFALCO TODO Simplify the two stage initialization to one stage (construction).
// NOTE In stand-alone mode the load manager thread isn't started
virtual void startThread () = 0; virtual void startThread () = 0;
virtual void stopThread () = 0;
/** Turn on deadlock detection. /** Turn on deadlock detection.

View File

@@ -67,7 +67,6 @@ public:
, mDebitWarn (-500) , mDebitWarn (-500)
, mDebitLimit (-1000) , mDebitLimit (-1000)
, mArmed (false) , mArmed (false)
, mRunning (false)
, mDeadLock (0) , mDeadLock (0)
, mCosts (LT_MAX) , mCosts (LT_MAX)
{ {
@@ -110,6 +109,8 @@ public:
addCost (Cost (LT_RequestData, -5, flagDisk | flagNet)); addCost (Cost (LT_RequestData, -5, flagDisk | flagNet));
addCost (Cost (LT_CheapQuery, -1, flagCpu)); addCost (Cost (LT_CheapQuery, -1, flagCpu));
UptimeTimer::getInstance ().beginManualUpdates ();
} }
private: private:
@@ -117,29 +118,12 @@ private:
{ {
UptimeTimer::getInstance ().endManualUpdates (); UptimeTimer::getInstance ().endManualUpdates ();
if (mRunning) m_thread.interrupt ();
{
m_thread.interrupt ();
m_thread.join ();
}
} }
void startThread () void startThread ()
{ {
UptimeTimer::getInstance ().beginManualUpdates ();
m_thread.start (this); m_thread.start (this);
mRunning = true;
}
void stopThread()
{
if (mRunning)
{
m_thread.interrupt ();
m_thread.join ();
mRunning = false;
}
} }
void canonicalize (LoadSource& source, int now) const void canonicalize (LoadSource& source, int now) const
@@ -417,7 +401,7 @@ private:
int mDebitWarn; // when a source drops below this, we warn int mDebitWarn; // when a source drops below this, we warn
int mDebitLimit; // when a source drops below this, we cut it off (should be negative) int mDebitLimit; // when a source drops below this, we cut it off (should be negative)
bool mArmed, mRunning; bool mArmed;
int mDeadLock; // Detect server deadlocks int mDeadLock; // Detect server deadlocks