mirror of
https://github.com/MariaDB/server.git
synced 2025-08-31 22:22:30 +03:00
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
This commit is contained in:
@@ -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());
|
||||
|
@@ -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,
|
||||
|
@@ -199,6 +199,13 @@ public:
|
||||
*/
|
||||
Uint32 getLatestGCI();
|
||||
|
||||
/**
|
||||
* Get the latest error
|
||||
*
|
||||
* @return Error object.
|
||||
*/
|
||||
const struct NdbError & getNdbError() const;
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
|
||||
/*
|
||||
*
|
||||
|
@@ -17,6 +17,8 @@
|
||||
#ifndef NDBERROR_H
|
||||
#define NDBERROR_H
|
||||
|
||||
#define NDBERR_EVENT_NAME_ALEADY_EXISTS 746
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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"},
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user