Skip to content

Commit 2eb062b

Browse files
committed
Bug#36218231 NdbApi logging cleanup
General cleanup - Use g_eventLogger for events that should be async / are potentially generated from threads delivering signals - Use fprintf(stderr) / Ndberr for 'pre-crash' states which should be flushed before process exit/abort Add a Timestamp and 'NDBAPI FATAL ERROR' to these occurrences. - Remove unnecessary logging - Remove non standard 'user help' logging - Add some more context info to async messages to understand e.g. - What the message is about - Which instance(s) it is referring to (connection id, event buffer) Not a complete cleanup, more can be done. Change-Id: I904435608f699401e7431bb5c68c0c5fb0bd8df1
1 parent cefcd8b commit 2eb062b

File tree

13 files changed

+307
-201
lines changed

13 files changed

+307
-201
lines changed

storage/ndb/include/logger/Logger.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ class Logger {
122122
*/
123123
static void format_timestamp(const time_t epoch, char *str, size_t len);
124124

125+
// Timestamp - handy class for getting a timestamp string
126+
class Timestamp {
127+
public:
128+
Timestamp();
129+
const char *c_str() const { return buff; }
130+
131+
private:
132+
static constexpr Uint32 TsLen = 64;
133+
char buff[TsLen];
134+
};
135+
125136
/** The log levels. NOTE: Could not use the name LogLevel since
126137
* it caused conflicts with another class.
127138
*/

storage/ndb/src/common/logger/Logger.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ void Logger::setRepeatFrequency(unsigned val) {
394394
m_internalLogListHandler->setRepeatFrequency(val);
395395
}
396396

397+
Logger::Timestamp::Timestamp() {
398+
Logger::format_timestamp(time(nullptr), buff, TsLen);
399+
}
400+
397401
void Logger::format_timestamp(const time_t epoch, char *str, size_t len) {
398402
assert(len > 0); // Assume buffer has size
399403

storage/ndb/src/ndbapi/ClusterMgr.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ ClusterMgr::ClusterMgr(TransporterFacade &_facade)
9999

100100
Uint32 ret = this->open(&theFacade, API_CLUSTERMGR);
101101
if (unlikely(ret == 0)) {
102-
g_eventLogger->info("Failed to register ClusterMgr! ret: %d", ret);
102+
fprintf(stderr,
103+
"%s NDBAPI FATAL ERROR : Failed to register "
104+
"ClusterMgr! ret: %d\n",
105+
Logger::Timestamp().c_str(), ret);
103106
abort();
104107
}
105108
DBUG_VOID_RETURN;
@@ -223,10 +226,11 @@ void ClusterMgr::startThread() {
223226
0, // default stack size
224227
"ndb_clustermgr", NDB_THREAD_PRIO_HIGH);
225228
if (theClusterMgrThread == nullptr) {
226-
g_eventLogger->info(
227-
"ClusterMgr::startThread:"
228-
" Failed to create thread for cluster management.");
229-
assert(theClusterMgrThread != nullptr);
229+
fprintf(stderr,
230+
"%s NDBAPI FATAL ERROR : ClusterMgr::startThread:"
231+
" Failed to create thread for cluster management.\n",
232+
Logger::Timestamp().c_str());
233+
abort();
230234
DBUG_VOID_RETURN;
231235
}
232236

@@ -904,8 +908,10 @@ void ClusterMgr::execAPI_REGREF(const Uint32 *theData) {
904908

905909
switch (ref->errorCode) {
906910
case ApiRegRef::WrongType:
907-
g_eventLogger->info("Node %d reports that this node should be a NDB node",
908-
nodeId);
911+
fprintf(stderr,
912+
"%s NDBAPI FATAL ERROR : Node %d reports that "
913+
"this node %d should be an NDB node\n",
914+
Logger::Timestamp().c_str(), nodeId, getOwnNodeId());
909915
abort();
910916
case ApiRegRef::UnsupportedVersion:
911917
default:
@@ -1462,9 +1468,11 @@ void ArbitMgr::doStart(const Uint32 *theData) {
14621468
0, // default stack size
14631469
"ndb_arbitmgr", NDB_THREAD_PRIO_HIGH);
14641470
if (theThread == nullptr) {
1465-
g_eventLogger->info(
1466-
"ArbitMgr::doStart: Failed to create thread for arbitration.");
1467-
assert(theThread != nullptr);
1471+
fprintf(stderr,
1472+
"%s NDBAPI FATAL ERROR : ArbitMgr::doStart: Failed to "
1473+
"create thread for arbitration.\n",
1474+
Logger::Timestamp().c_str());
1475+
abort();
14681476
}
14691477
NdbMutex_Unlock(theThreadMutex);
14701478
DBUG_VOID_RETURN;

storage/ndb/src/ndbapi/Ndb.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ void Ndb::closeTransaction(NdbTransaction *aConnection) {
967967
// application behaviour.
968968
//-----------------------------------------------------
969969
#ifdef VM_TRACE
970-
printf("NULL into closeTransaction\n");
970+
g_eventLogger->info("Ndb::closeTransaction passed nullptr");
971971
#endif
972972
DBUG_VOID_RETURN;
973973
} // if
@@ -1003,15 +1003,18 @@ void Ndb::closeTransaction(NdbTransaction *aConnection) {
10031003
* something else...
10041004
*/
10051005
#ifdef VM_TRACE
1006-
printf(
1007-
"Scan timeout:ed NdbTransaction-> "
1008-
"not returning it-> memory leak\n");
1006+
g_eventLogger->warning(
1007+
"Ndb::closeTransaction() scan time out, not "
1008+
"returning NdbTransaction -> memory leak");
10091009
#endif
10101010
DBUG_VOID_RETURN;
10111011
}
10121012

10131013
#ifdef VM_TRACE
1014-
printf("Non-existing transaction into closeTransaction\n");
1014+
fprintf(stderr,
1015+
"%s NDBAPI FATAL ERROR : Non-existing transaction %p "
1016+
"passed into closeTransaction on Ndb %p\n",
1017+
Logger::Timestamp().c_str(), aConnection, this);
10151018
abort();
10161019
#endif
10171020
DBUG_VOID_RETURN;
@@ -1032,9 +1035,9 @@ void Ndb::closeTransaction(NdbTransaction *aConnection) {
10321035
* to reuse. And TC crashes when the API tries to reuse it to
10331036
* something else...
10341037
*/
1035-
#ifdef VM_TRACE
1036-
printf("Con timeout:ed NdbTransaction-> not returning it-> memory leak\n");
1037-
#endif
1038+
g_eventLogger->warning(
1039+
"Ndb::closeTransaction() passed a timed out NdbTransaction, not "
1040+
"returning it -> resource leak");
10381041
DBUG_VOID_RETURN;
10391042
}
10401043

@@ -1861,9 +1864,6 @@ NdbEventOperation *Ndb::getEventOperation(NdbEventOperation *tOp) {
18611864

18621865
int Ndb::pollEvents2(int aMillisecondNumber, Uint64 *highestQueuedEpoch) {
18631866
if (unlikely(aMillisecondNumber < 0)) {
1864-
g_eventLogger->error(
1865-
"Ndb::pollEvents2: negative aMillisecondNumber %d 0x%x %s",
1866-
aMillisecondNumber, getReference(), getNdbObjectName());
18671867
return -1;
18681868
}
18691869

@@ -1893,19 +1893,21 @@ bool Ndb::isExpectingHigherQueuedEpochs() {
18931893
}
18941894

18951895
void Ndb::printOverflowErrorAndExit() {
1896-
g_eventLogger->error("Ndb Event Buffer : 0x%x %s", getReference(),
1897-
getNdbObjectName());
1898-
g_eventLogger->error("Ndb Event Buffer : Event buffer out of memory.");
1899-
g_eventLogger->error("Ndb Event Buffer : Fatal error.");
1896+
fprintf(stderr,
1897+
"%s NDBAPI FATAL ERROR : Ndb Event Buffer : 0x%x %s\n"
1898+
"Event buffer out of memory.\n",
1899+
Logger::Timestamp().c_str(), getReference(), getNdbObjectName());
19001900
Uint64 maxalloc = get_eventbuf_max_alloc();
19011901
if (maxalloc != 0) {
19021902
// limited memory is allocated for event buffer, give recommendation
1903-
g_eventLogger->error(
1904-
"Ndb Event Buffer : Change eventbuf_max_alloc (Current max_alloc is "
1905-
"%llu).",
1906-
maxalloc);
1907-
}
1908-
g_eventLogger->error("Ndb Event Buffer : Consider using the new API.");
1903+
fprintf(stderr,
1904+
"Consider changing eventbuf_max_alloc (Current max_alloc is "
1905+
"%llu).\n",
1906+
maxalloc);
1907+
}
1908+
fprintf(stderr,
1909+
"Out of Memory events can be handled non fatally "
1910+
"using nextEvent2().\n");
19091911
exit(-1);
19101912
}
19111913

@@ -1962,11 +1964,14 @@ NdbEventOperation *Ndb::nextEvent() {
19621964
}
19631965

19641966
if (unlikely(op->isEmptyEpoch())) {
1965-
g_eventLogger->error(
1966-
"Ndb::nextEvent: Found exceptional event type "
1967-
"TE_EMPTY when using old event API. "
1968-
"Turn off empty epoch queuing by "
1969-
"setEventBufferQueueEmptyEpoch(false).");
1967+
fprintf(stderr,
1968+
"%s NDBAPI FATAL ERROR : Ndb::nextEvent() : Found "
1969+
"exceptional event type TE_EMPTY when using old "
1970+
"event API nextEvent() call. "
1971+
"Turn off empty epoch queuing by "
1972+
"setEventBufferQueueEmptyEpoch(false) "
1973+
"or use new API nextEvent2().\n",
1974+
Logger::Timestamp().c_str());
19701975
exit(-1);
19711976
}
19721977
return op;

storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,9 @@ int NdbDictInterface::dictSignal(NdbApiSignal *sig, LinearSectionPtr ptr[3],
26162616
if (i > 0) {
26172617
Uint32 t = sleep + 10 * (rand() % mod);
26182618
#ifdef VM_TRACE
2619-
g_eventLogger->info("retry sleep %ums on error %u", t, m_error.code);
2619+
g_eventLogger->info(
2620+
"NdbDictionary::dictSignal() : retry sleep %ums on error %u", t,
2621+
m_error.code);
26202622
#endif
26212623
NdbSleep_MilliSleep(t);
26222624
}
@@ -5158,8 +5160,6 @@ int NdbDictionaryImpl::createEvent(NdbEventImpl &evnt) {
51585160
if (col_impl) {
51595161
evnt.m_facade->addColumn(*(col_impl->m_facade));
51605162
} else {
5161-
g_eventLogger->info("Attr id %u in table %s not found", evnt.m_attrIds[i],
5162-
evnt.getTableName());
51635163
m_error.code = 4713;
51645164
ERR_RETURN(getNdbError(), -1);
51655165
}
@@ -5361,7 +5361,6 @@ int NdbDictInterface::createEvent(NdbEventImpl &evnt, int getFlag) {
53615361
evnt.m_tableImpl->m_version != evntConf->getTableVersion() ||
53625362
// evnt.m_attrListBitmask != evntConf->getAttrListBitmask() ||
53635363
evnt.mi_type != evntConf->getEventType()) {
5364-
g_eventLogger->info("ERROR*************");
53655364
m_buffer.clear();
53665365
m_tableData.clear();
53675366
ERR_RETURN(getNdbError(), 1);
@@ -5911,9 +5910,6 @@ static int scanEventTable(Ndb *pNdb, const NdbDictionary::Table *pTab,
59115910

59125911
if (retryAttempt) {
59135912
if (retryAttempt >= retryMax) {
5914-
g_eventLogger->info(
5915-
"ERROR: has retried this operation %d times, failing!",
5916-
retryAttempt);
59175913
goto error;
59185914
}
59195915
if (pTrans) pNdb->closeTransaction(pTrans);

0 commit comments

Comments
 (0)