List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:November 19 2007 9:35am
Subject:Rev 263: Getting log events works now. It's not pretty... but it does work. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel

------------------------------------------------------------
revno: 263
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Mon 2007-11-19 01:34:49 -0800
message:
  Getting log events works now. It's not pretty... but it does work.
added:
  java/com/mysql/cluster/mgmj/examples/ examples-20071119093428-2f2zw02dpk5jlq9f-1
  java/com/mysql/cluster/mgmj/examples/SampleMGMJ.java
samplemgmj.java-20071119093428-2f2zw02dpk5jlq9f-2
modified:
  interface/mgmapi/NdbLogEvent.i ndblogevent.i-20070906065931-8drgzkovsy4cdn0b-1
  interface/mgmapi/NdbLogEventManager.i
ndbmgmlogeventhandle-20070906065939-pj4qrhof8kkzg3d1-1
  interface/mgmapi/NdbMgm.i      ndbmgm.i-20070528224404-qscgbkcvhcru9u2o-4
  interface/mgmapi/mgmglobals.i  mgm.i-20070228021421-qkr4cbpxymyqdrf3-8
  java/mgmj.i                    mgmapi.i-20070415064013-80k9rsqzumm2kjaf-1
=== added directory 'java/com/mysql/cluster/mgmj/examples'
=== added file 'java/com/mysql/cluster/mgmj/examples/SampleMGMJ.java'
--- a/java/com/mysql/cluster/mgmj/examples/SampleMGMJ.java	1970-01-01 00:00:00 +0000
+++ b/java/com/mysql/cluster/mgmj/examples/SampleMGMJ.java	2007-11-19 09:34:49 +0000
@@ -0,0 +1,52 @@
+package com.mysql.cluster.mgmj.examples;
+
+import com.mysql.cluster.mgmj.*;
+
+public class SampleMGMJ {
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) throws MgmApiException {
+
+		NdbMgm mgm = NdbMgmFactory.createNdbMgm("localhost");
+
+		mgm.setConnectTimeout(4000);
+		mgm.connect(5, 3, true);
+		int[] filter = { 15, NdbMgmEventCategory.NDB_MGM_EVENT_CATEGORY_STATISTIC.swigValue(),
0 };
+		NdbFilterList theList = new NdbFilterList();
+		NdbFilterItem theItem = new NdbFilterItem();
+		theItem.setLevel(15);
+		theItem.setCategory(NdbMgmEventCategory.NDB_MGM_EVENT_CATEGORY_STATISTIC);
+		theList.add(theItem);
+		NdbLogEventManager manager = mgm.createNdbLogEventManager(theList);
+
+		while(true) { 	
+			//mgm.dumpState(1, 1000);
+			BaseEvent event = manager.getLogEvent(5000);
+			if (event != null)  {
+				System.out.println("Got an Event from Node" + event.getSourceNodeId()+" 
"+event.getType());
+			if (event.getType() == NdbLogEventType.NDB_LE_TransReportCounters) {
+				TransReportCountersEvent theEvent = new TransReportCountersEvent(event.getEvent());
+				System.out.println("Trans count:"+theEvent.getTransCount());
+				System.out.println("Read count:"+theEvent.getReadCount());
+				System.out.println("Scan count:"+theEvent.getScanCount());
+				System.out.println("Range Scan count:"+theEvent.getRangeScanCount());
+			} else if (event.getType() == NdbLogEventType.NDB_LE_MemoryUsage) { 
+				MemoryUsageEvent theEvent = new MemoryUsageEvent(event.getEvent()); 
+				if (theEvent.getPageSizeKb() == 8192) { 
+					//System.out.println("Index Memory: "+theEvent.getPagesUsed());
+				} else if (theEvent.getPageSizeKb() == 32768) { 
+					//System.out.println("Data Memory: "+theEvent.getPagesUsed());
+				}
+				
+
+			}
+			} else { 
+				//System.out.println("Still null");
+			}
+		}
+
+	}
+
+}

=== modified file 'interface/mgmapi/NdbLogEvent.i'
--- a/interface/mgmapi/NdbLogEvent.i	2007-11-18 01:00:39 +0000
+++ b/interface/mgmapi/NdbLogEvent.i	2007-11-19 09:34:49 +0000
@@ -86,8 +86,20 @@
 
   class BaseEvent { 
   protected: 
-    BaseEvent(); 
+    BaseEvent()  { 
+//      event=NULL; 
+    }
+  public: 
     ndb_logevent event; 
+    BaseEvent(ndb_logevent theEvent) { 
+      event=theEvent;
+    } 
+    Ndb_logevent_type getType() { 
+      return event.type;
+    }
+    int getSourceNodeId() { 
+      return event.source_nodeid;
+    }
   };
 
 
@@ -893,13 +905,13 @@
   class SingleUserEvent : public BaseEvent { 
   public: 
 
-    unsigned type;
+    unsigned eventType;
     unsigned nodeId;
     SingleUserEvent(ndb_logevent theEvent) {
       event=theEvent;
 
 
-      type=event.SingleUser.type;
+      eventType=event.SingleUser.type;
       nodeId=event.SingleUser.node_id;
     }
 

=== modified file 'interface/mgmapi/NdbLogEventManager.i'
--- a/interface/mgmapi/NdbLogEventManager.i	2007-11-18 01:00:39 +0000
+++ b/interface/mgmapi/NdbLogEventManager.i	2007-11-19 09:34:49 +0000
@@ -57,6 +57,10 @@
       this->handle=theHandle;
     }
     
+    const char * getMgmError() { 
+      return ndb_logevent_get_latest_error_msg(this->handle); 
+    }
+
     // Returns -1 on error, 0 otherwise
     int registerListener(NdbLogEventTypeListener * listener) { 
       Ndb_logevent_type theType = listener->getEventType();
@@ -118,9 +122,279 @@
       if (eventWrapper->ret > 0) { 
 	
 	switch(event.type) { 
+
 	case NDB_LE_Connected:
 	  eventWrapper->theEvent = (BaseEvent *)(new ConnectedEvent(event));
 	  break;
+
+	case NDB_LE_Disconnected:
+	  eventWrapper->theEvent = (BaseEvent *)(new DisconnectedEvent(event));
+	  break;
+
+	case NDB_LE_CommunicationClosed:
+	  eventWrapper->theEvent = (BaseEvent *)(new CommunicationClosedEvent(event));
+	  break;
+
+	case NDB_LE_CommunicationOpened:
+	  eventWrapper->theEvent = (BaseEvent *)(new CommunicationOpenedEvent(event));
+	  break;
+
+	case NDB_LE_ConnectedApiVersion:
+	  eventWrapper->theEvent = (BaseEvent *)(new ConnectedApiVersionEvent(event));
+	  break;
+
+	case NDB_LE_GlobalCheckpointStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new GlobalCheckpointStartedEvent(event));
+	  break;
+
+	case NDB_LE_GlobalCheckpointCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new GlobalCheckpointCompletedEvent(event));
+	  break;
+
+	case NDB_LE_LocalCheckpointStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new LocalCheckpointStartedEvent(event));
+	  break;
+
+	case NDB_LE_LocalCheckpointCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new LocalCheckpointCompletedEvent(event));
+	  break;
+
+	case NDB_LE_LCPStoppedInCalcKeepGci:
+	  eventWrapper->theEvent = (BaseEvent *)(new LCPStoppedInCalcKeepGciEvent(event));
+	  break;
+
+	case NDB_LE_LCPFragmentCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new LCPFragmentCompletedEvent(event));
+	  break;
+
+	case NDB_LE_NDBStartStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new NDBStartStartedEvent(event));
+	  break;
+
+	case NDB_LE_NDBStartCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new NDBStartCompletedEvent(event));
+	  break;
+
+	case NDB_LE_STTORRYRecieved:
+	  eventWrapper->theEvent = (BaseEvent *)(new STTORRYRecievedEvent(event));
+	  break;
+
+	case NDB_LE_StartPhaseCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new StartPhaseCompletedEvent(event));
+	  break;
+
+	case NDB_LE_CM_REGCONF:
+	  eventWrapper->theEvent = (BaseEvent *)(new CmRegConfEvent(event));
+	  break;
+
+	case NDB_LE_CM_REGREF:
+	  eventWrapper->theEvent = (BaseEvent *)(new CmRegRefEvent(event));
+	  break;
+
+	case NDB_LE_FIND_NEIGHBOURS:
+	  eventWrapper->theEvent = (BaseEvent *)(new FindNeighboursEvent(event));
+	  break;
+
+	case NDB_LE_NDBStopStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new NDBStopStartedEvent(event));
+	  break;
+
+	case NDB_LE_NDBStopCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new NDBStopCompletedEvent(event));
+	  break;
+
+	case NDB_LE_NDBStopForced:
+	  eventWrapper->theEvent = (BaseEvent *)(new NDBStopForcedEvent(event));
+	  break;
+
+	case NDB_LE_NDBStopAborted:
+	  eventWrapper->theEvent = (BaseEvent *)(new NDBStopAbortedEvent(event));
+	  break;
+
+	case NDB_LE_StartREDOLog:
+	  eventWrapper->theEvent = (BaseEvent *)(new StartREDOLogEvent(event));
+	  break;
+
+	case NDB_LE_StartLog:
+	  eventWrapper->theEvent = (BaseEvent *)(new StartLogEvent(event));
+	  break;
+
+	case NDB_LE_UNDORecordsExecuted:
+	  eventWrapper->theEvent = (BaseEvent *)(new UNDORecordsExecutedEvent(event));
+	  break;
+
+	case NDB_LE_NR_CopyDict:
+	  eventWrapper->theEvent = (BaseEvent *)(new NRCopyDictEvent(event));
+	  break;
+
+	case NDB_LE_NR_CopyDistr:
+	  eventWrapper->theEvent = (BaseEvent *)(new NRCopyDistrEvent(event));
+	  break;
+
+	case NDB_LE_NR_CopyFragsStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new NRCopyFragsStartedEvent(event));
+	  break;
+
+	case NDB_LE_NR_CopyFragDone:
+	  eventWrapper->theEvent = (BaseEvent *)(new NRCopyFragDoneEvent(event));
+	  break;
+
+	case NDB_LE_NR_CopyFragsCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new NRCopyFragsCompletedEvent(event));
+	  break;
+
+	case NDB_LE_NodeFailCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new NodeFailCompletedEvent(event));
+	  break;
+
+	case NDB_LE_NODE_FAILREP:
+	  eventWrapper->theEvent = (BaseEvent *)(new NodeFAILREPEvent(event));
+	  break;
+
+	case NDB_LE_ArbitState:
+	  eventWrapper->theEvent = (BaseEvent *)(new ArbitStateEvent(event));
+	  break;
+
+	case NDB_LE_ArbitResult:
+	  eventWrapper->theEvent = (BaseEvent *)(new ArbitResultEvent(event));
+	  break;
+
+	case NDB_LE_GCP_TakeoverStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new GCPTakeoverStartedEvent(event));
+	  break;
+
+	case NDB_LE_GCP_TakeoverCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new GCPTakeoverCompletedEvent(event));
+	  break;
+
+	case NDB_LE_LCP_TakeoverStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new LCPTakeoverStartedEvent(event));
+	  break;
+
+	case NDB_LE_LCP_TakeoverCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new LCPTakeoverCompletedEvent(event));
+	  break;
+
+	case NDB_LE_TransReportCounters:
+	  eventWrapper->theEvent = (BaseEvent *)(new TransReportCountersEvent(event));
+	  break;
+
+	case NDB_LE_OperationReportCounters:
+	  eventWrapper->theEvent = (BaseEvent *)(new OperationReportCountersEvent(event));
+	  break;
+
+	case NDB_LE_TableCreated:
+	  eventWrapper->theEvent = (BaseEvent *)(new TableCreatedEvent(event));
+	  break;
+
+	case NDB_LE_UndoLogBlocked:
+	  eventWrapper->theEvent = (BaseEvent *)(new UndoLogBlockedEvent(event));
+	  break;
+
+	case NDB_LE_JobStatistic:
+	  eventWrapper->theEvent = (BaseEvent *)(new JobStatisticEvent(event));
+	  break;
+
+	case NDB_LE_SendBytesStatistic:
+	  eventWrapper->theEvent = (BaseEvent *)(new SendBytesStatisticEvent(event));
+	  break;
+
+	case NDB_LE_ReceiveBytesStatistic:
+	  eventWrapper->theEvent = (BaseEvent *)(new ReceiveBytesStatisticEvent(event));
+	  break;
+
+	case NDB_LE_MemoryUsage:
+	  eventWrapper->theEvent = (BaseEvent *)(new MemoryUsageEvent(event));
+	  break;
+
+/*	case NDB_LE_ThreadConfigLoop:
+	  eventWrapper->theEvent = (BaseEvent *)(new ThreadConfigLoopEvent(event));
+	  break;
+*/
+	case NDB_LE_TransporterError:
+	  eventWrapper->theEvent = (BaseEvent *)(new TransporterErrorEvent(event));
+	  break;
+
+	case NDB_LE_TransporterWarning:
+	  eventWrapper->theEvent = (BaseEvent *)(new TransporterWarningEvent(event));
+	  break;
+
+	case NDB_LE_MissedHeartbeat:
+	  eventWrapper->theEvent = (BaseEvent *)(new MissedHeartbeatEvent(event));
+	  break;
+
+	case NDB_LE_DeadDueToHeartbeat:
+	  eventWrapper->theEvent = (BaseEvent *)(new DeadDueToHeartbeatEvent(event));
+	  break;
+
+	case NDB_LE_WarningEvent:
+	  eventWrapper->theEvent = (BaseEvent *)(new WarningEventEvent(event));
+	  break;
+
+	case NDB_LE_SentHeartbeat:
+	  eventWrapper->theEvent = (BaseEvent *)(new SentHeartbeatEvent(event));
+	  break;
+
+	case NDB_LE_CreateLogBytes:
+	  eventWrapper->theEvent = (BaseEvent *)(new CreateLogBytesEvent(event));
+	  break;
+
+	case NDB_LE_InfoEvent:
+	  eventWrapper->theEvent = (BaseEvent *)(new InfoEventEvent(event));
+	  break;
+
+	case NDB_LE_SingleUser:
+	  eventWrapper->theEvent = (BaseEvent *)(new SingleUserEvent(event));
+	  break;
+
+	case NDB_LE_BackupStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new BackupStartedEvent(event));
+	  break;
+
+	case NDB_LE_BackupFailedToStart:
+	  eventWrapper->theEvent = (BaseEvent *)(new BackupFailedToStartEvent(event));
+	  break;
+
+/*	case NDB_LE_BackupStatus:
+	  eventWrapper->theEvent = (BaseEvent *)(new BackupStatusEvent(event));
+	  break;
+*/
+	case NDB_LE_BackupCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new BackupCompletedEvent(event));
+	  break;
+
+	case NDB_LE_BackupAborted:
+	  eventWrapper->theEvent = (BaseEvent *)(new BackupAbortedEvent(event));
+	  break;
+
+/*	case NDB_LE_RestoreMetaData:
+	  eventWrapper->theEvent = (BaseEvent *)(new RestoreMetaDataEvent(event));
+	  break;
+*/
+/*	case NDB_LE_RestoreData:
+	  eventWrapper->theEvent = (BaseEvent *)(new RestoreDataEvent(event));
+	  break;
+*/
+/*	case NDB_LE_RestoreLog:
+	  eventWrapper->theEvent = (BaseEvent *)(new RestoreLogEvent(event));
+	  break;
+*/
+/*	case NDB_LE_RestoreStarted:
+	  eventWrapper->theEvent = (BaseEvent *)(new RestoreStartedEvent(event));
+	  break;
+*/
+/*	case NDB_LE_RestoreCompleted:
+	  eventWrapper->theEvent = (BaseEvent *)(new RestoreCompletedEvent(event));
+	  break;
+*/
+	case NDB_LE_EventBufferStatus:
+	  eventWrapper->theEvent = (BaseEvent *)(new EventBufferStatusEvent(event));
+	  break;
+
+	case NDB_LE_StartReport:
+	  eventWrapper->theEvent = (BaseEvent *)(new StartReportEvent(event));
+	  break;
+
 	default:
 	  break;
 	}
@@ -188,10 +462,11 @@
   int registerListener(NdbLogEventTypeListener * listener);   
   bool unregisterListener(NdbLogEventTypeListener * listener);
   int registerCategoryListener(NdbLogEventCategoryListener * listener);
+
   %ndbexception("MgmApiException") { 
     $action
       if (result->ret < 0) { 
-	NDB_exception(NdbApiException,"Error fetching ndb_logevent object!");
+	NDB_exception(NdbApiException,arg1->getMgmError());
       }
   }
   BaseEventWrapper * getLogEvent(unsigned timeout_in_milliseconds);

=== modified file 'interface/mgmapi/NdbMgm.i'
--- a/interface/mgmapi/NdbMgm.i	2007-11-06 22:59:00 +0000
+++ b/interface/mgmapi/NdbMgm.i	2007-11-19 09:34:49 +0000
@@ -22,6 +22,7 @@
    * The NdbMgmHandle.
    */
 %rename ndb_mgm_handle NdbMgm; 
+%typemap(freearg) (ndb_mgm_reply *) "free($1);";
 
 struct ndb_mgm_handle { 
 private: 
@@ -731,4 +732,45 @@
     return new NdbLogEventManager(ndb_mgm_create_logevent_handle($self,filter));
   }
 
+
+  %newobject dumpState;
+  %apply int *INOUT { const int * args };
+  ndb_mgm_reply * dumpState(int nodeId,
+			    const int * args,
+			    int num_args) {
+    ndb_mgm_reply * reply = (ndb_mgm_reply *)malloc(sizeof(ndb_mgm_reply));
+    if (reply == NULL) { 
+      return NULL;
+    }
+    int ret = ndb_mgm_dump_state($self,nodeId,args,num_args,reply);
+    if (ret == -1) {
+      free(reply);
+      return NULL;
+    }
+    return reply;
+    
+  }
+
+  %ndbexception("MgmApiException") {
+    $action
+      if (result < 0) { 
+	//int errCode = ndb_mgm_get_latest_error(arg1);
+        const char * errMsg = ndb_mgm_get_latest_error_msg(arg1);
+        NDB_exception(MgmApiException,errMsg);
+      }
+  }
+  
+  int dumpState(int nodeId, int theState) { 
+    ndb_mgm_reply * reply = (ndb_mgm_reply *)malloc(sizeof(ndb_mgm_reply));
+    if (reply == NULL) { 
+      return -1;
+    }
+    int theArgs[1]; 
+    theArgs[0]=theState;
+    int ret = ndb_mgm_dump_state($self,nodeId,theArgs,1,reply);
+    free(reply);
+    return ret;
+  }
+
+  %ndbnoexception;
 };

=== modified file 'interface/mgmapi/mgmglobals.i'
--- a/interface/mgmapi/mgmglobals.i	2007-11-06 22:59:00 +0000
+++ b/interface/mgmapi/mgmglobals.i	2007-11-19 09:34:49 +0000
@@ -27,6 +27,7 @@
 
 #include "ndb_init.h"
 #include "mgmapi.h"
+#include "mgmapi_debug.h"
 
 %}
 

=== modified file 'java/mgmj.i'
--- a/java/mgmj.i	2007-11-18 01:00:39 +0000
+++ b/java/mgmj.i	2007-11-19 09:34:49 +0000
@@ -68,6 +68,19 @@
 %include "mgmapi/NdbLogEvent.i"
 %include "mgmapi/NdbLogEventManager.i"
 %include "mgmapi/NdbMgm.i"
+%typemap(javacode) NdbMgmFactory %{ 
+
+  static {
+    try {
+      System.loadLibrary("mgmj");
+    } catch (UnsatisfiedLinkError e) {
+      System.err.println("Native code library failed to load. \n" + e);
+      System.exit(1);
+    }
+    mgmj.ndb_init();
+  }
+
+ %}
 %include "mgmapi/NdbMgmFactory.i"
 %include "mgmapi/ClusterState.i"
 %include "mgmapi/NodeState.i"

Thread
Rev 263: Getting log events works now. It's not pretty... but it does work. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/develMonty Taylor19 Nov