summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <tomas@poseidon.ndb.mysql.com>2005-01-06 21:13:04 +0100
committerunknown <tomas@poseidon.ndb.mysql.com>2005-01-06 21:13:04 +0100
commit58f8f9b3ca30977cbd003cdc06fffc41a96a3557 (patch)
tree0ef3691f140cae1f4b492f5e1fde0df8a09cdc00
parentd42ff5df42e3acd43f7512b6f6fc1f2e9980e355 (diff)
downloadmariadb-git-58f8f9b3ca30977cbd003cdc06fffc41a96a3557.tar.gz
updated event example to make use of new NdbError member in NdbEventOperation
added my_pthread_init to get dbug print correct in Hugo added define for event error code ndb/examples/ndbapi_event_example/ndbapi_event.cpp: updated event example to make use of new NdbError member in NdbEventOperation + use define to check error code ndb/include/kernel/signaldata/CreateEvnt.hpp: updated create event signal to use define ndb/include/ndbapi/NdbEventOperation.hpp: added NdbError member to NdbEventOperation ndb/include/ndbapi/ndberror.h: added define for event error code ndb/src/kernel/blocks/dbdict/Dbdict.cpp: changed name of error code ndb/src/ndbapi/NdbEventOperation.cpp: added NdbError ndb/src/ndbapi/NdbEventOperationImpl.cpp: added debug printout added some error handling ndb/src/ndbapi/NdbEventOperationImpl.hpp: added NdbError ndb/src/ndbapi/Ndberr.cpp: added NdbError for NdbEventOperationImpl ndb/src/ndbapi/ndberror.c: changed some error codes ndb/test/ndbapi/test_event.cpp: added testcase for BUG#7627 ndb/test/src/HugoTransactions.cpp: added printout in event ndb/test/src/NDBT_Test.cpp: added my_pthread_init to get dbug print correct
-rw-r--r--ndb/examples/ndbapi_event_example/ndbapi_event.cpp10
-rw-r--r--ndb/include/kernel/signaldata/CreateEvnt.hpp3
-rw-r--r--ndb/include/ndbapi/NdbEventOperation.hpp7
-rw-r--r--ndb/include/ndbapi/ndberror.h2
-rw-r--r--ndb/src/kernel/blocks/dbdict/Dbdict.cpp2
-rw-r--r--ndb/src/ndbapi/NdbEventOperation.cpp20
-rw-r--r--ndb/src/ndbapi/NdbEventOperationImpl.cpp22
-rw-r--r--ndb/src/ndbapi/NdbEventOperationImpl.hpp19
-rw-r--r--ndb/src/ndbapi/Ndberr.cpp9
-rw-r--r--ndb/src/ndbapi/ndberror.c3
-rw-r--r--ndb/test/ndbapi/test_event.cpp47
-rw-r--r--ndb/test/src/HugoTransactions.cpp5
-rw-r--r--ndb/test/src/NDBT_Test.cpp3
13 files changed, 108 insertions, 44 deletions
diff --git a/ndb/examples/ndbapi_event_example/ndbapi_event.cpp b/ndb/examples/ndbapi_event_example/ndbapi_event.cpp
index 1c2c9ab5ac4..b2d6d1c9077 100644
--- a/ndb/examples/ndbapi_event_example/ndbapi_event.cpp
+++ b/ndb/examples/ndbapi_event_example/ndbapi_event.cpp
@@ -50,6 +50,7 @@
*/
#include <NdbApi.hpp>
+#include <ndberror.h>
// Used for cout
#include <stdio.h>
@@ -160,10 +161,9 @@ int main()
// set up the callbacks
printf("execute\n");
- if (op->execute()) { // This starts changes to "start flowing"
- printf("operation execution failed\n");
- exit(-1);
- }
+ // This starts changes to "start flowing"
+ if (op->execute())
+ APIERROR(op->getNdbError());
int i= 0;
while(i < 40) {
@@ -251,7 +251,7 @@ int myCreateEvent(Ndb* myNdb,
// Add event to database
if (myDict->createEvent(myEvent) == 0)
myEvent.print();
- else if (myDict->getNdbError().code == 4709) {
+ else if (myDict->getNdbError().code == NDBERR_EVENT_NAME_ALEADY_EXISTS) {
printf("Event creation failed, event exists\n");
printf("dropping Event...\n");
if (myDict->dropEvent(eventName)) APIERROR(myDict->getNdbError());
diff --git a/ndb/include/kernel/signaldata/CreateEvnt.hpp b/ndb/include/kernel/signaldata/CreateEvnt.hpp
index c381377c54f..0547818fd1b 100644
--- a/ndb/include/kernel/signaldata/CreateEvnt.hpp
+++ b/ndb/include/kernel/signaldata/CreateEvnt.hpp
@@ -17,6 +17,7 @@
#ifndef CREATE_EVNT_HPP
#define CREATE_EVNT_HPP
+#include <ndberror.h>
#include "SignalData.hpp"
#include <NodeBitmask.hpp>
#include <signaldata/DictTabInfo.hpp>
@@ -365,7 +366,7 @@ struct CreateEvntRef {
SeizeError = 703,
TooManyEvents = 4707,
EventNameTooLong = 4708,
- EventExists = 4709,
+ EventNameExists = NDBERR_EVENT_NAME_ALEADY_EXISTS,
EventNotFound = 4731,
AttributeNotStored = 4245,
AttributeNullable = 4246,
diff --git a/ndb/include/ndbapi/NdbEventOperation.hpp b/ndb/include/ndbapi/NdbEventOperation.hpp
index 8c2de36fc51..dc6c8b657c5 100644
--- a/ndb/include/ndbapi/NdbEventOperation.hpp
+++ b/ndb/include/ndbapi/NdbEventOperation.hpp
@@ -199,6 +199,13 @@ public:
*/
Uint32 getLatestGCI();
+ /**
+ * Get the latest error
+ *
+ * @return Error object.
+ */
+ const struct NdbError & getNdbError() const;
+
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/*
*
diff --git a/ndb/include/ndbapi/ndberror.h b/ndb/include/ndbapi/ndberror.h
index ceb1881a4cc..aea1c2f43ce 100644
--- a/ndb/include/ndbapi/ndberror.h
+++ b/ndb/include/ndbapi/ndberror.h
@@ -17,6 +17,8 @@
#ifndef NDBERROR_H
#define NDBERROR_H
+#define NDBERR_EVENT_NAME_ALEADY_EXISTS 746
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/ndb/src/kernel/blocks/dbdict/Dbdict.cpp b/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
index 96995df44d5..f62b1eda587 100644
--- a/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
+++ b/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
@@ -7849,7 +7849,7 @@ void Dbdict::createEventUTIL_EXECUTE(Signal *signal,
break;
case ZALREADYEXIST:
jam();
- evntRecPtr.p->m_errorCode = CreateEvntRef::EventExists;
+ evntRecPtr.p->m_errorCode = CreateEvntRef::EventNameExists;
break;
default:
jam();
diff --git a/ndb/src/ndbapi/NdbEventOperation.cpp b/ndb/src/ndbapi/NdbEventOperation.cpp
index d209293f8b0..e99cad918c5 100644
--- a/ndb/src/ndbapi/NdbEventOperation.cpp
+++ b/ndb/src/ndbapi/NdbEventOperation.cpp
@@ -15,23 +15,9 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-/*****************************************************************************
- * Name: NdbEventOperation.cpp
- * Include:
- * Link:
- * Author: Tomas Ulin MySQL AB
- * Date: 2003-11-21
- * Version: 0.1
- * Description: Event support
- * Documentation:
- * Adjust: 2003-11-21 Tomas Ulin First version.
- ****************************************************************************/
-
#include <Ndb.hpp>
-#include <signaldata/SumaImpl.hpp>
+#include <NdbError.hpp>
#include <portlib/NdbMem.h>
-#include <transporter/TransporterDefinitions.hpp>
-#include <NdbEventOperation.hpp>
#include "NdbEventOperationImpl.hpp"
#include "NdbDictionaryImpl.hpp"
@@ -123,3 +109,7 @@ NdbEventOperation::wait(void *p, int aMillisecondNumber)
NdbEventOperation::NdbEventOperation(NdbEventOperationImpl& impl)
: m_impl(impl) {}
+const struct NdbError &
+NdbEventOperation::getNdbError() const {
+ return m_impl.getNdbError();
+}
diff --git a/ndb/src/ndbapi/NdbEventOperationImpl.cpp b/ndb/src/ndbapi/NdbEventOperationImpl.cpp
index b3fac64d1c4..e41eec6e38e 100644
--- a/ndb/src/ndbapi/NdbEventOperationImpl.cpp
+++ b/ndb/src/ndbapi/NdbEventOperationImpl.cpp
@@ -223,13 +223,17 @@ NdbEventOperationImpl::execute()
int hasSubscriber;
- m_bufferId =
+ int r=
m_bufferHandle->prepareAddSubscribeEvent(m_eventImpl->m_eventId,
hasSubscriber /* return value */);
+ m_error.code= 4709;
- m_eventImpl->m_bufferId = m_bufferId;
+ if (r < 0)
+ return -1;
- int r = -1;
+ m_eventImpl->m_bufferId = m_bufferId = (Uint32)r;
+
+ r = -1;
if (m_bufferId >= 0) {
// now we check if there's already a subscriber
@@ -363,11 +367,11 @@ NdbEventOperationImpl::next(int *pOverrun)
#ifdef EVENT_DEBUG
printf("after values sz=%u\n", ptr[1].sz);
- for(int i=0; i < ptr[1].sz; i++)
+ for(int i=0; i < (int)ptr[1].sz; i++)
printf ("H'%.8X ",ptr[1].p[i]);
printf("\n");
printf("before values sz=%u\n", ptr[2].sz);
- for(int i=0; i < ptr[2].sz; i++)
+ for(int i=0; i < (int)ptr[2].sz; i++)
printf ("H'%.8X ",ptr[2].p[i]);
printf("\n");
#endif
@@ -871,6 +875,7 @@ int
NdbGlobalEventBuffer::real_prepareAddSubscribeEvent
(NdbGlobalEventBufferHandle *aHandle, Uint32 eventId, int& hasSubscriber)
{
+ DBUG_ENTER("NdbGlobalEventBuffer::real_prepareAddSubscribeEvent");
int i;
int bufferId = -1;
@@ -900,7 +905,10 @@ NdbGlobalEventBuffer::real_prepareAddSubscribeEvent
} else {
ndbout_c("prepareAddSubscribeEvent: Can't accept more subscribers");
// add_drop_unlock();
- return -1;
+ DBUG_PRINT("error",("Can't accept more subscribers:"
+ " bufferId=%d, m_no=%d, m_max=%d",
+ bufferId, m_no, m_max));
+ DBUG_RETURN(-1);
}
}
@@ -976,7 +984,7 @@ NdbGlobalEventBuffer::real_prepareAddSubscribeEvent
/* we now have a lock on the prepare so that no one can mess with this
* unlock comes in unprepareAddSubscribeEvent or addSubscribeEvent
*/
- return bufferId;
+ DBUG_RETURN(bufferId);
}
void
diff --git a/ndb/src/ndbapi/NdbEventOperationImpl.hpp b/ndb/src/ndbapi/NdbEventOperationImpl.hpp
index f67c998e639..fae9dda45e4 100644
--- a/ndb/src/ndbapi/NdbEventOperationImpl.hpp
+++ b/ndb/src/ndbapi/NdbEventOperationImpl.hpp
@@ -14,21 +14,13 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-/*****************************************************************************
- * Name: NdbEventOperationImpl.hpp
- * Include:
- * Link:
- * Author: Tomas Ulin MySQL AB
- * Date: 2003-11-21
- * Version: 0.1
- * Description: Event support
- * Documentation:
- * Adjust: 2003-11-21 Tomas Ulin First version.
- ****************************************************************************/
-
#ifndef NdbEventOperationImpl_H
#define NdbEventOperationImpl_H
+#include <NdbEventOperation.hpp>
+#include <signaldata/SumaImpl.hpp>
+#include <transporter/TransporterDefinitions.hpp>
+
class NdbGlobalEventBufferHandle;
class NdbEventOperationImpl : public NdbEventOperation {
public:
@@ -61,6 +53,9 @@ public:
void print();
void printAll();
+ const NdbError & getNdbError() const;
+ NdbError m_error;
+
Ndb *m_ndb;
NdbEventImpl *m_eventImpl;
NdbGlobalEventBufferHandle *m_bufferHandle;
diff --git a/ndb/src/ndbapi/Ndberr.cpp b/ndb/src/ndbapi/Ndberr.cpp
index 07f33d3e8b3..b05818de6f1 100644
--- a/ndb/src/ndbapi/Ndberr.cpp
+++ b/ndb/src/ndbapi/Ndberr.cpp
@@ -21,7 +21,7 @@
#include <NdbOperation.hpp>
#include <NdbTransaction.hpp>
#include <NdbBlob.hpp>
-
+#include "NdbEventOperationImpl.hpp"
static void
update(const NdbError & _err){
@@ -73,3 +73,10 @@ NdbBlob::getNdbError() const {
update(theError);
return theError;
}
+
+const
+NdbError &
+NdbEventOperationImpl::getNdbError() const {
+ update(m_error);
+ return m_error;
+}
diff --git a/ndb/src/ndbapi/ndberror.c b/ndb/src/ndbapi/ndberror.c
index d1e3b5efa2e..e14ed52640c 100644
--- a/ndb/src/ndbapi/ndberror.c
+++ b/ndb/src/ndbapi/ndberror.c
@@ -303,7 +303,8 @@ ErrorBundle ErrorCodes[] = {
{ 4707, AE, "Too many event have been defined"},
{ 4708, AE, "Event name is too long"},
- { 4709, AE, "Event already exists"},
+ { 4709, AE, "Can't accept more subscribers"},
+ { NDBERR_EVENT_NAME_ALEADY_EXISTS, AE, "Event name already exists"},
{ 4710, AE, "Event not found"},
{ 4711, AE, "Creation of event failed"},
diff --git a/ndb/test/ndbapi/test_event.cpp b/ndb/test/ndbapi/test_event.cpp
index cb2793e42b9..567cd1581f5 100644
--- a/ndb/test/ndbapi/test_event.cpp
+++ b/ndb/test/ndbapi/test_event.cpp
@@ -32,6 +32,46 @@ int runCreateEvent(NDBT_Context* ctx, NDBT_Step* step)
return NDBT_OK;
}
+int runCreateDropEventOperation(NDBT_Context* ctx, NDBT_Step* step)
+{
+ int loops = ctx->getNumLoops();
+ int records = ctx->getNumRecords();
+ HugoTransactions hugoTrans(*ctx->getTab());
+ EventOperationStats stats;
+
+ Ndb *pNdb=GETNDB(step);
+ const NdbDictionary::Table& tab= *ctx->getTab();
+ NdbEventOperation *pOp;
+ char eventName[1024];
+ sprintf(eventName,"%s_EVENT",tab.getName());
+ int noEventColumnName = tab.getNoOfColumns();
+
+ for (int i= 0; i < loops; i++)
+ {
+#if 1
+ if (hugoTrans.eventOperation(GETNDB(step), (void*)&stats, 0) != 0){
+ return NDBT_FAILED;
+ }
+#else
+ g_info << "create EventOperation\n";
+ pOp = pNdb->createEventOperation(eventName, 100);
+ if ( pOp == NULL ) {
+ g_err << "Event operation creation failed\n";
+ return NDBT_FAILED;
+ }
+
+ g_info << "dropping event operation" << endl;
+ int res = pNdb->dropEventOperation(pOp);
+ if (res != 0) {
+ g_err << "operation execution failed\n";
+ return NDBT_FAILED;
+ }
+#endif
+ }
+
+ return NDBT_OK;
+}
+
int theThreadIdCounter = 0;
int runEventOperation(NDBT_Context* ctx, NDBT_Step* step)
@@ -122,6 +162,13 @@ TESTCASE("BasicEventOperation",
STEP(runEventLoad);
FINALIZER(runDropEvent);
}
+TESTCASE("CreateDropEventOperation",
+ "Verify that we can Create and Drop many times"
+ "NOTE! No errors are allowed!" ){
+ INITIALIZER(runCreateEvent);
+ STEP(runCreateDropEventOperation);
+ FINALIZER(runDropEvent);
+}
NDBT_TESTSUITE_END(test_event);
#if 0
diff --git a/ndb/test/src/HugoTransactions.cpp b/ndb/test/src/HugoTransactions.cpp
index d9207386bf0..b76ac088793 100644
--- a/ndb/test/src/HugoTransactions.cpp
+++ b/ndb/test/src/HugoTransactions.cpp
@@ -826,6 +826,7 @@ struct receivedEvent {
};
int XXXXX = 0;
+
int
HugoTransactions::eventOperation(Ndb* pNdb, void* pstats,
int records) {
@@ -896,7 +897,9 @@ HugoTransactions::eventOperation(Ndb* pNdb, void* pstats,
// set up the callbacks
g_info << function << "execute\n";
if (pOp->execute()) { // This starts changes to "start flowing"
- g_err << function << "operation execution failed\n";
+ g_err << function << "operation execution failed: \n";
+ g_err << pOp->getNdbError().code << " "
+ << pOp->getNdbError().message << endl;
return NDBT_FAILED;
}
diff --git a/ndb/test/src/NDBT_Test.cpp b/ndb/test/src/NDBT_Test.cpp
index d86cfbf3c70..45ee172811a 100644
--- a/ndb/test/src/NDBT_Test.cpp
+++ b/ndb/test/src/NDBT_Test.cpp
@@ -15,6 +15,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
+#include <my_pthread.h>
#include "NDBT.hpp"
#include "NDBT_Test.hpp"
@@ -476,7 +477,9 @@ extern "C"
void *
runStep_C(void * s)
{
+ my_thread_init();
runStep(s);
+ my_thread_end();
NdbThread_Exit(0);
return NULL;
}