[svn:dbd-oracle] r15187 - dbd-oracle/branches/FAN

[email protected] Mon, 27 Feb 2012 10:28:47 -0800 (PST)
Newsgroups perl.dbd.oracle.changes
Message-ID <[email protected]>
Author: byterock
Date: Mon Feb 27 10:28:46 2012
New Revision: 15187

Modified:
   dbd-oracle/branches/FAN/oci8.c

Log:
revert to working copy 

Modified: dbd-oracle/branches/FAN/oci8.c
==============================================================================
--- dbd-oracle/branches/FAN/oci8.c	(original)
+++ dbd-oracle/branches/FAN/oci8.c	Mon Feb 27 10:28:46 2012
@@ -1299,127 +1299,130 @@
 
 }
 
-/* HA or High Availabilty callback also called FAN Fast Application Notification */
+void
+hacb_fn( dvoid *ha_ctx, OCIEvent *eventhp) {
 
-/*  Works with Oracle clusters (you have to have at least two) when an event happens on a cluster */
-/*  node it sends out notifications to the other nodes so they know what to do.  Normlly this is */
-/*  all handled behide the sceans and the cluster software does it for you.  With this callback */
-/*  you can reviecve these events with the caviate that you cannot do alot with them as any load balancing,*/
-/*  connection pools, etc as the are handled by the node software at the same time.*/
-/*  Anyway the callback will return an array of hashes that contain all the event data. */
+ ha_context_t *ctx =(ha_context_t*)ha_ctx;
+   OCIServer *srvhp;
+   dTHXa(ctx->ct_perl);
+   dSP;
+   imp_dbh_t  *imp_dbh = (imp_dbh_t*)ctx->imp_dbh;
+   sword status;
+   text *event_att;
+   OCIDateTime *event_ts;
+   OraText tsbuff[50];
+   ub4 event_att_len;
+   ub4 event_code;
+   HV* ha_event;
+   AV* servers;
+   PERL_SET_CONTEXT(ctx->ct_perl);
+   ha_event  = newHV();
+   servers  = newAV();
+   PUSHMARK(SP);
 
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_code, 0, OCI_ATTR_HA_SOURCE, imp_dbh->errhp, status);
 
+   hv_store(ha_event,"Source",6,sv_2mortal(newSVpv(oci_ha_event_source(event_code),strlen(oci_ha_event_source(event_code)))),0);
 
-void
-ha_cbk( dvoid *ha_ctx, OCIEvent *eventhp) {
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_code, 0, OCI_ATTR_HA_STATUS, imp_dbh->errhp, status);
 
-	ha_ctx_t *ctx =(ha_ctx_t*)ha_ctx;
-	OCIServer *srvhp;
-	dTHXa(ctx->ctx_perl);
-	dSP;
-	imp_dbh_t  *imp_dbh = (imp_dbh_t*)ctx->imp_dbh;
-	sword status;
-	text *event_att;
-	OCIDateTime *event_ts;
-	OraText ts_buff[50];
-	ub4 event_att_len;
-	ub4 event_code;
-	HV* ha_event;
-	AV* servers;
-	PERL_SET_CONTEXT(ctx->ctx_perl);
-	ha_event = newHV();
-	servers  = newAV();
-	PUSHMARK(SP);
 
 
-	OCIAttrGet_log_stat(eventhp, OCI_HTYPE_EVENT, (dvoid *)&event_code, 0, OCI_ATTR_HA_SOURCE, imp_dbh->errhp, status);
+   if (event_code == OCI_HA_STATUS_UP){
+   	hv_store(ha_event,"Status",6,sv_2mortal(newSVpv("UP",2)),0);
 
-	hv_store(ha_event,"HA_Source",9,sv_2mortal(newSVpv(oci_ha_event_source(event_code),strlen(oci_ha_event_source(event_code)))),0);
+   }
+   else {
+ 	hv_store(ha_event,"Status",6,sv_2mortal(newSVpv("DOWN",4)),0);
+   }
 
-	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_code, 0, OCI_ATTR_HA_STATUS, imp_dbh->errhp, status);
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_DBDOMAIN, imp_dbh->errhp, status);
 
-	if (event_code == OCI_HA_STATUS_UP){
-		hv_store(ha_event,"HA_Status",9,sv_2mortal(newSVpv("UP",2)),0);
-	}
-	else {
-		hv_store(ha_event,"HA_Status",9,sv_2mortal(newSVpv("DOWN",4)),0);
-	}
+    hv_store(ha_event,"Domain",6,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
 
-	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_DBDOMAIN, imp_dbh->errhp, status);
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_DBNAME, imp_dbh->errhp, status);
 
-	hv_store(ha_event,"DB_Domain",9,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
+   hv_store(ha_event,"Name",5,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
 
-	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_DBNAME, imp_dbh->errhp, status);
 
-	hv_store(ha_event,"DB_Name",7,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_HOSTNAME, imp_dbh->errhp, status);
 
-	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_HOSTNAME, imp_dbh->errhp, status);
+   hv_store(ha_event,"Host",4,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
 
-	hv_store(ha_event,"Host_Name",9,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_INSTNAME, imp_dbh->errhp, status);
 
-	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_INSTNAME, imp_dbh->errhp, status);
+   hv_store(ha_event,"Instance",8,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
 
-	hv_store(ha_event,"Instance_Name",13,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
 
-	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_SERVICENAME, imp_dbh->errhp, status);
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_SERVICENAME, imp_dbh->errhp, status);
 
-	hv_store(ha_event,"Service_Name",12,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
+   hv_store(ha_event,"Service",7,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
 
-	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_ts,0, OCI_ATTR_HA_TIMESTAMP, imp_dbh->errhp, status);
 
-	OCIDateTimeToText_log_stat(eventhp,imp_dbh->errhp,event_ts,&event_att_len,ts_buff,status);
 
-	hv_store(ha_event,"Time_Stamp",10,sv_2mortal(newSVpv((char*)ts_buff,event_att_len)),0);
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_ts,0, OCI_ATTR_HA_TIMESTAMP, imp_dbh->errhp, status);
 
-	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&srvhp,0, OCI_ATTR_HA_SRVFIRST, imp_dbh->errhp, status);
 
-	OCIAttrGet_log_stat(srvhp,  OCI_HTYPE_SERVER, (dvoid *)&event_att,&event_att_len, OCI_ATTR_INSTNAME, imp_dbh->errhp, status);
+   OCIDateTimeToText(imp_dbh->envhp,imp_dbh->errhp, event_ts, (char*) "MM-DD-YY HH24:MI:SS",
+ 		    strlen("MM-DD-YY HH24:MI:SS"),
+ 		    (ub1)4, (OraText *)0, 0,&event_att_len, tsbuff);
 
-	av_push(servers, newSVpv( (char *) event_att,0));
+   hv_store(ha_event,"Timestamp",9,sv_2mortal(newSVpv((char*)tsbuff,event_att_len)),0);
 
-	while(status){
 
-		OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&srvhp,0, OCI_ATTR_HA_SRVNEXT, imp_dbh->errhp, status);
-		if (status == OCI_NO_DATA) {
-			break;
-		}
-		else {
 
-			OCIAttrGet_log_stat(srvhp,  OCI_HTYPE_SERVER, (dvoid *)&event_att,&event_att_len, OCI_ATTR_INSTNAME, imp_dbh->errhp, status);
-			av_push(servers, newSVpv( (char *) event_att,0));
-		}
-	}
+   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&srvhp,0, OCI_ATTR_HA_SRVFIRST, imp_dbh->errhp, status);
 
-	hv_store(ha_event,"Instances",9,newRV_noinc((SV*)servers),0);
-	XPUSHs(sv_2mortal(newRV((SV*)ha_event)));
-	PUTBACK;
-	call_pv(ctx->function, G_DISCARD);
 
+
+   OCIAttrGet_log_stat(srvhp,  OCI_HTYPE_SERVER, (dvoid *)&event_att,&event_att_len, OCI_ATTR_INSTNAME, imp_dbh->errhp, status);
+
+
+   av_push(servers, newSVpv( (char *) event_att,0));
+
+
+
+
+  while(status){
+
+     OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&srvhp,0, OCI_ATTR_HA_SRVNEXT, imp_dbh->errhp, status);
+     if (status == OCI_NO_DATA) {
+          break;
+     }
+     else {
+
+      OCIAttrGet_log_stat(srvhp,  OCI_HTYPE_SERVER, (dvoid *)&event_att,&event_att_len, OCI_ATTR_INSTNAME, imp_dbh->errhp, status);
+      av_push(servers, newSVpv( (char *) event_att,0));
+
+    }
+  }
+
+   hv_store(ha_event,"Instances",9,newRV_noinc((SV*)servers),0);
+   XPUSHs(sv_2mortal(newRV((SV*)ha_event)));
+   PUTBACK;
+   call_pv(ctx->function, G_DISCARD);
 }
 
-/*   HA or High Availabilty Callback */
-/*   Works like this.  The fuction below is registered on the cluster,*/
-/*   when a node on a cluster goes up or down then messages are popiegated */
-/*   to the other nodes on the cluster.  Used for loadbalancing are reconnecting. */
-/*   Not very useful to perl as you cannot do much but monitor events as this */
-/*   is usisng threaded perl and you go not have a DB handle to play with */
 
 sb4
-reg_ha_callback( imp_dbh_t *imp_dbh){
-	dTHX;
-	sword status;
-	ha_ctx_t  *ctx = NULL;
-	Newz(1, ctx, 1, ha_ctx_t);
-	ctx->function = (char*)safemalloc(strlen(imp_dbh->ha_function));
-	ctx->ctx_perl = my_perl;
-	ctx->imp_dbh  = imp_dbh;
+reg_ha_callback( imp_dbh_t *imp_dbh)
+{
+        dTHX;
+        sword status;
+        ha_context_t  *ctx = NULL;
+/*allocate space for the callback */
+        Newz(1, ctx, 1, ha_context_t);
+        ctx->function= (char*)safemalloc(strlen(imp_dbh->ha_function));
+        ctx->ct_perl   = my_perl;
+        ctx->imp_dbh   = imp_dbh;
+        strcpy((char *)ctx->function,imp_dbh->ha_function);
 
-	if (dbd_verbose >= 5 ) {
-		PerlIO_printf(DBILOGFP, " Register HA callback %s\n",imp_dbh->ha_function);
-	}
+ PerlIO_printf(DBILOGFP, " In reg_ha_callback reg OCI_ATTR_FOCBK =%d, OCI_ATTR_EVTCTX=%d\n",OCI_ATTR_EVTCBK,OCI_ATTR_EVTCTX);
+
+         OCIAttrSet_log_stat(imp_dbh->envhp, (ub4) OCI_HTYPE_ENV,(dvoid *)hacb_fn ,(ub4)0,(ub4)OCI_ATTR_EVTCBK, imp_dbh->errhp, status);
 
-	OCIAttrSet_log_stat(imp_dbh->envhp, (ub4) OCI_HTYPE_ENV,(dvoid *)ha_cbk ,(ub4)0,(ub4)OCI_ATTR_EVTCBK, imp_dbh->errhp, status);
-	OCIAttrSet_log_stat(imp_dbh->envhp, OCI_HTYPE_ENV,ctx,0,OCI_ATTR_EVTCTX, imp_dbh->errhp , status);
+        OCIAttrSet_log_stat(imp_dbh->envhp, OCI_HTYPE_ENV,ctx,0,OCI_ATTR_EVTCTX, imp_dbh->errhp , status);
+PerlIO_printf(DBILOGFP, " In reg_ha_callback reg OCI_ATTR_EVTCX status=%d\n",status);
 
 	return status;
 }