1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

WL#2299, structured log events

This commit is contained in:
tomas@poseidon.ndb.mysql.com
2005-01-19 08:14:52 +01:00
parent 84296d55f0
commit 0a857aca57
16 changed files with 1971 additions and 1400 deletions

View File

@ -688,7 +688,8 @@ INCLUDE_FILE_PATTERNS =
# or name=definition (no spaces). If the definition and the = are
# omitted =1 is assumed.
PREDEFINED = DOXYGEN_SHOULD_SKIP_DEPRECATED \
PREDEFINED = DOXYGEN_FIX \
DOXYGEN_SHOULD_SKIP_DEPRECATED \
DOXYGEN_SHOULD_SKIP_INTERNAL \
protected=private

View File

@ -0,0 +1,104 @@
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <mysql.h>
#include <ndbapi/NdbApi.hpp>
#include <mgmapi.h>
#include <stdio.h>
/*
* export LD_LIBRARY_PATH=../../../libmysql_r/.libs:../../../ndb/src/.libs
*/
#define MGMERROR(h) \
{ \
fprintf(stderr, "code: %d msg: %s\n", \
ndb_mgm_get_latest_error(h), \
ndb_mgm_get_latest_error_msg(h)); \
exit(-1); \
}
#define LOGEVENTERROR(h) \
{ \
fprintf(stderr, "code: %d msg: %s\n", \
ndb_logevent_get_latest_error(h), \
ndb_logevent_get_latest_error_msg(h)); \
exit(-1); \
}
int main()
{
NdbMgmHandle h;
NdbLogEventHandle l;
int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 };
struct ndb_logevent event;
ndb_init();
h= ndb_mgm_create_handle();
if ( h == 0)
{
printf("Unable to create handle\n");
exit(-1);
}
if (ndb_mgm_connect(h,0,0,0)) MGMERROR(h);
l= ndb_mgm_create_logevent_handle(h, filter);
if ( l == 0 ) MGMERROR(h);
while (1)
{
int timeout= 5000;
int r= ndb_logevent_get_next(l,&event,timeout);
if (r == 0)
printf("No event within %d milliseconds\n", timeout);
else if (r < 0)
LOGEVENTERROR(l)
else
{
printf("Event %d from node ID %d\n",
event.type,
event.source_nodeid);
printf("Category %d, severity %d, level %d\n",
event.category,
event.severity,
event.level);
switch (event.type) {
case NDB_LE_BackupStarted:
printf("BackupStartded\n");
printf("Starting node ID: %d\n", event.BackupStarted.starting_node);
printf("Backup ID: %d\n", event.BackupStarted.backup_id);
break;
case NDB_LE_BackupCompleted:
printf("BackupCompleted\n");
printf("Backup ID: %d\n", event.BackupStarted.backup_id);
break;
case NDB_LE_BackupAborted:
break;
case NDB_LE_BackupFailedToStart:
break;
default:
printf("Unexpected event\n");
break;
}
}
}
ndb_mgm_destroy_logevent_handle(&l);
ndb_mgm_destroy_handle(&h);
ndb_end(0);
return 0;
}

View File

@ -17,12 +17,12 @@
#ifndef EVENTLOGGER_H
#define EVENTLOGGER_H
#include <Logger.hpp>
#include <FileLogHandler.hpp>
#include <GrepError.hpp>
#include <kernel_types.h>
#include <logger/Logger.hpp>
#include <logger/FileLogHandler.hpp>
#include "GrepError.hpp"
#include <kernel/kernel_types.h>
#include <kernel/LogLevel.hpp>
#include <signaldata/EventReport.hpp>
#include <kernel/signaldata/EventReport.hpp>
class EventLoggerBase {
public:
@ -39,11 +39,14 @@ public:
* threshold - is in range [0-15]
* severity - DEBUG to ALERT (Type of log message)
*/
typedef void (* EventTextFunction)(char *,size_t,const Uint32*);
struct EventRepLogLevelMatrix {
Ndb_logevent_type eventType;
LogLevel::EventCategory eventCategory;
Uint32 threshold;
Logger::LoggerLevel severity;
Ndb_logevent_type eventType;
LogLevel::EventCategory eventCategory;
Uint32 threshold;
Logger::LoggerLevel severity;
EventTextFunction textF;
};
static const EventRepLogLevelMatrix matrix[];
@ -51,7 +54,8 @@ public:
static int event_lookup(int eventType,
LogLevel::EventCategory &cat,
Uint32 &threshold,
Logger::LoggerLevel &severity);
Logger::LoggerLevel &severity,
EventTextFunction &textF);
};
/**
@ -130,17 +134,18 @@ public:
* @param nodeId the node id of event origin.
*/
virtual void log(int, const Uint32*, NodeId = 0,const class LogLevel * = 0);
/**
* Returns the event text for the specified event report type.
*
* @param type the event type.
* @param textF print function for the event
* @param theData the event data.
* @param nodeId a node id.
* @return the event report text.
*/
static const char* getText(char * dst, size_t dst_len,
int type,
EventTextFunction textF,
const Uint32* theData, NodeId nodeId = 0);
/**

View File

@ -147,7 +147,7 @@ LogLevel::set_max(const LogLevel & org){
return * this;
}
#include <signaldata/EventSubscribeReq.hpp>
#include "signaldata/EventSubscribeReq.hpp"
inline
LogLevel&

View File

@ -18,8 +18,8 @@
#define SIGNAL_DATA_H
#include <ndb_global.h>
#include <ndb_limits.h>
#include <kernel_types.h>
#include <kernel/ndb_limits.h>
#include <kernel/kernel_types.h>
#include <BaseString.hpp>
#define ASSERT_BOOL(flag, message) assert(flag<=1)

View File

@ -86,6 +86,53 @@
* int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 };
* int fd = ndb_mgm_listen_event(handle, filter);
* @endcode
*
*
* @section secSLogEvents Structured Log Events
*
* The following steps are involved:
* - Create a NdbEventLogHandle using ndb_mgm_create_logevent_handle()
* - Wait and store log events using ndb_logevent_get_next()
* - The log event data is available in the struct ndb_logevent. The
* data which is specific to a particular event is stored in a union
* between structs so use ndb_logevent::type to decide which struct
* is valid.
*
* Sample code for listening to Backup related events. The availaable log
* events are listed in @ref ndb_logevent.h
*
* @code
* int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 };
* NdbEventLogHandle le_handle= ndb_mgm_create_logevent_handle(handle, filter);
* struct ndb_logevent le;
* int r= ndb_logevent_get_next(le_handle,&le,0);
* if (r < 0) error
* else if (r == 0) no event
*
* switch (le.type)
* {
* case NDB_LE_BackupStarted:
* ... le.BackupStarted.starting_node;
* ... le.BackupStarted.backup_id;
* break;
* case NDB_LE_BackupFailedToStart:
* ... le.BackupFailedToStart.error;
* break;
* case NDB_LE_BackupCompleted:
* ... le.BackupCompleted.stop_gci;
* break;
* case NDB_LE_BackupAborted:
* ... le.BackupStarted.backup_id;
* break;
* default:
* break;
* }
* @endcode
*/
/*
* @page ndb_logevent.h ndb_logevent.h
* @include ndb_logevent.h
*/
/** @addtogroup MGM_C_API
@ -93,6 +140,7 @@
*/
#include <ndb_types.h>
#include "ndb_logevent.h"
#include "mgmapi_config_parameters.h"
#ifdef __cplusplus
@ -348,97 +396,6 @@ extern "C" {
};
#endif
/**
* Log event severities (used to filter the cluster log,
* ndb_mgm_set_clusterlog_severity_filter(), and filter listening to events
* ndb_mgm_listen_event())
*/
enum ndb_mgm_event_severity {
NDB_MGM_ILLEGAL_EVENT_SEVERITY = -1,
/* Must be a nonnegative integer (used for array indexing) */
/** Cluster log on */
NDB_MGM_EVENT_SEVERITY_ON = 0,
/** Used in NDB Cluster developement */
NDB_MGM_EVENT_SEVERITY_DEBUG = 1,
/** Informational messages*/
NDB_MGM_EVENT_SEVERITY_INFO = 2,
/** Conditions that are not error condition, but might require handling.
*/
NDB_MGM_EVENT_SEVERITY_WARNING = 3,
/** Conditions that, while not fatal, should be corrected. */
NDB_MGM_EVENT_SEVERITY_ERROR = 4,
/** Critical conditions, like device errors or out of resources */
NDB_MGM_EVENT_SEVERITY_CRITICAL = 5,
/** A condition that should be corrected immediately,
* such as a corrupted system
*/
NDB_MGM_EVENT_SEVERITY_ALERT = 6,
/* must be next number, works as bound in loop */
/** All severities */
NDB_MGM_EVENT_SEVERITY_ALL = 7
};
/**
* Log event categories, used to set filter level on the log events using
* ndb_mgm_set_clusterlog_loglevel() and ndb_mgm_listen_event()
*/
enum ndb_mgm_event_category {
/**
* Invalid log event category
*/
NDB_MGM_ILLEGAL_EVENT_CATEGORY = -1,
/**
* Log events during all kinds of startups
*/
NDB_MGM_EVENT_CATEGORY_STARTUP = CFG_LOGLEVEL_STARTUP,
/**
* Log events during shutdown
*/
NDB_MGM_EVENT_CATEGORY_SHUTDOWN = CFG_LOGLEVEL_SHUTDOWN,
/**
* Statistics log events
*/
NDB_MGM_EVENT_CATEGORY_STATISTIC = CFG_LOGLEVEL_STATISTICS,
/**
* Log events related to checkpoints
*/
NDB_MGM_EVENT_CATEGORY_CHECKPOINT = CFG_LOGLEVEL_CHECKPOINT,
/**
* Log events during node restart
*/
NDB_MGM_EVENT_CATEGORY_NODE_RESTART = CFG_LOGLEVEL_NODERESTART,
/**
* Log events related to connections between cluster nodes
*/
NDB_MGM_EVENT_CATEGORY_CONNECTION = CFG_LOGLEVEL_CONNECTION,
/**
* Backup related log events
*/
NDB_MGM_EVENT_CATEGORY_BACKUP = CFG_LOGLEVEL_BACKUP,
/**
* Congestion related log events
*/
NDB_MGM_EVENT_CATEGORY_CONGESTION = CFG_LOGLEVEL_CONGESTION,
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/**
* Loglevel debug
*/
NDB_MGM_EVENT_CATEGORY_DEBUG = CFG_LOGLEVEL_DEBUG,
#endif
/**
* Uncategorized log events (severity info)
*/
NDB_MGM_EVENT_CATEGORY_INFO = CFG_LOGLEVEL_INFO,
/**
* Uncategorized log events (severity warning or higher)
*/
NDB_MGM_EVENT_CATEGORY_ERROR = CFG_LOGLEVEL_ERROR,
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
NDB_MGM_MIN_EVENT_CATEGORY = CFG_MIN_LOGLEVEL,
NDB_MGM_MAX_EVENT_CATEGORY = CFG_MAX_LOGLEVEL
#endif
};
/***************************************************************************/
/**
* @name Functions: Error Handling
@ -871,6 +828,64 @@ extern "C" {
struct ndb_mgm_reply* reply);
#endif
/**
* The NdbLogEventHandle
*/
typedef struct ndb_logevent_handle * NdbLogEventHandle;
/**
* Listen to log events.
*
* @param handle NDB management handle.
* @param filter pairs of { level, ndb_mgm_event_category } that will be
* pushed to fd, level=0 ends list.
*
* @return NdbLogEventHandle
*/
NdbLogEventHandle ndb_mgm_create_logevent_handle(NdbMgmHandle,
const int filter[]);
void ndb_mgm_destroy_logevent_handle(NdbLogEventHandle*);
/**
* Retrieve filedescriptor from NdbLogEventHandle. May be used in
* e.g. an application select() statement.
*
* @note Do not attemt to read from it, it will corrupt the parsing.
*
* @return filedescriptor, -1 on failure.
*/
int ndb_logevent_get_fd(const NdbLogEventHandle);
/**
* Attempt to retrieve next log event and will fill in the supplied
* struct dst
*
* @param dst Pointer to struct to fill in event information
* @param timeout_in_milliseconds Timeout for waiting for event
*
* @return >0 if event exists, 0 no event (timed out), or -1 on error.
*
* @note Return value <=0 will leave dst untouched
*/
int ndb_logevent_get_next(const NdbLogEventHandle,
struct ndb_logevent *dst,
unsigned timeout_in_milliseconds);
/**
* Retrieve laterst error code
*
* @return error code
*/
int ndb_logevent_get_latest_error(const NdbLogEventHandle);
/**
* Retrieve laterst error message
*
* @return error message
*/
const char *ndb_logevent_get_latest_error_msg(const NdbLogEventHandle);
/** @} *********************************************************************/
/**
* @name Functions: Backup

View File

@ -17,90 +17,542 @@
#ifndef NDB_LOGEVENT_H
#define NDB_LOGEVENT_H
/** @addtogroup MGM_C_API
* @{
*/
#include "mgmapi_config_parameters.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Available log events grouped by @ref ndb_mgm_event_category
*/
enum Ndb_logevent_type {
/* CONNECTION */
NDB_LE_ILLEGAL_TYPE = -1,
/** NDB_MGM_EVENT_CATEGORY_CONNECTION */
NDB_LE_Connected = 0,
/** NDB_MGM_EVENT_CATEGORY_CONNECTION */
NDB_LE_Disconnected = 1,
/** NDB_MGM_EVENT_CATEGORY_CONNECTION */
NDB_LE_CommunicationClosed = 2,
/** NDB_MGM_EVENT_CATEGORY_CONNECTION */
NDB_LE_CommunicationOpened = 3,
/** NDB_MGM_EVENT_CATEGORY_CONNECTION */
NDB_LE_ConnectedApiVersion = 51,
/* CHECKPOINT */
/** NDB_MGM_EVENT_CATEGORY_CHECKPOINT */
NDB_LE_GlobalCheckpointStarted = 4,
/** NDB_MGM_EVENT_CATEGORY_CHECKPOINT */
NDB_LE_GlobalCheckpointCompleted = 5,
/** NDB_MGM_EVENT_CATEGORY_CHECKPOINT */
NDB_LE_LocalCheckpointStarted = 6,
/** NDB_MGM_EVENT_CATEGORY_CHECKPOINT */
NDB_LE_LocalCheckpointCompleted = 7,
/** NDB_MGM_EVENT_CATEGORY_CHECKPOINT */
NDB_LE_LCPStoppedInCalcKeepGci = 8,
/** NDB_MGM_EVENT_CATEGORY_CHECKPOINT */
NDB_LE_LCPFragmentCompleted = 9,
/* STARTUP */
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_NDBStartStarted = 10,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_NDBStartCompleted = 11,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_STTORRYRecieved = 12,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_StartPhaseCompleted = 13,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_CM_REGCONF = 14,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_CM_REGREF = 15,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_FIND_NEIGHBOURS = 16,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_NDBStopStarted = 17,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_NDBStopAborted = 18,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_StartREDOLog = 19,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_StartLog = 20,
/** NDB_MGM_EVENT_CATEGORY_STARTUP */
NDB_LE_UNDORecordsExecuted = 21,
/* NODERESTART */
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_NR_CopyDict = 22,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_NR_CopyDistr = 23,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_NR_CopyFragsStarted = 24,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_NR_CopyFragDone = 25,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_NR_CopyFragsCompleted = 26,
/* NODEFAIL */
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_NodeFailCompleted = 27,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_NODE_FAILREP = 28,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_ArbitState = 29,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_ArbitResult = 30,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_GCP_TakeoverStarted = 31,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_GCP_TakeoverCompleted = 32,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_LCP_TakeoverStarted = 33,
/** NDB_MGM_EVENT_CATEGORY_NODE_RESTART */
NDB_LE_LCP_TakeoverCompleted = 34,
/* STATISTIC */
/** NDB_MGM_EVENT_CATEGORY_STATISTIC */
NDB_LE_TransReportCounters = 35,
/** NDB_MGM_EVENT_CATEGORY_STATISTIC */
NDB_LE_OperationReportCounters = 36,
/** NDB_MGM_EVENT_CATEGORY_STATISTIC */
NDB_LE_TableCreated = 37,
/** NDB_MGM_EVENT_CATEGORY_STATISTIC */
NDB_LE_UndoLogBlocked = 38,
/** NDB_MGM_EVENT_CATEGORY_STATISTIC */
NDB_LE_JobStatistic = 39,
/** NDB_MGM_EVENT_CATEGORY_STATISTIC */
NDB_LE_SendBytesStatistic = 40,
/** NDB_MGM_EVENT_CATEGORY_STATISTIC */
NDB_LE_ReceiveBytesStatistic = 41,
/** NDB_MGM_EVENT_CATEGORY_STATISTIC */
NDB_LE_MemoryUsage = 50,
/* ERROR */
/** NDB_MGM_EVENT_CATEGORY_ERROR */
NDB_LE_TransporterError = 42,
/** NDB_MGM_EVENT_CATEGORY_ERROR */
NDB_LE_TransporterWarning = 43,
/** NDB_MGM_EVENT_CATEGORY_ERROR */
NDB_LE_MissedHeartbeat = 44,
/** NDB_MGM_EVENT_CATEGORY_ERROR */
NDB_LE_DeadDueToHeartbeat = 45,
/** NDB_MGM_EVENT_CATEGORY_ERROR */
NDB_LE_WarningEvent = 46,
/* INFO */
/** NDB_MGM_EVENT_CATEGORY_INFO */
NDB_LE_SentHeartbeat = 47,
/** NDB_MGM_EVENT_CATEGORY_INFO */
NDB_LE_CreateLogBytes = 48,
/** NDB_MGM_EVENT_CATEGORY_INFO */
NDB_LE_InfoEvent = 49,
/* GREP */
NDB_LE_GrepSubscriptionInfo = 52,
NDB_LE_GrepSubscriptionAlert = 53,
/* BACKUP */
/** NDB_MGM_EVENT_CATEGORY_BACKUP */
NDB_LE_BackupStarted = 54,
/** NDB_MGM_EVENT_CATEGORY_BACKUP */
NDB_LE_BackupFailedToStart = 55,
/** NDB_MGM_EVENT_CATEGORY_BACKUP */
NDB_LE_BackupCompleted = 56,
/** NDB_MGM_EVENT_CATEGORY_BACKUP */
NDB_LE_BackupAborted = 57
};
/**
* Log event severities (used to filter the cluster log,
* ndb_mgm_set_clusterlog_severity_filter(), and filter listening to events
* ndb_mgm_listen_event())
*/
enum ndb_mgm_event_severity {
NDB_MGM_ILLEGAL_EVENT_SEVERITY = -1,
/* Must be a nonnegative integer (used for array indexing) */
/** Cluster log on */
NDB_MGM_EVENT_SEVERITY_ON = 0,
/** Used in NDB Cluster developement */
NDB_MGM_EVENT_SEVERITY_DEBUG = 1,
/** Informational messages*/
NDB_MGM_EVENT_SEVERITY_INFO = 2,
/** Conditions that are not error condition, but might require handling.
*/
NDB_MGM_EVENT_SEVERITY_WARNING = 3,
/** Conditions that, while not fatal, should be corrected. */
NDB_MGM_EVENT_SEVERITY_ERROR = 4,
/** Critical conditions, like device errors or out of resources */
NDB_MGM_EVENT_SEVERITY_CRITICAL = 5,
/** A condition that should be corrected immediately,
* such as a corrupted system
*/
NDB_MGM_EVENT_SEVERITY_ALERT = 6,
/* must be next number, works as bound in loop */
/** All severities */
NDB_MGM_EVENT_SEVERITY_ALL = 7
};
/**
* Log event categories, used to set filter level on the log events using
* ndb_mgm_set_clusterlog_loglevel() and ndb_mgm_listen_event()
*/
enum ndb_mgm_event_category {
/**
* Invalid log event category
*/
NDB_MGM_ILLEGAL_EVENT_CATEGORY = -1,
/**
* Log events during all kinds of startups
*/
NDB_MGM_EVENT_CATEGORY_STARTUP = CFG_LOGLEVEL_STARTUP,
/**
* Log events during shutdown
*/
NDB_MGM_EVENT_CATEGORY_SHUTDOWN = CFG_LOGLEVEL_SHUTDOWN,
/**
* Statistics log events
*/
NDB_MGM_EVENT_CATEGORY_STATISTIC = CFG_LOGLEVEL_STATISTICS,
/**
* Log events related to checkpoints
*/
NDB_MGM_EVENT_CATEGORY_CHECKPOINT = CFG_LOGLEVEL_CHECKPOINT,
/**
* Log events during node restart
*/
NDB_MGM_EVENT_CATEGORY_NODE_RESTART = CFG_LOGLEVEL_NODERESTART,
/**
* Log events related to connections between cluster nodes
*/
NDB_MGM_EVENT_CATEGORY_CONNECTION = CFG_LOGLEVEL_CONNECTION,
/**
* Backup related log events
*/
NDB_MGM_EVENT_CATEGORY_BACKUP = CFG_LOGLEVEL_BACKUP,
/**
* Congestion related log events
*/
NDB_MGM_EVENT_CATEGORY_CONGESTION = CFG_LOGLEVEL_CONGESTION,
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/**
* Loglevel debug
*/
NDB_MGM_EVENT_CATEGORY_DEBUG = CFG_LOGLEVEL_DEBUG,
#endif
/**
* Uncategorized log events (severity info)
*/
NDB_MGM_EVENT_CATEGORY_INFO = CFG_LOGLEVEL_INFO,
/**
* Uncategorized log events (severity warning or higher)
*/
NDB_MGM_EVENT_CATEGORY_ERROR = CFG_LOGLEVEL_ERROR,
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
NDB_MGM_MIN_EVENT_CATEGORY = CFG_MIN_LOGLEVEL,
NDB_MGM_MAX_EVENT_CATEGORY = CFG_MAX_LOGLEVEL
#endif
};
/**
* Structure to store and retrieve log event information.
* @see @ref secSLogEvents
*/
struct ndb_logevent {
/** NdbLogEventHandle (to be used for comparing only)
* set in ndb_logevent_get_next()
*/
void *handle;
/** Which event */
enum Ndb_logevent_type type;
/** Time when log event was registred at the management server */
unsigned time;
/** Category of log event */
enum ndb_mgm_event_category category;
/** Severity of log event */
enum ndb_mgm_event_severity severity;
/** Level (0-15) of log event */
unsigned level;
/** Node ID of the node that reported the log event */
unsigned source_nodeid;
/** Union of log event specific data. Use @ref type to decide
* which struct to use
*/
union {
/* CONNECT */
struct {
unsigned node;
} Connected;
struct {
unsigned node;
} Disconnected;
struct {
unsigned node;
} CommunicationClosed;
struct {
unsigned node;
} CommunicationOpened;
struct {
unsigned node;
unsigned version;
} ConnectedApiVersion;
/* CHECKPOINT */
struct {
unsigned gci;
} GlobalCheckpointStarted;
struct {
unsigned gci;
} GlobalCheckpointCompleted;
struct {
unsigned lci;
unsigned keep_gci;
unsigned restore_gci;
} LocalCheckpointStarted;
struct {
unsigned lci;
} LocalCheckpointCompleted;
struct {
unsigned data;
} LCPStoppedInCalcKeepGci;
struct {
unsigned node;
unsigned table_id;
unsigned fragment_id;
} LCPFragmentCompleted;
struct {
unsigned acc_count;
unsigned tup_count;
} UndoLogBlocked;
/* STARTUP */
struct {
unsigned version;
} NDBStartStarted;
struct {
unsigned version;
} NDBStartCompleted;
struct {
} STTORRYRecieved;
struct {
unsigned phase;
unsigned starttype;
} StartPhaseCompleted;
struct {
unsigned own_id;
unsigned president_id;
unsigned dynamic_id;
} CM_REGCONF;
struct {
unsigned own_id;
unsigned other_id;
unsigned cause;
} CM_REGREF;
struct {
unsigned own_id;
unsigned left_id;
unsigned right_id;
unsigned dynamic_id;
} FIND_NEIGHBOURS;
struct {
unsigned stoptype;
} NDBStopStarted;
struct {
} NDBStopAborted;
struct {
unsigned node;
unsigned keep_gci;
unsigned completed_gci;
unsigned restorable_gci;
} StartREDOLog;
struct {
unsigned log_part;
unsigned start_mb;
unsigned stop_mb;
unsigned gci;
} StartLog;
struct {
unsigned block;
unsigned data1;
unsigned data2;
unsigned data3;
unsigned data4;
unsigned data5;
unsigned data6;
unsigned data7;
unsigned data8;
unsigned data9;
unsigned data10;
} UNDORecordsExecuted;
/* NODERESTART */
struct {
} NR_CopyDict;
struct {
} NR_CopyDistr;
struct {
unsigned dest_node;
} NR_CopyFragsStarted;
struct {
unsigned dest_node;
unsigned table_id;
unsigned fragment_id;
} NR_CopyFragDone;
struct {
unsigned dest_node;
} NR_CopyFragsCompleted;
struct {
unsigned block; /* 0 = all */
unsigned failed_node;
unsigned completing_node; /* 0 = all */
} NodeFailCompleted;
struct {
unsigned failed_node;
unsigned failure_state;
} NODE_FAILREP;
struct {
/* TODO */
} ArbitState;
struct {
/* TODO */
} ArbitResult;
struct {
} GCP_TakeoverStarted;
struct {
} GCP_TakeoverCompleted;
struct {
} LCP_TakeoverStarted;
struct {
unsigned state;
} LCP_TakeoverCompleted;
/* STATISTIC */
struct {
unsigned trans_count;
unsigned commit_count;
unsigned read_count;
unsigned simple_read_count;
unsigned write_count;
unsigned attrinfo_count;
unsigned conc_op_count;
unsigned abort_count;
unsigned scan_count;
unsigned range_scan_count;
} TransReportCounters;
struct {
unsigned ops;
} OperationReportCounters;
struct {
unsigned table_id;
} TableCreated;
struct {
unsigned mean_loop_count;
} JobStatistic;
struct {
unsigned to_node;
unsigned mean_sent_bytes;
} SendBytesStatistic;
struct {
unsigned from_node;
unsigned mean_received_bytes;
} ReceiveBytesStatistic;
struct {
int gth;
unsigned page_size_kb;
unsigned pages_used;
unsigned pages_total;
unsigned block;
} MemoryUsage;
/* ERROR */
struct {
unsigned to_node;
unsigned code;
} TransporterError;
struct {
unsigned to_node;
unsigned code;
} TransporterWarning;
struct {
unsigned node;
unsigned count;
} MissedHeartbeat;
struct {
unsigned node;
} DeadDueToHeartbeat;
struct {
/* TODO */
} WarningEvent;
/* INFO */
struct {
unsigned node;
} SentHeartbeat;
struct {
unsigned node;
} CreateLogBytes;
struct {
/* TODO */
} InfoEvent;
/** Log event data for @ref NDB_LE_BackupStarted */
struct {
unsigned starting_node;
unsigned backup_id;
} BackupStarted;
/** Log event data @ref NDB_LE_BackupFailedToStart */
struct {
unsigned starting_node;
unsigned error;
} BackupFailedToStart;
/** Log event data @ref NDB_LE_BackupCompleted */
struct {
unsigned starting_node;
unsigned backup_id;
unsigned start_gci;
unsigned stop_gci;
unsigned n_records;
unsigned n_log_records;
unsigned n_bytes;
unsigned n_log_bytes;
} BackupCompleted;
/** Log event data @ref NDB_LE_BackupAborted */
struct {
unsigned starting_node;
unsigned backup_id;
unsigned error;
} BackupAborted;
#ifndef DOXYGEN_FIX
};
#else
} <union>;
#endif
};
enum ndb_logevent_handle_error {
NDB_LEH_NO_ERROR,
NDB_LEH_READ_ERROR,
NDB_LEH_MISSING_EVENT_SPECIFIER,
NDB_LEH_UNKNOWN_EVENT_TYPE,
NDB_LEH_UNKNOWN_EVENT_VARIABLE,
NDB_LEH_INTERNAL_ERROR
};
#ifdef __cplusplus
}
#endif
/** @} */
#endif

File diff suppressed because it is too large Load Diff

View File

@ -198,7 +198,8 @@ void Cmvmi::execEVENT_REP(Signal* signal)
Uint32 threshold;
LogLevel::EventCategory eventCategory;
Logger::LoggerLevel severity;
if (EventLoggerBase::event_lookup(eventType,eventCategory,threshold,severity))
EventLoggerBase::EventTextFunction textF;
if (EventLoggerBase::event_lookup(eventType,eventCategory,threshold,severity,textF))
return;
SubscriberPtr ptr;

View File

@ -1,7 +1,7 @@
noinst_LTLIBRARIES = libmgmapi.la
libmgmapi_la_SOURCES = mgmapi.cpp mgmapi_configuration.cpp LocalConfig.cpp
libmgmapi_la_SOURCES = mgmapi.cpp ndb_logevent.cpp mgmapi_configuration.cpp LocalConfig.cpp
INCLUDES_LOC = -I$(top_srcdir)/ndb/include/mgmapi

View File

@ -22,8 +22,8 @@
#include <NdbSleep.h>
#include <NdbTCP.h>
#include "mgmapi.h"
#include "mgmapi_debug.h"
#include <mgmapi.h>
#include <mgmapi_debug.h>
#include "mgmapi_configuration.hpp"
#include <socket_io.h>
@ -1156,9 +1156,9 @@ ndb_mgm_set_loglevel_node(NdbMgmHandle handle, int nodeId,
return 0;
}
extern "C"
int
ndb_mgm_listen_event(NdbMgmHandle handle, const int filter[])
ndb_mgm_listen_event_internal(NdbMgmHandle handle, const int filter[],
int structured)
{
SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_listen_event");
const ParserRow<ParserDummy> stat_reply[] = {
@ -1180,6 +1180,8 @@ ndb_mgm_listen_event(NdbMgmHandle handle, const int filter[])
}
Properties args;
args.put("structured", structured);
{
BaseString tmp;
for(int i = 0; filter[i] != 0; i += 2){
@ -1203,6 +1205,13 @@ ndb_mgm_listen_event(NdbMgmHandle handle, const int filter[])
return sockfd;
}
extern "C"
int
ndb_mgm_listen_event(NdbMgmHandle handle, const int filter[])
{
return ndb_mgm_listen_event_internal(handle,filter,0);
}
extern "C"
int
ndb_mgm_get_stat_port(NdbMgmHandle handle, struct ndb_mgm_reply* /*reply*/)
@ -2138,5 +2147,4 @@ ndb_mgm_get_connection_int_parameter(NdbMgmHandle handle,
DBUG_RETURN(res);
}
template class Vector<const ParserRow<ParserDummy>*>;

View File

@ -1,3 +1,19 @@
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef MGMAPI_CONFIGURATION_HPP
#define MGMAPI_CONFIGURATION_HPP

View File

@ -0,0 +1,477 @@
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <my_sys.h>
#include <mgmapi.h>
#include <NdbOut.hpp>
#include <Properties.hpp>
#include <socket_io.h>
#include <InputStream.hpp>
#include <debugger/EventLogger.hpp>
#include "ndb_logevent.hpp"
extern
int ndb_mgm_listen_event_internal(NdbMgmHandle, const int filter[], int);
struct ndb_logevent_error_msg {
enum ndb_logevent_handle_error code;
const char *msg;
};
struct ndb_logevent_error_msg ndb_logevent_error_messages[]= {
{ NDB_LEH_READ_ERROR, "Read error" },
{ NDB_LEH_MISSING_EVENT_SPECIFIER, "Missing event specifier" },
{ NDB_LEH_UNKNOWN_EVENT_VARIABLE, "Unknown event variable" },
{ NDB_LEH_UNKNOWN_EVENT_TYPE, "Unknown event type" },
{ NDB_LEH_INTERNAL_ERROR, "Unknown internal error" },
{ NDB_LEH_NO_ERROR,0}
};
struct ndb_logevent_handle {
NDB_SOCKET_TYPE socket;
enum ndb_logevent_handle_error m_error;
};
extern "C"
NdbLogEventHandle
ndb_mgm_create_logevent_handle(NdbMgmHandle mh,
const int filter[])
{
int fd= ndb_mgm_listen_event_internal(mh, filter, 1);
if (fd == -1)
return 0;
NdbLogEventHandle h=
(NdbLogEventHandle)my_malloc(sizeof(ndb_logevent_handle),MYF(MY_WME));
h->socket= fd;
return h;
}
extern "C"
void ndb_mgm_destroy_logevent_handle(NdbLogEventHandle * h)
{
if( !h )
return;
if ( *h )
close((*h)->socket);
my_free((char*)* h,MYF(MY_ALLOW_ZERO_PTR));
* h = 0;
}
#define ROW(a,b,c,d) \
{ NDB_LE_ ## a, b, c, 0, offsetof(struct ndb_logevent, a.d), \
sizeof(((struct ndb_logevent *)0)->a.d) }
#define ROW_FN(a,b,c,d,e) \
{ NDB_LE_ ## a, b, c, e, offsetof(struct ndb_logevent, a.d), \
sizeof(((struct ndb_logevent *)0)->a.d) }
static int ref_to_node(int ref){
return ref & 0xFFFF;
}
struct Ndb_logevent_body_row ndb_logevent_body[]= {
// Connection
ROW( Connected, "node", 1, node),
ROW( Disconnected, "node", 1, node),
ROW( CommunicationClosed, "node", 1, node),
ROW( CommunicationOpened, "node", 1, node),
ROW( ConnectedApiVersion, "node", 1, node),
ROW( ConnectedApiVersion, "version", 2, version),
/* CHECKPOINT */
ROW( GlobalCheckpointStarted, "gci", 1, gci),
ROW( GlobalCheckpointCompleted, "gci", 1, gci),
ROW( LocalCheckpointStarted, "lci", 1, lci),
ROW( LocalCheckpointStarted, "keep_gci", 2, keep_gci),
ROW( LocalCheckpointStarted, "restore_gci", 3, restore_gci),
ROW( LocalCheckpointCompleted, "lci", 1, lci),
ROW( LCPStoppedInCalcKeepGci, "data", 1, data),
ROW( LCPFragmentCompleted, "node", 1, node),
ROW( LCPFragmentCompleted, "table_id", 2, table_id),
ROW( LCPFragmentCompleted, "fragment_id", 3, fragment_id),
ROW( UndoLogBlocked, "acc_count", 1, acc_count),
ROW( UndoLogBlocked, "tup_count", 2, tup_count),
/* STARTUP */
ROW( NDBStartStarted, "version", 1, version),
ROW( NDBStartCompleted, "version", 1, version),
// ROW( STTORRYRecieved),
ROW( StartPhaseCompleted, "phase", 1, phase),
ROW( StartPhaseCompleted, "starttype", 2, starttype),
ROW( CM_REGCONF, "own_id", 1, own_id),
ROW( CM_REGCONF, "president_id", 2, president_id),
ROW( CM_REGCONF, "dynamic_id", 3, dynamic_id),
ROW( CM_REGREF, "own_id", 1, own_id),
ROW( CM_REGREF, "other_id", 2, other_id),
ROW( CM_REGREF, "cause", 3, cause),
ROW( FIND_NEIGHBOURS, "own_id", 1, own_id),
ROW( FIND_NEIGHBOURS, "left_id", 3, left_id),
ROW( FIND_NEIGHBOURS, "right_id", 3, right_id),
ROW( FIND_NEIGHBOURS, "dynamic_id", 4, dynamic_id),
ROW( NDBStopStarted, "stoptype", 1, stoptype),
// ROW( NDBStopAborted),
ROW( StartREDOLog, "node", 1, node),
ROW( StartREDOLog, "keep_gci", 2, keep_gci),
ROW( StartREDOLog, "completed_gci", 3, completed_gci),
ROW( StartREDOLog, "restorable_gci", 4, restorable_gci),
ROW( StartLog, "log_part", 1, log_part),
ROW( StartLog, "start_mb", 2, start_mb),
ROW( StartLog, "stop_mb", 3, stop_mb),
ROW( StartLog, "gci", 4, gci),
ROW( UNDORecordsExecuted, "block", 1, block),
ROW( UNDORecordsExecuted, "data1", 2, data1),
ROW( UNDORecordsExecuted, "data2", 3, data2),
ROW( UNDORecordsExecuted, "data3", 4, data3),
ROW( UNDORecordsExecuted, "data4", 5, data4),
ROW( UNDORecordsExecuted, "data5", 6, data5),
ROW( UNDORecordsExecuted, "data6", 7, data6),
ROW( UNDORecordsExecuted, "data7", 8, data7),
ROW( UNDORecordsExecuted, "data8", 9, data8),
ROW( UNDORecordsExecuted, "data9", 10, data9),
ROW( UNDORecordsExecuted, "data10", 11, data10),
/* NODERESTART */
// ROW( NR_CopyDict),
// ROW( NR_CopyDistr),
ROW( NR_CopyFragsStarted, "dest_node", 1, dest_node),
ROW( NR_CopyFragDone, "dest_node", 1, dest_node),
ROW( NR_CopyFragDone, "table_id", 2, table_id),
ROW( NR_CopyFragDone, "fragment_id", 3, fragment_id),
ROW( NR_CopyFragsCompleted, "dest_node", 1, dest_node),
ROW( NodeFailCompleted, "block", 1, block), /* 0 = all */
ROW( NodeFailCompleted, "failed_node", 2, failed_node),
ROW( NodeFailCompleted, "completing_node", 3, completing_node), /* 0 = all */
ROW( NODE_FAILREP, "failed_node", 1, failed_node),
ROW( NODE_FAILREP, "failure_state", 2, failure_state),
/* TODO */
// ROW( ArbitState),
/* TODO */
// ROW( ArbitResult),
// ROW( GCP_TakeoverStarted),
// ROW( GCP_TakeoverCompleted),
// ROW( LCP_TakeoverStarted),
ROW( LCP_TakeoverCompleted, "state", 1, state),
/* STATISTIC */
ROW( TransReportCounters, "trans_count", 1, trans_count),
ROW( TransReportCounters, "commit_count", 2, commit_count),
ROW( TransReportCounters, "read_count", 3, read_count),
ROW( TransReportCounters, "simple_read_count", 4, simple_read_count),
ROW( TransReportCounters, "write_count", 5, write_count),
ROW( TransReportCounters, "attrinfo_count", 6, attrinfo_count),
ROW( TransReportCounters, "conc_op_count", 7, conc_op_count),
ROW( TransReportCounters, "abort_count", 8, abort_count),
ROW( TransReportCounters, "scan_count", 9, scan_count),
ROW( TransReportCounters, "range_scan_count", 10, range_scan_count),
ROW( OperationReportCounters, "ops", 1, ops),
ROW( TableCreated, "table_id", 1, table_id),
ROW( JobStatistic, "mean_loop_count", 1, mean_loop_count),
ROW( SendBytesStatistic, "to_node", 1, to_node),
ROW( SendBytesStatistic, "mean_sent_bytes", 2, mean_sent_bytes),
ROW( ReceiveBytesStatistic, "from_node", 1, from_node),
ROW( ReceiveBytesStatistic, "mean_received_bytes", 2, mean_received_bytes),
ROW( MemoryUsage, "gth", 1, gth),
ROW( MemoryUsage, "page_size_kb", 2, page_size_kb),
ROW( MemoryUsage, "pages_used", 3, pages_used),
ROW( MemoryUsage, "pages_total", 4, pages_total),
ROW( MemoryUsage, "block", 5, block),
/* ERROR */
ROW( TransporterError, "to_node", 1, to_node),
ROW( TransporterError, "code", 2, code),
ROW( TransporterWarning, "to_node", 1, to_node),
ROW( TransporterWarning, "code", 2, code),
ROW( MissedHeartbeat, "node", 1, node),
ROW( MissedHeartbeat, "count", 2, count),
ROW( DeadDueToHeartbeat, "node", 1, node),
/* TODO */
// ROW( WarningEvent),
/* INFO */
ROW( SentHeartbeat, "node", 1, node),
ROW( CreateLogBytes, "node", 1, node),
/* TODO */
// ROW( InfoEvent),
// Backup
ROW_FN( BackupStarted, "starting_node", 1, starting_node, ref_to_node),
ROW( BackupStarted, "backup_id", 2, backup_id),
ROW_FN(BackupFailedToStart,"starting_node",1, starting_node, ref_to_node),
ROW( BackupFailedToStart, "error", 2, error),
ROW_FN( BackupCompleted, "starting_node", 1, starting_node, ref_to_node),
ROW( BackupCompleted, "backup_id", 2, backup_id),
ROW( BackupCompleted, "start_gci", 3, start_gci),
ROW( BackupCompleted, "stop_gci", 4, stop_gci),
ROW( BackupCompleted, "n_bytes", 5, n_bytes),
ROW( BackupCompleted, "n_records", 6, n_records),
ROW( BackupCompleted, "n_log_bytes", 7, n_log_bytes),
ROW( BackupCompleted, "n_log_records", 8, n_log_records),
ROW_FN( BackupAborted, "starting_node", 1, starting_node, ref_to_node),
ROW( BackupAborted, "backup_id", 2, backup_id),
ROW( BackupAborted, "error", 3, error),
{ NDB_LE_ILLEGAL_TYPE, 0, 0, 0, 0}
};
struct Ndb_logevent_header_row {
const char *token; // token to use for text transfer
int offset; // offset into struct ndb_logevent
int size;
};
#define ROW2(a,b) \
{ a, offsetof(struct ndb_logevent, b), \
sizeof(((struct ndb_logevent *)0)->b) }
struct Ndb_logevent_header_row ndb_logevent_header[]= {
ROW2( "type", type),
ROW2( "time", time),
ROW2( "source_nodeid", source_nodeid),
{ 0, 0, 0 }
};
static int
insert_row(const char * pair, Properties & p){
BaseString tmp(pair);
tmp.trim(" \t\n\r");
Vector<BaseString> split;
tmp.split(split, ":=", 2);
if(split.size() != 2)
return -1;
p.put(split[0].trim().c_str(), split[1].trim().c_str());
return 0;
}
static
int memcpy_atoi(void *dst, const char *str, int sz)
{
switch (sz)
{
case 1:
{
Int8 val= atoi(str);
memcpy(dst,&val,sz);
return 0;
}
case 2:
{
Int16 val= atoi(str);
memcpy(dst,&val,sz);
return 0;
}
case 4:
{
Int32 val= atoi(str);
memcpy(dst,&val,sz);
return 0;
}
case 8:
{
Int64 val= atoi(str);
memcpy(dst,&val,sz);
return 0;
}
default:
{
return -1;
}
}
}
extern "C"
int ndb_logevent_get_next(const NdbLogEventHandle h,
struct ndb_logevent *dst,
unsigned timeout_in_milliseconds)
{
SocketInputStream in(h->socket, timeout_in_milliseconds);
Properties p;
char buf[256];
/* header */
while (1) {
if (in.gets(buf,sizeof(buf)) == 0)
{
h->m_error= NDB_LEH_READ_ERROR;
return -1;
}
if ( buf[0] == 0 )
{
// timed out
return 0;
}
if ( strcmp("log event reply\n", buf) == 0 )
break;
ndbout_c("skipped: %s", buf);
}
/* read name-value pairs into properties object */
while (1)
{
if (in.gets(buf,sizeof(buf)) == 0)
{
h->m_error= NDB_LEH_READ_ERROR;
return -1;
}
if ( buf[0] == 0 )
{
// timed out
return 0;
}
if ( buf[0] == '\n' )
{
break;
}
if (insert_row(buf,p))
{
h->m_error= NDB_LEH_READ_ERROR;
return -1;
}
}
int i;
const char *val;
dst->type= (enum Ndb_logevent_type)-1;
/* fill in header info from p*/
for (i= 0; ndb_logevent_header[i].token; i++)
{
if ( p.get(ndb_logevent_header[i].token, &val) == 0 )
{
ndbout_c("missing: %s\n", ndb_logevent_header[i].token);
h->m_error= NDB_LEH_MISSING_EVENT_SPECIFIER;
return -1;
}
if ( memcpy_atoi((char *)dst+ndb_logevent_header[i].offset, val,
ndb_logevent_header[i].size) )
{
h->m_error= NDB_LEH_INTERNAL_ERROR;
return -1;
}
}
Uint32 level;
LogLevel::EventCategory category;
Logger::LoggerLevel severity;
EventLoggerBase::EventTextFunction text_fn;
/* fill in rest of header info event_lookup */
if (EventLoggerBase::event_lookup(dst->type,category,level,severity,text_fn))
{
ndbout_c("unknown type: %d\n", dst->type);
h->m_error= NDB_LEH_UNKNOWN_EVENT_TYPE;
return -1;
}
dst->category= (enum ndb_mgm_event_category)category;
dst->severity= (enum ndb_mgm_event_severity)severity;
dst->level= level;
/* fill in header info from p */
for (i= 0; ndb_logevent_body[i].token; i++)
{
if ( ndb_logevent_body[i].type != dst->type )
continue;
if ( p.get(ndb_logevent_body[i].token, &val) == 0 )
{
h->m_error= NDB_LEH_UNKNOWN_EVENT_VARIABLE;
return -1;
}
if ( memcpy_atoi((char *)dst+ndb_logevent_body[i].offset, val,
ndb_logevent_body[i].size) )
{
h->m_error= NDB_LEH_INTERNAL_ERROR;
return -1;
}
}
return 1;
}
extern "C"
int ndb_logevent_get_latest_error(const NdbLogEventHandle h)
{
return h->m_error;
}
extern "C"
const char *ndb_logevent_get_latest_error_msg(const NdbLogEventHandle h)
{
for (int i= 0; ndb_logevent_error_messages[i].msg; i++)
if (ndb_logevent_error_messages[i].code == h->m_error)
return ndb_logevent_error_messages[i].msg;
return "<unknown error msg>";
}

View File

@ -0,0 +1,34 @@
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef NDB_LOGEVENT_HPP
#define NDB_LOGEVENT_HPP
#include <ndb_logevent.h>
struct Ndb_logevent_body_row {
enum Ndb_logevent_type type; // type
const char *token; // token to use for text transfer
int index; // index into theData array
int (*index_fn)(int); // conversion function on the data array[index]
int offset; // offset into struct ndb_logevent
int size; // offset into struct ndb_logevent
};
extern
struct Ndb_logevent_body_row ndb_logevent_body[];
#endif

View File

@ -49,6 +49,7 @@ class Ndb_mgmd_event_service : public EventLoggerBase
public:
struct Event_listener : public EventLoggerBase {
NDB_SOCKET_TYPE m_socket;
Uint32 m_parsable;
};
private:

View File

@ -31,6 +31,7 @@
#include <mgmapi_configuration.hpp>
#include <Vector.hpp>
#include "Services.hpp"
#include "../mgmapi/ndb_logevent.hpp"
extern bool g_StopServer;
@ -256,6 +257,7 @@ ParserRow<MgmApiSession> commands[] = {
MGM_CMD("listen event", &MgmApiSession::listen_event, ""),
MGM_ARG("node", Int, Optional, "Node"),
MGM_ARG("parsable", Int, Optional, "Parsable"),
MGM_ARG("filter", String, Mandatory, "Event category"),
MGM_CMD("purge stale sessions", &MgmApiSession::purge_stale_sessions, ""),
@ -1249,25 +1251,49 @@ Ndb_mgmd_event_service::log(int eventType, const Uint32* theData, NodeId nodeId)
Uint32 threshold;
LogLevel::EventCategory cat;
Logger::LoggerLevel severity;
EventLoggerBase::EventTextFunction textF;
int i;
DBUG_ENTER("Ndb_mgmd_event_service::log");
DBUG_PRINT("enter",("eventType=%d, nodeid=%d", eventType, nodeId));
if (EventLoggerBase::event_lookup(eventType,cat,threshold,severity))
if (EventLoggerBase::event_lookup(eventType,cat,threshold,severity,textF))
DBUG_VOID_RETURN;
char m_text[256];
EventLogger::getText(m_text, sizeof(m_text), eventType, theData, nodeId);
EventLogger::getText(m_text, sizeof(m_text),
textF, theData, nodeId);
Vector<NDB_SOCKET_TYPE> copy;
BaseString str("log event reply\n");
str.appfmt("type=%d\n", eventType);
str.appfmt("time=%d\n", 0);
str.appfmt("source_nodeid=%d\n", nodeId);
for (i= 0; ndb_logevent_body[i].token; i++)
{
if ( ndb_logevent_body[i].type != eventType)
continue;
int val= theData[ndb_logevent_body[i].index];
if (ndb_logevent_body[i].index_fn)
val= (*(ndb_logevent_body[i].index_fn))(val);
str.appfmt("%s=%d\n",ndb_logevent_body[i].token, val);
}
Vector<NDB_SOCKET_TYPE> copy;
m_clients.lock();
for(i = m_clients.size() - 1; i >= 0; i--){
if(threshold <= m_clients[i].m_logLevel.getLogLevel(cat)){
if(m_clients[i].m_socket != NDB_INVALID_SOCKET &&
println_socket(m_clients[i].m_socket,
MAX_WRITE_TIMEOUT, m_text) == -1){
copy.push_back(m_clients[i].m_socket);
m_clients.erase(i, false);
if(m_clients[i].m_socket != NDB_INVALID_SOCKET)
{
int r;
if (m_clients[i].m_parsable)
r= println_socket(m_clients[i].m_socket,
MAX_WRITE_TIMEOUT, str.c_str());
else
r= println_socket(m_clients[i].m_socket,
MAX_WRITE_TIMEOUT, m_text);
if (r == -1) {
copy.push_back(m_clients[i].m_socket);
m_clients.erase(i, false);
}
}
}
}
@ -1395,15 +1421,17 @@ MgmApiSession::getConnectionParameter(Parser_t::Context &ctx,
void
MgmApiSession::listen_event(Parser<MgmApiSession>::Context & ctx,
Properties const & args) {
Uint32 parsable= 0;
BaseString node, param, value;
args.get("node", node);
args.get("filter", param);
args.get("parsable", &parsable);
int result = 0;
BaseString msg;
Ndb_mgmd_event_service::Event_listener le;
le.m_parsable = parsable;
le.m_socket = m_socket;
Vector<BaseString> list;