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)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static uint64_t CurrentTick = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tick lock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static triagens::basics::SpinLock TickLock;
|
||||
static std::atomic<uint64_t> CurrentTick(0);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the server's global id
|
||||
|
@ -306,30 +300,6 @@ static int DetermineServerId (TRI_server_t* server, bool checkVersion) {
|
|||
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
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -2772,8 +2742,6 @@ void TRI_GetDatabaseDefaultsServer (TRI_server_t* server,
|
|||
TRI_voc_tick_t TRI_NewTickServer () {
|
||||
uint64_t tick = ServerIdentifier;
|
||||
|
||||
SPIN_LOCKER(TickLock);
|
||||
|
||||
tick |= (++CurrentTick) << 16;
|
||||
|
||||
return tick;
|
||||
|
@ -2784,16 +2752,15 @@ TRI_voc_tick_t TRI_NewTickServer () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_UpdateTickServer (TRI_voc_tick_t tick) {
|
||||
SPIN_LOCKER(TickLock);
|
||||
UpdateTick(tick);
|
||||
}
|
||||
TRI_voc_tick_t t = tick >> 16;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief updates the tick counter, without lock - only use at startup!!
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_FastUpdateTickServer (TRI_voc_tick_t tick) {
|
||||
UpdateTick(tick);
|
||||
auto expected = CurrentTick.load(std::memory_order_relaxed);
|
||||
|
||||
// only update global tick if less than the specified value...
|
||||
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 () {
|
||||
SPIN_LOCKER(TickLock);
|
||||
return GetTick();
|
||||
return (ServerIdentifier | (CurrentTick << 16));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -314,12 +314,6 @@ TRI_voc_tick_t TRI_NewTickServer (void);
|
|||
|
||||
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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -787,7 +787,11 @@ static int RenameCollection (TRI_vocbase_t* vocbase,
|
|||
static bool StartupTickIterator (TRI_df_marker_t const* marker,
|
||||
void* data,
|
||||
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;
|
||||
}
|
||||
|
@ -856,7 +860,7 @@ static int ScanPath (TRI_vocbase_t* vocbase,
|
|||
res = TRI_LoadCollectionInfo(file, &info, true);
|
||||
|
||||
if (res == TRI_ERROR_NO_ERROR) {
|
||||
TRI_FastUpdateTickServer(info._cid);
|
||||
TRI_UpdateTickServer(info._cid);
|
||||
}
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
|
@ -958,7 +962,10 @@ static int ScanPath (TRI_vocbase_t* vocbase,
|
|||
if (iterateMarkers) {
|
||||
// iterating markers may be time-consuming. we'll only do it if
|
||||
// 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);
|
||||
|
|
Loading…
Reference in New Issue