Commit 97682b76 authored by unknown's avatar unknown

ndbapi event code cleanup

+ some more docs on event


ndb/examples/ndbapi_event_example/ndbapi_event.cpp:
  ndbapi event code cleanup
ndb/include/kernel/signaldata/CreateEvnt.hpp:
  ndbapi event code cleanup
ndb/include/ndbapi/NdbDictionary.hpp:
  ndbapi event code cleanup
ndb/src/ndbapi/NdbDictionaryImpl.cpp:
  ndbapi event code cleanup
ndb/src/ndbapi/ndberror.c:
  ndbapi event code cleanup
parent 41b5876e
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
* *
* NdbDictionary::Event * NdbDictionary::Event
* setTable() * setTable()
* addtableEvent() * addTableEvent()
* addEventColumn() * addEventColumn()
* *
* NdbEventOperation * NdbEventOperation
...@@ -63,12 +63,12 @@ ...@@ -63,12 +63,12 @@
* another process (e.g. flexBench -l 0 -stdtables). * another process (e.g. flexBench -l 0 -stdtables).
* We want to monitor what happens with columns COL0, COL2, COL11 * We want to monitor what happens with columns COL0, COL2, COL11
* *
* or together with the mysqlcluster client; * or together with the mysql client;
* *
* shell> mysqlcluster -u root * shell> mysql -u root
* mysql> create database TEST_DB; * mysql> create database TEST_DB;
* mysql> use TEST_DB; * mysql> use TEST_DB;
* mysql> create table TAB0 (COL0 int primary key, COL1 int, COL11 int); * mysql> create table TAB0 (COL0 int primary key, COL1 int, COL11 int) engine=ndb;
* *
* In another window start ndbapi_example5, wait until properly started * In another window start ndbapi_example5, wait until properly started
* *
...@@ -199,7 +199,7 @@ int main() ...@@ -199,7 +199,7 @@ int main()
printf("NULL"); printf("NULL");
} }
if (recAttrPre[i]->isNULL() >= 0) { // we have a value if (recAttrPre[i]->isNULL() >= 0) { // we have a value
printf(" post[%u]=", i); printf(" pre[%u]=", i);
if (recAttrPre[i]->isNULL() == 0) // we have a non-null value if (recAttrPre[i]->isNULL() == 0) // we have a non-null value
printf("%u", recAttrPre[i]->u_32_value()); printf("%u", recAttrPre[i]->u_32_value());
else // we have a null value else // we have a null value
...@@ -212,7 +212,7 @@ int main() ...@@ -212,7 +212,7 @@ int main()
;//printf("timed out\n"); ;//printf("timed out\n");
} }
// don't want to listen to events anymore // don't want to listen to events anymore
myNdb->dropEventOperation(op); if (myNdb->dropEventOperation(op)) APIERROR(myNdb->getNdbError());
j++; j++;
} }
...@@ -220,7 +220,8 @@ int main() ...@@ -220,7 +220,8 @@ int main()
{ {
NdbDictionary::Dictionary *myDict = myNdb->getDictionary(); NdbDictionary::Dictionary *myDict = myNdb->getDictionary();
if (!myDict) APIERROR(myNdb->getNdbError()); if (!myDict) APIERROR(myNdb->getNdbError());
myDict->dropEvent(eventName); // remove event from database // remove event from database
if (myDict->dropEvent(eventName)) APIERROR(myDict->getNdbError());
} }
delete myNdb; delete myNdb;
...@@ -232,8 +233,8 @@ int main() ...@@ -232,8 +233,8 @@ int main()
int myCreateEvent(Ndb* myNdb, int myCreateEvent(Ndb* myNdb,
const char *eventName, const char *eventName,
const char *eventTableName, const char *eventTableName,
const char **eventColumnName, const char **eventColumnNames,
const int noEventColumnName) const int noEventColumnNames)
{ {
NdbDictionary::Dictionary *myDict= myNdb->getDictionary(); NdbDictionary::Dictionary *myDict= myNdb->getDictionary();
if (!myDict) APIERROR(myNdb->getNdbError()); if (!myDict) APIERROR(myNdb->getNdbError());
...@@ -245,24 +246,20 @@ int myCreateEvent(Ndb* myNdb, ...@@ -245,24 +246,20 @@ int myCreateEvent(Ndb* myNdb,
// myEvent.addTableEvent(NdbDictionary::Event::TE_UPDATE); // myEvent.addTableEvent(NdbDictionary::Event::TE_UPDATE);
// myEvent.addTableEvent(NdbDictionary::Event::TE_DELETE); // myEvent.addTableEvent(NdbDictionary::Event::TE_DELETE);
for (int i = 0; i < noEventColumnName; i++) myEvent.addEventColumns(noEventColumnNames, eventColumnNames);
myEvent.addEventColumn(eventColumnName[i]);
int res = myDict->createEvent(myEvent); // Add event to database // Add event to database
if (myDict->createEvent(myEvent) == 0)
if (res == 0)
myEvent.print(); myEvent.print();
else { else if (myDict->getNdbError().code == 4709) {
printf("Event creation failed\n"); printf("Event creation failed, event exists\n");
printf("trying drop Event, maybe event exists\n"); printf("dropping Event...\n");
res = myDict->dropEvent(eventName); if (myDict->dropEvent(eventName)) APIERROR(myDict->getNdbError());
if (res)
exit(-1);
// try again // try again
res = myDict->createEvent(myEvent); // Add event to database // Add event to database
if (res) if ( myDict->createEvent(myEvent)) APIERROR(myDict->getNdbError());
exit(-1); } else
} APIERROR(myDict->getNdbError());
return res; return 0;
} }
...@@ -101,7 +101,7 @@ public: ...@@ -101,7 +101,7 @@ public:
Busy = 701, Busy = 701,
NotMaster = 702, NotMaster = 702,
SeizeError = 703, SeizeError = 703,
EventNotFound = 4238, EventNotFound = 4710,
EventNameTooLong = 4241, EventNameTooLong = 4241,
TooManyEvents = 4242, TooManyEvents = 4242,
BadRequestType = 4247, BadRequestType = 4247,
...@@ -363,11 +363,10 @@ struct CreateEvntRef { ...@@ -363,11 +363,10 @@ struct CreateEvntRef {
Busy = 701, Busy = 701,
NotMaster = 702, NotMaster = 702,
SeizeError = 703, SeizeError = 703,
EventNotFound = 4238, TooManyEvents = 4707,
EventExists = 4239, EventNameTooLong = 4708,
EventNameTooLong = 4241, EventExists = 4709,
TooManyEvents = 4242, EventNotFound = 4731,
// EventExists = 4244,
AttributeNotStored = 4245, AttributeNotStored = 4245,
AttributeNullable = 4246, AttributeNullable = 4246,
BadRequestType = 4247, BadRequestType = 4247,
...@@ -376,7 +375,7 @@ struct CreateEvntRef { ...@@ -376,7 +375,7 @@ struct CreateEvntRef {
InvalidEventType = 4250, InvalidEventType = 4250,
NotUnique = 4251, NotUnique = 4251,
AllocationError = 4252, AllocationError = 4252,
CreateEventTableFailed = 4253, CreateEventTableFailed = 4711,
InvalidAttributeOrder = 4255, InvalidAttributeOrder = 4255,
Temporary = 0x1 << 16 Temporary = 0x1 << 16
}; };
......
...@@ -931,13 +931,50 @@ public: ...@@ -931,13 +931,50 @@ public:
Event(const char *name); Event(const char *name);
virtual ~Event(); virtual ~Event();
void setName(const char *); /**
void setTable(const char *); * Set unique identifier for the event
void addTableEvent(const TableEvent); */
void setDurability(const EventDurability); void setName(const char *name);
/**
* Set table for which events should be detected
*/
void setTable(const char *tableName);
/**
* Add type of event that should be detected
*/
void addTableEvent(const TableEvent te);
/**
* Set durability of the event
*/
void setDurability(const EventDurability ed);
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
void addColumn(const Column &c); void addColumn(const Column &c);
#endif
/**
* Add a column on which events should be detected
*
* @param attrId Column id
*
* @note errors will mot be detected until createEvent() is called
*/
void addEventColumn(unsigned attrId); void addEventColumn(unsigned attrId);
/**
* Add a column on which events should be detected
*
* @param columnName Column name
*
* @note errors will mot be detected until createEvent() is called
*/
void addEventColumn(const char * columnName); void addEventColumn(const char * columnName);
/**
* Add several columns on which events should be detected
*
* @param n Number of columns
* @param columnNames Column names
*
* @note errors will mot be detected until
* NdbDictionary::Dictionary::createEvent() is called
*/
void addEventColumns(int n, const char ** columnNames); void addEventColumns(int n, const char ** columnNames);
/** /**
...@@ -950,7 +987,9 @@ public: ...@@ -950,7 +987,9 @@ public:
*/ */
virtual int getObjectVersion() const; virtual int getObjectVersion() const;
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
void print(); void print();
#endif
private: private:
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
......
...@@ -2236,10 +2236,9 @@ NdbDictionaryImpl::createEvent(NdbEventImpl & evnt) ...@@ -2236,10 +2236,9 @@ NdbDictionaryImpl::createEvent(NdbEventImpl & evnt)
NdbTableImpl* tab = getTable(evnt.getTable()); NdbTableImpl* tab = getTable(evnt.getTable());
if(tab == 0){ if(tab == 0){
// m_error.code = 3249;
ndbout_c(":createEvent: table %s not found", evnt.getTable());
#ifdef EVENT_DEBUG #ifdef EVENT_DEBUG
ndbout_c("NdbDictionaryImpl::createEvent: table not found: %s", evnt.getTable()); ndbout_c("NdbDictionaryImpl::createEvent: table not found: %s",
evnt.getTable());
#endif #endif
return -1; return -1;
} }
......
...@@ -79,6 +79,7 @@ static const char* empty_string = ""; ...@@ -79,6 +79,7 @@ static const char* empty_string = "";
* 4400 - "" * 4400 - ""
* 4500 - "" * 4500 - ""
* 4600 - "" * 4600 - ""
* 4700 - "" Event
* 5000 - Management server * 5000 - Management server
*/ */
...@@ -296,6 +297,22 @@ ErrorBundle ErrorCodes[] = { ...@@ -296,6 +297,22 @@ ErrorBundle ErrorCodes[] = {
{ 4232, AE, "Parallelism can only be between 1 and 240" }, { 4232, AE, "Parallelism can only be between 1 and 240" },
{ 290, AE, "Scan not started or has been closed by kernel due to timeout" }, { 290, AE, "Scan not started or has been closed by kernel due to timeout" },
/**
* Event application errors
*/
{ 4707, AE, "Too many event have been defined"},
{ 4708, AE, "Event name is too long"},
{ 4709, AE, "Event already exists"},
{ 4710, AE, "Event not found"},
{ 4711, AE, "Creation of event failed"},
/**
* Event internal errors
*/
{ 4731, IE, "Event not found"},
/** /**
* SchemaError * SchemaError
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment