From a06e44956b65abd0f54f74d86705c0203e65b6dd Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Wed, 22 Oct 2014 10:18:26 +0200 Subject: [PATCH] catch 'too many statistics' overflow --- lib/Statistics/StatisticsAgent.h | 44 ++++++++++++++++---------------- lib/Statistics/statistics.cpp | 28 ++++++++++++-------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/lib/Statistics/StatisticsAgent.h b/lib/Statistics/StatisticsAgent.h index 852b59225f..f5ec095da8 100644 --- a/lib/Statistics/StatisticsAgent.h +++ b/lib/Statistics/StatisticsAgent.h @@ -64,7 +64,7 @@ namespace triagens { #ifdef TRI_ENABLE_FIGURES StatisticsAgent () - : _statistics(0) { + : _statistics(nullptr) { } #else @@ -81,7 +81,7 @@ namespace triagens { #ifdef TRI_ENABLE_FIGURES ~StatisticsAgent () { - if (_statistics != 0) { + if (_statistics != nullptr) { FUNC::release(_statistics); } } @@ -101,7 +101,7 @@ namespace triagens { STAT* acquire () { #ifdef TRI_ENABLE_FIGURES - if (_statistics != 0) { + if (_statistics != nullptr) { return _statistics; } @@ -119,7 +119,7 @@ namespace triagens { void release () { #ifdef TRI_ENABLE_FIGURES - if (_statistics != 0) { + if (_statistics != nullptr) { FUNC::release(_statistics); _statistics = 0; } @@ -186,7 +186,7 @@ namespace triagens { virtual void replace (STAT* statistics) { #ifdef TRI_ENABLE_FIGURES - if (_statistics != 0) { + if (_statistics != nullptr) { FUNC::release(_statistics); } @@ -236,7 +236,7 @@ namespace triagens { #define RequestStatisticsAgentSetRequestType(a,b) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_requestType = b; \ } \ } \ @@ -258,7 +258,7 @@ namespace triagens { #define RequestStatisticsAgentSetAsync(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_async = true; \ } \ } \ @@ -280,7 +280,7 @@ namespace triagens { #define RequestStatisticsAgentSetReadStart(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_readStart = TRI_StatisticsTime(); \ } \ } \ @@ -302,7 +302,7 @@ namespace triagens { #define RequestStatisticsAgentSetReadEnd(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_readEnd = TRI_StatisticsTime(); \ } \ } \ @@ -324,7 +324,7 @@ namespace triagens { #define RequestStatisticsAgentSetWriteStart(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_writeStart = TRI_StatisticsTime(); \ } \ } \ @@ -346,7 +346,7 @@ namespace triagens { #define RequestStatisticsAgentSetWriteEnd(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_writeEnd = TRI_StatisticsTime(); \ } \ } \ @@ -368,7 +368,7 @@ namespace triagens { #define RequestStatisticsAgentSetQueueStart(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_queueStart = TRI_StatisticsTime(); \ } \ } \ @@ -390,7 +390,7 @@ namespace triagens { #define RequestStatisticsAgentSetQueueEnd(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_queueEnd = TRI_StatisticsTime(); \ } \ } \ @@ -412,7 +412,7 @@ namespace triagens { #define RequestStatisticsAgentSetRequestStart(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_requestStart = TRI_StatisticsTime(); \ } \ } \ @@ -434,7 +434,7 @@ namespace triagens { #define RequestStatisticsAgentSetRequestEnd(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_requestEnd = TRI_StatisticsTime(); \ } \ } \ @@ -456,7 +456,7 @@ namespace triagens { #define RequestStatisticsAgentSetExecuteError(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_executeError = true; \ } \ } \ @@ -478,7 +478,7 @@ namespace triagens { #define RequestStatisticsAgentSetIgnore(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_ignore = true; \ } \ } \ @@ -500,7 +500,7 @@ namespace triagens { #define RequestStatisticsAgentAddReceivedBytes(a,b) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_receivedBytes += (b); \ } \ } \ @@ -522,7 +522,7 @@ namespace triagens { #define RequestStatisticsAgentAddSentBytes(a,b) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->RequestStatisticsAgent::_statistics != 0) { \ + if ((a)->RequestStatisticsAgent::_statistics != nullptr) { \ (a)->RequestStatisticsAgent::_statistics->_sentBytes += (b); \ } \ } \ @@ -573,7 +573,7 @@ namespace triagens { #define ConnectionStatisticsAgentSetHttp(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->ConnectionStatisticsAgent::_statistics != 0) { \ + if ((a)->ConnectionStatisticsAgent::_statistics != nullptr) { \ (a)->ConnectionStatisticsAgent::_statistics->_http = true; \ } \ } \ @@ -595,7 +595,7 @@ namespace triagens { #define ConnectionStatisticsAgentSetStart(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->ConnectionStatisticsAgent::_statistics != 0) { \ + if ((a)->ConnectionStatisticsAgent::_statistics != nullptr) { \ (a)->ConnectionStatisticsAgent::_statistics->_connStart = TRI_StatisticsTime(); \ } \ } \ @@ -617,7 +617,7 @@ namespace triagens { #define ConnectionStatisticsAgentSetEnd(a) \ do { \ if (TRI_ENABLE_STATISTICS) { \ - if ((a)->ConnectionStatisticsAgent::_statistics != 0) { \ + if ((a)->ConnectionStatisticsAgent::_statistics != nullptr) { \ (a)->ConnectionStatisticsAgent::_statistics->_connEnd = TRI_StatisticsTime(); \ } \ } \ diff --git a/lib/Statistics/statistics.cpp b/lib/Statistics/statistics.cpp index 4ae0581cd0..18b01dabc4 100644 --- a/lib/Statistics/statistics.cpp +++ b/lib/Statistics/statistics.cpp @@ -78,11 +78,11 @@ static TRI_statistics_list_t RequestFreeList; //////////////////////////////////////////////////////////////////////////////// TRI_request_statistics_t* TRI_AcquireRequestStatistics () { - TRI_request_statistics_t* statistics = NULL; + TRI_request_statistics_t* statistics = nullptr; STATISTICS_LOCK(&RequestListLock); - if (RequestFreeList._first != NULL) { + if (RequestFreeList._first != nullptr) { statistics = (TRI_request_statistics_t*) RequestFreeList._first; RequestFreeList._first = RequestFreeList._first->_next; } @@ -99,6 +99,10 @@ TRI_request_statistics_t* TRI_AcquireRequestStatistics () { void TRI_ReleaseRequestStatistics (TRI_request_statistics_t* statistics) { STATISTICS_LOCK(&RequestListLock); + if (statistics == nullptr) { + return; + } + if (! statistics->_ignore) { TRI_TotalRequestsStatistics.incCounter(); @@ -138,7 +142,7 @@ void TRI_ReleaseRequestStatistics (TRI_request_statistics_t* statistics) { memset(statistics, 0, sizeof(TRI_request_statistics_t)); statistics->_requestType = triagens::rest::HttpRequest::HTTP_REQUEST_ILLEGAL; - if (RequestFreeList._first == NULL) { + if (RequestFreeList._first == nullptr) { RequestFreeList._first = (TRI_statistics_entry_t*) statistics; RequestFreeList._last = (TRI_statistics_entry_t*) statistics; } @@ -203,7 +207,7 @@ TRI_connection_statistics_t* TRI_AcquireConnectionStatistics () { STATISTICS_LOCK(&ConnectionListLock); - if (ConnectionFreeList._first != NULL) { + if (ConnectionFreeList._first != nullptr) { statistics = (TRI_connection_statistics_t*) ConnectionFreeList._first; ConnectionFreeList._first = ConnectionFreeList._first->_next; } @@ -220,6 +224,10 @@ TRI_connection_statistics_t* TRI_AcquireConnectionStatistics () { void TRI_ReleaseConnectionStatistics (TRI_connection_statistics_t* statistics) { STATISTICS_LOCK(&ConnectionListLock); + if (statistics == nullptr) { + return; + } + if (statistics->_http) { if (statistics->_connStart != 0) { if (statistics->_connEnd == 0) { @@ -237,7 +245,7 @@ void TRI_ReleaseConnectionStatistics (TRI_connection_statistics_t* statistics) { // clear statistics and put back an the free list memset(statistics, 0, sizeof(TRI_connection_statistics_t)); - if (ConnectionFreeList._first == NULL) { + if (ConnectionFreeList._first == nullptr) { ConnectionFreeList._first = (TRI_statistics_entry_t*) statistics; ConnectionFreeList._last = (TRI_statistics_entry_t*) statistics; } @@ -319,13 +327,13 @@ static void FillStatisticsList (TRI_statistics_list_t* list, size_t element, siz static void DestroyStatisticsList (TRI_statistics_list_t* list) { TRI_statistics_entry_t* entry = list->_first; - while (entry != NULL) { + while (entry != nullptr) { TRI_statistics_entry_t* next = entry->_next; TRI_Free(TRI_CORE_MEM_ZONE, entry); entry = next; } - list->_first = list->_last = NULL; + list->_first = list->_last = nullptr; } //////////////////////////////////////////////////////////////////////////////// @@ -343,7 +351,7 @@ static uint64_t GetPhysicalMemory () { mib[0] = CTL_HW; mib[1] = HW_MEMSIZE; length = sizeof(int64_t); - sysctl(mib, 2, &physicalMemory, &length, NULL, 0); + sysctl(mib, 2, &physicalMemory, &length, nullptr, 0); return (uint64_t) physicalMemory; } @@ -574,7 +582,7 @@ void TRI_InitialiseStatistics () { // generate the request statistics queue // ............................................................................. - RequestFreeList._first = RequestFreeList._last = NULL; + RequestFreeList._first = RequestFreeList._last = nullptr; FillStatisticsList(&RequestFreeList, sizeof(TRI_request_statistics_t), QUEUE_SIZE); @@ -584,7 +592,7 @@ void TRI_InitialiseStatistics () { // generate the connection statistics queue // ............................................................................. - ConnectionFreeList._first = ConnectionFreeList._last = NULL; + ConnectionFreeList._first = ConnectionFreeList._last = nullptr; FillStatisticsList(&ConnectionFreeList, sizeof(TRI_connection_statistics_t), QUEUE_SIZE);