ndbapi event code cleanup

+ some more docs on event
parent fa5127e2
......@@ -36,7 +36,7 @@
*
* NdbDictionary::Event
* setTable()
* addtableEvent()
* addTableEvent()
* addEventColumn()
*
* NdbEventOperation
......@@ -63,12 +63,12 @@
* another process (e.g. flexBench -l 0 -stdtables).
* 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> 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
*
......@@ -199,7 +199,7 @@ int main()
printf("NULL");
}
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
printf("%u", recAttrPre[i]->u_32_value());
else // we have a null value
......@@ -212,7 +212,7 @@ int main()
;//printf("timed out\n");
}
// don't want to listen to events anymore
myNdb->dropEventOperation(op);
if (myNdb->dropEventOperation(op)) APIERROR(myNdb->getNdbError());
j++;
}
......@@ -220,7 +220,8 @@ int main()
{
NdbDictionary::Dictionary *myDict = myNdb->getDictionary();
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;
......@@ -232,8 +233,8 @@ int main()
int myCreateEvent(Ndb* myNdb,
const char *eventName,
const char *eventTableName,
const char **eventColumnName,
const int noEventColumnName)
const char **eventColumnNames,
const int noEventColumnNames)
{
NdbDictionary::Dictionary *myDict= myNdb->getDictionary();
if (!myDict) APIERROR(myNdb->getNdbError());
......@@ -245,24 +246,20 @@ int myCreateEvent(Ndb* myNdb,
// myEvent.addTableEvent(NdbDictionary::Event::TE_UPDATE);
// myEvent.addTableEvent(NdbDictionary::Event::TE_DELETE);
for (int i = 0; i < noEventColumnName; i++)
myEvent.addEventColumn(eventColumnName[i]);
myEvent.addEventColumns(noEventColumnNames, eventColumnNames);
int res = myDict->createEvent(myEvent); // Add event to database
if (res == 0)
// Add event to database
if (myDict->createEvent(myEvent) == 0)
myEvent.print();
else {
printf("Event creation failed\n");
printf("trying drop Event, maybe event exists\n");
res = myDict->dropEvent(eventName);
if (res)
exit(-1);
else if (myDict->getNdbError().code == 4709) {
printf("Event creation failed, event exists\n");
printf("dropping Event...\n");
if (myDict->dropEvent(eventName)) APIERROR(myDict->getNdbError());
// try again
res = myDict->createEvent(myEvent); // Add event to database
if (res)
exit(-1);
}
// Add event to database
if ( myDict->createEvent(myEvent)) APIERROR(myDict->getNdbError());
} else
APIERROR(myDict->getNdbError());
return res;
return 0;
}
......@@ -101,7 +101,7 @@ public:
Busy = 701,
NotMaster = 702,
SeizeError = 703,
EventNotFound = 4238,
EventNotFound = 4710,
EventNameTooLong = 4241,
TooManyEvents = 4242,
BadRequestType = 4247,
......@@ -363,11 +363,10 @@ struct CreateEvntRef {
Busy = 701,
NotMaster = 702,
SeizeError = 703,
EventNotFound = 4238,
EventExists = 4239,
EventNameTooLong = 4241,
TooManyEvents = 4242,
// EventExists = 4244,
TooManyEvents = 4707,
EventNameTooLong = 4708,
EventExists = 4709,
EventNotFound = 4731,
AttributeNotStored = 4245,
AttributeNullable = 4246,
BadRequestType = 4247,
......@@ -376,7 +375,7 @@ struct CreateEvntRef {
InvalidEventType = 4250,
NotUnique = 4251,
AllocationError = 4252,
CreateEventTableFailed = 4253,
CreateEventTableFailed = 4711,
InvalidAttributeOrder = 4255,
Temporary = 0x1 << 16
};
......
......@@ -931,13 +931,50 @@ public:
Event(const char *name);
virtual ~Event();
void setName(const char *);
void setTable(const char *);
void addTableEvent(const TableEvent);
void setDurability(const EventDurability);
/**
* Set unique identifier for the event
*/
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);
#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);
/**
* 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);
/**
* 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);
/**
......@@ -950,7 +987,9 @@ public:
*/
virtual int getObjectVersion() const;
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
void print();
#endif
private:
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
......
......@@ -2236,10 +2236,9 @@ NdbDictionaryImpl::createEvent(NdbEventImpl & evnt)
NdbTableImpl* tab = getTable(evnt.getTable());
if(tab == 0){
// m_error.code = 3249;
ndbout_c(":createEvent: table %s not found", evnt.getTable());
#ifdef EVENT_DEBUG
ndbout_c("NdbDictionaryImpl::createEvent: table not found: %s", evnt.getTable());
ndbout_c("NdbDictionaryImpl::createEvent: table not found: %s",
evnt.getTable());
#endif
return -1;
}
......
......@@ -79,6 +79,7 @@ static const char* empty_string = "";
* 4400 - ""
* 4500 - ""
* 4600 - ""
* 4700 - "" Event
* 5000 - Management server
*/
......@@ -296,6 +297,22 @@ ErrorBundle ErrorCodes[] = {
{ 4232, AE, "Parallelism can only be between 1 and 240" },
{ 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
*/
......
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