mirror of https://gitee.com/bigwinds/arangodb
removed SpinLock around CurrentTick
This commit is contained in:
parent
97094b8f74
commit
ecf9402b71
|
@ -117,13 +117,7 @@ static uint16_t ServerIdentifier = 0;
|
||||||
/// @brief current tick identifier (48 bit)
|
/// @brief current tick identifier (48 bit)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static uint64_t CurrentTick = 0;
|
static std::atomic<uint64_t> CurrentTick(0);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief tick lock
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static triagens::basics::SpinLock TickLock;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief the server's global id
|
/// @brief the server's global id
|
||||||
|
@ -306,30 +300,6 @@ static int DetermineServerId (TRI_server_t* server, bool checkVersion) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// --SECTION-- tick functions
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief returns the current tick value, without using a lock
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static inline TRI_voc_tick_t GetTick (void) {
|
|
||||||
return (ServerIdentifier | (CurrentTick << 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief updates the tick counter, without using a lock
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static inline void UpdateTick (TRI_voc_tick_t tick) {
|
|
||||||
TRI_voc_tick_t s = tick >> 16;
|
|
||||||
|
|
||||||
if (CurrentTick < s) {
|
|
||||||
CurrentTick = s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- database functions
|
// --SECTION-- database functions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -2772,8 +2742,6 @@ void TRI_GetDatabaseDefaultsServer (TRI_server_t* server,
|
||||||
TRI_voc_tick_t TRI_NewTickServer () {
|
TRI_voc_tick_t TRI_NewTickServer () {
|
||||||
uint64_t tick = ServerIdentifier;
|
uint64_t tick = ServerIdentifier;
|
||||||
|
|
||||||
SPIN_LOCKER(TickLock);
|
|
||||||
|
|
||||||
tick |= (++CurrentTick) << 16;
|
tick |= (++CurrentTick) << 16;
|
||||||
|
|
||||||
return tick;
|
return tick;
|
||||||
|
@ -2784,16 +2752,15 @@ TRI_voc_tick_t TRI_NewTickServer () {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TRI_UpdateTickServer (TRI_voc_tick_t tick) {
|
void TRI_UpdateTickServer (TRI_voc_tick_t tick) {
|
||||||
SPIN_LOCKER(TickLock);
|
TRI_voc_tick_t t = tick >> 16;
|
||||||
UpdateTick(tick);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
auto expected = CurrentTick.load(std::memory_order_relaxed);
|
||||||
/// @brief updates the tick counter, without lock - only use at startup!!
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void TRI_FastUpdateTickServer (TRI_voc_tick_t tick) {
|
// only update global tick if less than the specified value...
|
||||||
UpdateTick(tick);
|
while (expected < t &&
|
||||||
|
! CurrentTick.compare_exchange_weak(expected, t, std::memory_order_release, std::memory_order_relaxed)) {
|
||||||
|
expected = CurrentTick.load(std::memory_order_relaxed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -2801,8 +2768,7 @@ void TRI_FastUpdateTickServer (TRI_voc_tick_t tick) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TRI_voc_tick_t TRI_CurrentTickServer () {
|
TRI_voc_tick_t TRI_CurrentTickServer () {
|
||||||
SPIN_LOCKER(TickLock);
|
return (ServerIdentifier | (CurrentTick << 16));
|
||||||
return GetTick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -314,12 +314,6 @@ TRI_voc_tick_t TRI_NewTickServer (void);
|
||||||
|
|
||||||
void TRI_UpdateTickServer (TRI_voc_tick_t);
|
void TRI_UpdateTickServer (TRI_voc_tick_t);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief updates the tick counter, without lock - only use at startup!!
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void TRI_FastUpdateTickServer (TRI_voc_tick_t);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief returns the current tick counter
|
/// @brief returns the current tick counter
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -787,7 +787,11 @@ static int RenameCollection (TRI_vocbase_t* vocbase,
|
||||||
static bool StartupTickIterator (TRI_df_marker_t const* marker,
|
static bool StartupTickIterator (TRI_df_marker_t const* marker,
|
||||||
void* data,
|
void* data,
|
||||||
TRI_datafile_t* datafile) {
|
TRI_datafile_t* datafile) {
|
||||||
TRI_FastUpdateTickServer(marker->_tick);
|
auto tick = static_cast<TRI_voc_tick_t*>(data);
|
||||||
|
|
||||||
|
if (marker->_tick > *tick) {
|
||||||
|
*tick = marker->_tick;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -856,7 +860,7 @@ static int ScanPath (TRI_vocbase_t* vocbase,
|
||||||
res = TRI_LoadCollectionInfo(file, &info, true);
|
res = TRI_LoadCollectionInfo(file, &info, true);
|
||||||
|
|
||||||
if (res == TRI_ERROR_NO_ERROR) {
|
if (res == TRI_ERROR_NO_ERROR) {
|
||||||
TRI_FastUpdateTickServer(info._cid);
|
TRI_UpdateTickServer(info._cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
|
@ -958,7 +962,10 @@ static int ScanPath (TRI_vocbase_t* vocbase,
|
||||||
if (iterateMarkers) {
|
if (iterateMarkers) {
|
||||||
// iterating markers may be time-consuming. we'll only do it if
|
// iterating markers may be time-consuming. we'll only do it if
|
||||||
// we have to
|
// we have to
|
||||||
TRI_IterateTicksCollection(file, StartupTickIterator, nullptr);
|
TRI_voc_tick_t tick;
|
||||||
|
TRI_IterateTicksCollection(file, StartupTickIterator, &tick);
|
||||||
|
|
||||||
|
TRI_UpdateTickServer(tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("added document collection from '%s'", file);
|
LOG_DEBUG("added document collection from '%s'", file);
|
||||||
|
|
Loading…
Reference in New Issue