mariadb/ndb/include/ndbapi/NdbEventOperation.hpp

226 lines
7.7 KiB
C++
Raw Normal View History

2004-04-14 10:53:21 +02:00
/* 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 NdbEventOperation_H
#define NdbEventOperation_H
class NdbGlobalEventBuffer;
class NdbEventOperationImpl;
/**
* @class NdbEventOperation
* @brief Class of operations for getting change events from database.
*
2005-01-07 15:11:32 +01:00
* Brief description on how to work with events:
*
* - An event, represented by an NdbDictionary::Event, i created in the
* Database through
2005-01-07 15:11:32 +01:00
* NdbDictionary::Dictionary::createEvent() (note that this can be done
* by any application or thread and not necessarily by the "listener")
* - To listen to events, an NdbEventOperation object is instantiated by
* Ndb::createEventOperation()
* - execute() starts the event flow. Use Ndb::pollEvents() to wait
* for an event to occur. Use next() to iterate
* through the events that have occured.
* - The instance is removed by Ndb::dropEventOperation()
2004-04-14 10:53:21 +02:00
*
* For more info see:
* @ref ndbapi_event.cpp
2004-04-14 10:53:21 +02:00
*
* Known limitations:
*
2005-01-07 15:11:32 +01:00
* - Maximum number of active NdbEventOperations are now set at compile time.
2004-04-14 10:53:21 +02:00
* Today 100. This will become a configuration parameter later.
2005-01-07 15:11:32 +01:00
* - Maximum number of NdbEventOperations tied to same event are maximum 16
2004-04-14 10:53:21 +02:00
* per process.
*
* Known issues:
*
2005-01-07 15:11:32 +01:00
* - When several NdbEventOperation's are tied to the same event in the same
2004-04-14 10:53:21 +02:00
* process they will share the circular buffer. The BufferLength will then
* be the same for all and decided by the first NdbEventOperation
* instantiation. Just make sure to instantiate the "largest" one first.
2005-01-07 15:11:32 +01:00
* - Today all events INSERT/DELETE/UPDATE and all changed attributes are
2004-04-14 10:53:21 +02:00
* sent to the API, even if only specific attributes have been specified.
* These are however hidden from the user and only relevant data is shown
2005-01-02 13:21:17 +01:00
* after next().
2005-01-07 15:11:32 +01:00
* - "False" exits from Ndb::pollEvents() may occur and thus
2005-01-02 13:21:17 +01:00
* the subsequent next() will return zero,
* since there was no available data. Just do Ndb::pollEvents() again.
2005-01-07 15:11:32 +01:00
* - Event code does not check table schema version. Make sure to drop events
2004-04-14 10:53:21 +02:00
* after table is dropped. Will be fixed in later
* versions.
2005-01-07 15:11:32 +01:00
* - If a node failure has occured not all events will be recieved
2004-04-14 10:53:21 +02:00
* anymore. Drop NdbEventOperation and Create again after nodes are up
* again. Will be fixed in later versions.
*
* Test status:
*
2005-01-07 15:11:32 +01:00
* - Tests have been run on 1-node and 2-node systems
2004-04-14 10:53:21 +02:00
*
* Useful API programs:
*
2005-01-07 15:11:32 +01:00
* - ndb_select_all -d sys 'NDB$EVENTS_0'
* shows contents in the system table containing created events.
2004-04-14 10:53:21 +02:00
*
2005-01-07 15:11:32 +01:00
* @note this is an inteface to viewing events that is subject to change
2004-04-14 10:53:21 +02:00
*/
class NdbEventOperation {
public:
2005-01-07 15:11:32 +01:00
/**
* State of the NdbEventOperation object
*/
enum State {
EO_CREATED, ///< Created but execute() not called
EO_EXECUTING, ///< execute() called
EO_ERROR ///< An error has occurred. Object unusable.
};
2005-01-02 13:21:17 +01:00
/**
* Retrieve current state of the NdbEventOperation object
*/
2004-04-14 10:53:21 +02:00
State getState();
/**
* Activates the NdbEventOperation to start receiving events. The
* changed attribute values may be retrieved after next() has returned
2005-01-07 15:11:32 +01:00
* a value greater than zero. The getValue() methods must be called
2004-04-14 10:53:21 +02:00
* prior to execute().
*
* @return 0 if successful otherwise -1.
*/
int execute();
// about the event operation
// getting data
// NdbResultSet* getResultSet();
/**
* Defines a retrieval operation of an attribute value.
* The NDB API allocate memory for the NdbRecAttr object that
* will hold the returned attribute value.
*
* @note Note that it is the applications responsibility
* to allocate enough memory for aValue (if non-NULL).
* The buffer aValue supplied by the application must be
* aligned appropriately. The buffer is used directly
* (avoiding a copy penalty) only if it is aligned on a
* 4-byte boundary and the attribute size in bytes
2005-01-07 15:11:32 +01:00
* (i.e. NdbRecAttr::attrSize() times NdbRecAttr::arraySize() is
2004-04-14 10:53:21 +02:00
* a multiple of 4).
*
2005-01-07 15:11:32 +01:00
* @note There are two versions, getValue() and
* getPreValue() for retrieving the current and
2004-04-14 10:53:21 +02:00
* previous value repectively.
*
* @note This method does not fetch the attribute value from
* the database! The NdbRecAttr object returned by this method
* is <em>not</em> readable/printable before the
2005-01-07 15:11:32 +01:00
* execute() has been made and
* next() has returned a value greater than
2004-04-14 10:53:21 +02:00
* zero. If a specific attribute has not changed the corresponding
* NdbRecAttr will be in state UNDEFINED. This is checked by
2005-01-10 01:25:20 +01:00
* NdbRecAttr::isNULL() which then returns -1.
2004-04-14 10:53:21 +02:00
*
* @param anAttrName Attribute name
* @param aValue If this is non-NULL, then the attribute value
* will be returned in this parameter.<br>
* If NULL, then the attribute value will only
* be stored in the returned NdbRecAttr object.
* @return An NdbRecAttr object to hold the value of
* the attribute, or a NULL pointer
* (indicating error).
*/
NdbRecAttr *getValue(const char *anAttrName, char *aValue = 0);
2005-01-10 01:25:20 +01:00
/**
* See getValue().
*/
NdbRecAttr *getPreValue(const char *anAttrName, char *aValue = 0);
2004-04-14 10:53:21 +02:00
/**
* Retrieves event resultset if available, inserted into the NdbRecAttrs
* specified in getValue() and getPreValue(). To avoid polling for
2005-01-07 15:11:32 +01:00
* a resultset, one can use Ndb::pollEvents()
2004-04-14 10:53:21 +02:00
* which will wait on a mutex until an event occurs or the specified
* timeout occurs.
*
2005-01-07 15:11:32 +01:00
* @return >=0 if successful otherwise -1. Return value indicates number
2004-04-14 10:53:21 +02:00
* of available events. By sending pOverRun one may query for buffer
* overflow and *pOverRun will indicate the number of events that have
* overwritten.
2005-01-02 13:21:17 +01:00
*
* @return number of available events, -1 on failure
2004-04-14 10:53:21 +02:00
*/
int next(int *pOverRun=0);
2004-04-14 10:53:21 +02:00
/**
* In the current implementation a nodefailiure may cause loss of events,
* in which case isConsistent() will return false
*/
bool isConsistent();
/**
* Query for occured event type.
2005-01-02 13:21:17 +01:00
*
* @note Only valid after next() has been called and returned value >= 0
*
* @return type of event
2004-04-14 10:53:21 +02:00
*/
NdbDictionary::Event::TableEvent getEventType();
2004-12-21 17:16:39 +01:00
/**
2005-01-02 13:21:17 +01:00
* Retrieve the GCI of the latest retrieved event
2004-12-21 17:16:39 +01:00
*
2005-01-02 13:21:17 +01:00
* @return GCI number
2004-12-21 17:16:39 +01:00
*/
2004-04-14 10:53:21 +02:00
Uint32 getGCI();
2004-12-21 17:16:39 +01:00
/**
2005-01-02 13:21:17 +01:00
* Retrieve the complete GCI in the cluster (not necessarily
* associated with an event)
2004-12-21 17:16:39 +01:00
*
2005-01-02 13:21:17 +01:00
* @return GCI number
2004-12-21 17:16:39 +01:00
*/
2004-04-14 10:53:21 +02:00
Uint32 getLatestGCI();
2004-12-21 17:16:39 +01:00
/**
* Get the latest error
*
* @return Error object.
*/
const struct NdbError & getNdbError() const;
2005-01-02 13:21:17 +01:00
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
2004-12-21 17:16:39 +01:00
/*
*
*/
2004-04-14 10:53:21 +02:00
void print();
2005-01-02 13:21:17 +01:00
#endif
2004-04-14 10:53:21 +02:00
private:
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
2004-04-14 10:53:21 +02:00
friend class NdbEventOperationImpl;
friend class Ndb;
#endif
2004-04-14 10:53:21 +02:00
NdbEventOperation(Ndb *theNdb, const char* eventName,int bufferLength);
~NdbEventOperation();
static int wait(void *p, int aMillisecondNumber);
class NdbEventOperationImpl &m_impl;
NdbEventOperation(NdbEventOperationImpl& impl);
};
typedef void (* NdbEventCallback)(NdbEventOperation*, Ndb*, void*);
#endif