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

[email protected] Thu, 23 Feb 2012 05:05:53 -0800 (PST)
Newsgroups perl.dbd.oracle.changes
Message-ID <[email protected]>
Author: byterock
Date: Thu Feb 23 05:05:52 2012
New Revision: 15172

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

Log:
Cleaning up the code

Modified: dbd-oracle/branches/FAN/dbdimp.c
==============================================================================
--- dbd-oracle/branches/FAN/dbdimp.c	(original)
+++ dbd-oracle/branches/FAN/dbdimp.c	Thu Feb 23 05:05:52 2012
@@ -938,22 +938,20 @@
 #ifdef ORA_OCI_112
 	/* set up HA evnets callback if requested */
 
-         if (imp_dbh->using_ha){
+	if (imp_dbh->using_ha){
 
-                if (DBIS->debug >= 4 || dbd_verbose >= 4 ) {
-                	PerlIO_printf(DBILOGFP,"Setting up HA Event Callback!");
-                }
+		if (DBIS->debug >= 4 || dbd_verbose >= 4 ) {
+			PerlIO_printf(DBILOGFP,"Setting up HA Event Callback!");
+		}
 
-                status = reg_ha_callback(imp_dbh);
+		status = reg_ha_callback(imp_dbh);
 
-                if (status != OCI_SUCCESS) {
-                        oci_error(dbh, NULL, status,
-                                "Setting HA Event Callback Failed! ");
-                        return 0;
-                }
-        }
+		if (status != OCI_SUCCESS) {
+			oci_error(dbh, NULL, status,"Setting HA Event Callback Failed! ");
+			return 0;
+		}
+	}
 
-dbd_verbose =0;
 #endif /* ORA_OCI_112 */
 	return 1;
 }

Modified: dbd-oracle/branches/FAN/dbdimp.h
==============================================================================
--- dbd-oracle/branches/FAN/dbdimp.h	(original)
+++ dbd-oracle/branches/FAN/dbdimp.h	Thu Feb 23 05:05:52 2012
@@ -58,8 +58,8 @@
 	OCISession	*seshp;
 #ifdef ORA_OCI_112
 	OCIAuthInfo *authp;
-	OCISPool    *poolhp;
-	text        *pool_name;
+	OCISPool	*poolhp;
+	text		*pool_name;
 	ub4			pool_namel;
 	bool		using_drcp;
 	text		*pool_class;
@@ -69,29 +69,28 @@
 	ub4			pool_incr;
 	char		*driver_name;/*driver name user defined*/
 	ub4			driver_namel;
-        bool            using_ha;   
-        char	        *ha_function;
+	bool		using_ha; /*HA events */
+	char		*ha_function; /*HA function */
 #endif
-	taf_callback_t  *taf_callback;
 	bool		using_taf; /*TAF stuff*/
-    char		*taf_function; /*User supplied TAF functiomn*/
-    int			taf_sleep;
-    char		*client_info;  /*user defined*/
-    ub4			client_infol;
+	char		*taf_function; /*User supplied TAF function*/
+	int			taf_sleep;
+	char		*client_info;  /*user defined*/
+	ub4			client_infol;
 	char		*module_name; /*module user defined */
 	ub4			module_namel;
 	char		*client_identifier;  /*user defined*/
-    ub4			client_identifierl;
-    char		*action;  /*user defined*/
-    ub4			actionl;
-	int RowCacheSize; /* both of these are defined by DBI spec*/
-	int RowsInCache;	/* this vaue is RO and cannot be set*/
-	int ph_type;		/* default oratype for placeholders */
-	ub1 ph_csform;		/* default charset for placeholders */
-	int parse_error_offset;	/* position in statement of last error */
-	int max_nested_cursors;	 /* limit on cached nested cursors per stmt */
-	int array_chunk_size;  /* the max size for an array bind */
-    ub4 server_version; /* version of Oracle server */
+	ub4			client_identifierl;
+	char		*action;  /*user defined*/
+	ub4			actionl;
+	int			RowCacheSize; /* both of these are defined by DBI spec*/
+	int			RowsInCache;	/* this vaue is RO and cannot be set*/
+	int			ph_type;		/* default oratype for placeholders */
+	ub1			ph_csform;		/* default charset for placeholders */
+	int			parse_error_offset;	/* position in statement of last error */
+	int			max_nested_cursors;	 /* limit on cached nested cursors per stmt */
+	int			array_chunk_size;  /* the max size for an array bind */
+	ub4			server_version; /* version of Oracle server */
 };
 
 #define DBH_DUP_OFF sizeof(dbih_dbc_t)

Modified: dbd-oracle/branches/FAN/oci8.c
==============================================================================
--- dbd-oracle/branches/FAN/oci8.c	(original)
+++ dbd-oracle/branches/FAN/oci8.c	Thu Feb 23 05:05:52 2012
@@ -1299,109 +1299,102 @@
 
 }
 
+/* HA or High Availabilty callback also called FAN Fast Application Notification */
 
-void
-ha_cbk( dvoid *ha_ctx, OCIEvent *eventhp) {
-
-   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 tsbuff[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);   
-
-   PerlIO_printf(DBILOGFP, "DBIc_ACTIVE=%d\n",DBIc_ACTIVE(imp_dbh));
-
-   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);
-
-   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_code, 0, OCI_ATTR_HA_STATUS, imp_dbh->errhp, status);
-
-
-   if (event_code == OCI_HA_STATUS_UP){
-   	hv_store(ha_event,"Status",6,sv_2mortal(newSVpv("UP",2)),0);
-   }
-   else {
- 	hv_store(ha_event,"Status",6,sv_2mortal(newSVpv("DOWN",4)),0);
-   }
-
-   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_DBDOMAIN, imp_dbh->errhp, status);
+/*  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. */
 
-    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_DBNAME, imp_dbh->errhp, status);
 
-   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_HOSTNAME, imp_dbh->errhp, status);
-
-   hv_store(ha_event,"Host",4,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);
-
-   hv_store(ha_event,"Instance",8,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
+void
+ha_cbk( dvoid *ha_ctx, OCIEvent *eventhp) {
 
+	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_att, &event_att_len, OCI_ATTR_SERVICENAME, imp_dbh->errhp, status);
 
-   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_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);
 
+	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_ts,0, OCI_ATTR_HA_TIMESTAMP, imp_dbh->errhp, status);
+	if (event_code == OCI_HA_STATUS_UP){
+		hv_store(ha_event,"Status",6,sv_2mortal(newSVpv("UP",2)),0);
+	}
+	else {
+		hv_store(ha_event,"Status",6,sv_2mortal(newSVpv("DOWN",4)),0);
+	}
 
+	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_DBDOMAIN, imp_dbh->errhp, status);
 
+	hv_store(ha_event,"Domain",6,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
 
-   OCIDateTimeToText_log_stat(eventhp,imp_dbh->errhp,event_ts,&event_att_len,tsbuff,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,"Timestamp",9,sv_2mortal(newSVpv((char*)tsbuff,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_HOSTNAME, imp_dbh->errhp, status);
 
+	hv_store(ha_event,"Host",4,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
 
-   OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&srvhp,0, OCI_ATTR_HA_SRVFIRST, 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);
 
+	OCIAttrGet_log_stat(eventhp,  OCI_HTYPE_EVENT, (dvoid *)&event_att, &event_att_len, OCI_ATTR_SERVICENAME, imp_dbh->errhp, status);
 
-   OCIAttrGet_log_stat(srvhp,  OCI_HTYPE_SERVER, (dvoid *)&event_att,&event_att_len, OCI_ATTR_INSTNAME, imp_dbh->errhp, status);
+	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);
 
-   av_push(servers, newSVpv( (char *) event_att,0));
+	OCIDateTimeToText_log_stat(eventhp,imp_dbh->errhp,event_ts,&event_att_len,ts_buff,status);
 
+	hv_store(ha_event,"Timestamp",9,sv_2mortal(newSVpv((char*)ts_buff,event_att_len)),0);
 
+	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);
 
-  while(status){
+	av_push(servers, newSVpv( (char *) event_att,0));
 
-     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 {
+	while(status){
 
-      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_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*)DBIc_MY_H(imp_dbh))));
-   XPUSHs(sv_2mortal(newRV((SV*)ha_event)));
-   PUTBACK;
-   call_pv(ctx->function, G_DISCARD);
+	hv_store(ha_event,"Instances",9,newRV_noinc((SV*)servers),0);
+	XPUSHs(sv_2mortal(newRV((SV*)DBIc_MY_H(imp_dbh))));
+	XPUSHs(sv_2mortal(newRV((SV*)ha_event)));
+	PUTBACK;
+	call_pv(ctx->function, G_DISCARD);
 
 }
 
@@ -1414,21 +1407,20 @@
 
 sb4
 reg_ha_callback( imp_dbh_t *imp_dbh){
-        dTHX;
-        sword status;
-        ha_ctx_t  *ctx = NULL;
-        /*allocate space for the callback */
-        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;
-        
-        if (dbd_verbose >= 5 ) {
-                PerlIO_printf(DBILOGFP, " In reg_ha_callback\n");
-        }
+	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;
+
+	if (dbd_verbose >= 5 ) {
+		PerlIO_printf(DBILOGFP, " Register HA callback %s\n",imp_dbh->ha_function);
+	}
 
-        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, (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);
 
 	return status;
 }