mirror of https://gitee.com/bigwinds/arangodb
fixed startup race condition
This commit is contained in:
parent
060fb00626
commit
2f6f59e228
|
@ -155,14 +155,12 @@ bool ApplicationCluster::prepare () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialise ClusterInfo library
|
||||||
|
ClusterInfo::initialise();
|
||||||
|
|
||||||
// initialise ClusterComm library
|
// initialise ClusterComm library
|
||||||
ClusterComm::initialise();
|
ClusterComm::initialise();
|
||||||
|
|
||||||
// initialise cluster info library
|
|
||||||
ClusterInfo::instance();
|
|
||||||
|
|
||||||
usleep(1000);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,14 +59,8 @@ void triagens::arango::ClusterCommRestCallback(string& coordinator,
|
||||||
/// @brief ClusterComm constructor
|
/// @brief ClusterComm constructor
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ClusterComm::ClusterComm () {
|
ClusterComm::ClusterComm () :
|
||||||
_backgroundThread = new ClusterCommThread();
|
_backgroundThread(0) {
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -74,10 +68,13 @@ ClusterComm::ClusterComm () {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ClusterComm::~ClusterComm () {
|
ClusterComm::~ClusterComm () {
|
||||||
_backgroundThread->stop();
|
if (_backgroundThread != 0) {
|
||||||
_backgroundThread->shutdown();
|
_backgroundThread->stop();
|
||||||
delete _backgroundThread;
|
_backgroundThread->shutdown();
|
||||||
_backgroundThread = 0;
|
delete _backgroundThread;
|
||||||
|
_backgroundThread = 0;
|
||||||
|
}
|
||||||
|
|
||||||
cleanupAllQueues();
|
cleanupAllQueues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,12 +97,30 @@ ClusterComm* ClusterComm::instance () {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief only used to trigger creation
|
/// @brief initialise the cluster comm singleton object
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ClusterComm::initialise () {
|
void ClusterComm::initialise () {
|
||||||
assert(_theinstance == 0);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -261,6 +261,12 @@ void ClusterCommRestCallback(string& coordinator, rest::HttpResponse* response);
|
||||||
_theinstance = 0;
|
_theinstance = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief start the communication background thread
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void startBackgroundThread ();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief submit an HTTP request to a shard asynchronously.
|
/// @brief submit an HTTP request to a shard asynchronously.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -244,12 +244,19 @@ ClusterInfo* ClusterInfo::instance () {
|
||||||
// This does not have to be thread-safe, because we guarantee that
|
// 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
|
// this is called very early in the startup phase when there is still
|
||||||
// a single thread.
|
// a single thread.
|
||||||
if (0 == _theinstance) {
|
assert(_theinstance != 0);
|
||||||
_theinstance = new ClusterInfo(); // this now happens exactly once
|
|
||||||
}
|
|
||||||
return _theinstance;
|
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
|
/// @brief creates a cluster info object
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -2085,7 +2092,6 @@ int ClusterInfo::getResponsibleShard (CollectionID const& collectionID,
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode: outline-minor
|
// mode: outline-minor
|
||||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||||
|
|
|
@ -720,6 +720,12 @@ namespace triagens {
|
||||||
|
|
||||||
static ClusterInfo* instance ();
|
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
|
/// @brief cleanup function to call once when shutting down
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue