1
0
Fork 0

fixed startup race condition

This commit is contained in:
Jan Steemann 2014-02-21 08:47:24 +01:00
parent 060fb00626
commit 2f6f59e228
5 changed files with 54 additions and 23 deletions

View File

@ -155,14 +155,12 @@ bool ApplicationCluster::prepare () {
}
}
// initialise ClusterInfo library
ClusterInfo::initialise();
// initialise ClusterComm library
ClusterComm::initialise();
// initialise cluster info library
ClusterInfo::instance();
usleep(1000);
return true;
}

View File

@ -59,14 +59,8 @@ void triagens::arango::ClusterCommRestCallback(string& coordinator,
/// @brief ClusterComm constructor
////////////////////////////////////////////////////////////////////////////////
ClusterComm::ClusterComm () {
_backgroundThread = new ClusterCommThread();
if (0 == _backgroundThread) {
LOG_FATAL_AND_EXIT("unable to start ClusterComm background thread");
}
if (! _backgroundThread->init() || ! _backgroundThread->start()) {
LOG_FATAL_AND_EXIT("ClusterComm background thread does not work");
}
ClusterComm::ClusterComm () :
_backgroundThread(0) {
}
////////////////////////////////////////////////////////////////////////////////
@ -74,10 +68,13 @@ ClusterComm::ClusterComm () {
////////////////////////////////////////////////////////////////////////////////
ClusterComm::~ClusterComm () {
_backgroundThread->stop();
_backgroundThread->shutdown();
delete _backgroundThread;
_backgroundThread = 0;
if (_backgroundThread != 0) {
_backgroundThread->stop();
_backgroundThread->shutdown();
delete _backgroundThread;
_backgroundThread = 0;
}
cleanupAllQueues();
}
@ -100,12 +97,30 @@ ClusterComm* ClusterComm::instance () {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief only used to trigger creation
/// @brief initialise the cluster comm singleton object
////////////////////////////////////////////////////////////////////////////////
void ClusterComm::initialise () {
assert(_theinstance == 0);
_theinstance = new ClusterComm( ); // this now happens exactly once
_theinstance = new ClusterComm(); // this now happens exactly once
_theinstance->startBackgroundThread();
}
////////////////////////////////////////////////////////////////////////////////
/// @brief start the communication background thread
////////////////////////////////////////////////////////////////////////////////
void ClusterComm::startBackgroundThread () {
_backgroundThread = new ClusterCommThread();
if (0 == _backgroundThread) {
LOG_FATAL_AND_EXIT("unable to start ClusterComm background thread");
}
if (! _backgroundThread->init() || ! _backgroundThread->start()) {
LOG_FATAL_AND_EXIT("ClusterComm background thread does not work");
}
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -261,6 +261,12 @@ void ClusterCommRestCallback(string& coordinator, rest::HttpResponse* response);
_theinstance = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief start the communication background thread
////////////////////////////////////////////////////////////////////////////////
void startBackgroundThread ();
////////////////////////////////////////////////////////////////////////////////
/// @brief submit an HTTP request to a shard asynchronously.
////////////////////////////////////////////////////////////////////////////////

View File

@ -244,12 +244,19 @@ ClusterInfo* ClusterInfo::instance () {
// This does not have to be thread-safe, because we guarantee that
// this is called very early in the startup phase when there is still
// a single thread.
if (0 == _theinstance) {
_theinstance = new ClusterInfo(); // this now happens exactly once
}
assert(_theinstance != 0);
return _theinstance;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief initialise the cluster info singleton object
////////////////////////////////////////////////////////////////////////////////
void ClusterInfo::initialise () {
assert(_theinstance == 0);
_theinstance = new ClusterInfo(); // this now happens exactly once
}
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a cluster info object
////////////////////////////////////////////////////////////////////////////////
@ -2085,7 +2092,6 @@ int ClusterInfo::getResponsibleShard (CollectionID const& collectionID,
return error;
}
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"

View File

@ -720,6 +720,12 @@ namespace triagens {
static ClusterInfo* instance ();
////////////////////////////////////////////////////////////////////////////////
/// @brief initialise function to call once when still single-threaded
////////////////////////////////////////////////////////////////////////////////
static void initialise ();
////////////////////////////////////////////////////////////////////////////////
/// @brief cleanup function to call once when shutting down
////////////////////////////////////////////////////////////////////////////////