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

[email protected] Fri, 5 Oct 2012 11:25:26 -0700 (PDT)
Newsgroups perl.dbd.oracle.changes
Message-ID <[email protected]>
Author: byterock
Date: Fri Oct  5 11:25:26 2012
New Revision: 15432

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

Log:
code cleaned up and pod fixed up

Modified: dbd-oracle/branches/FAN/Oracle.pm
==============================================================================
--- dbd-oracle/branches/FAN/Oracle.pm	(original)
+++ dbd-oracle/branches/FAN/Oracle.pm	Fri Oct  5 11:25:26 2012
@@ -1131,13 +1131,16 @@
 You can find a white paper on setting up DRCP and its advantages at L<http://www.oracle.com/technetwork/articles/oracledrcp11g-1-133381.pdf>.
 Please note that DRCP support in DBD::Oracle is relatively new so the
 mechanics or its implementation are subject to change.
+
 =head3 HA (High Availably Event Notification)
-For RAC clusters OCI provides a mechanism, called the HA event notification, to quickly report if a server
+
+For RAC clusters OCI provides a mechanism, called HA event notification, to quickly report if a server
 instance, node or cluster has failed.  DBD::Oracle can now receive these notifications
 as a callback to a function in Perl that you provide.
 To receive HA notifications the OCI Environment must be initialized in both OCI_EVENTS and OCI_THREADED mode, 
 connect to a service that has notifications enabled by using the DBMS_SERVICE.MODIFY_SERVICE
-procedure to set AQ_HA_NOTIFICATIONS to TRUE and is compiles using threaded Perl.
+procedure to set AQ_HA_NOTIFICATIONS to TRUE and is compiled using threaded Perl.
+
 The way HA events work can be a little confusing as they seem to work opposite to what one would expect.
 For example, if an application that has two connections to instance A and two connections to instance B
 of the same database and if instance A goes down, a notification of the event will be sent to the client,
@@ -1162,7 +1165,7 @@
   my $dbh = DBI->connect('dbi:Oracle:RAC_XE','hr','hr',{ora_ha_function=>'handle_ha'});
   #create the Perl HA event function
   sub handle_ha {
-    my ($ha_event) = @_;
+    my ($ha_event,$dbh) = @_;
     print Dumper($ha_event);
   }
 The HA event is an array hash with the following keys
@@ -1319,6 +1322,26 @@
 greater than ora_drcp_max.
 This value can also be specified with the C<ORA_DRCP_INCR> environment
 variable.
+=head4 ora_ha_function
+If you are using and oracle client greater than 11.2 to connect to an Oracle cluster that has been
+configured to use FAN (Fast Application Notification) then you can receive these HA (High Availablity) events
+by providing a callback sub with this option.
+by setting this option.
+
+You can use a either the name of the Perl subroutine, or a code ref, that will be called from OCI when an HA event occurs.
+The perl function callback will always receive at least two parameters; a HASH of event details and the dbh.
+Below is an example of a HA function
+
+  sub ha_event{
+     my ($event, $dbh) = @_;
+
+     print "My HA event= Dumper($event)\n";
+     return;
+  }
+
+Note if passing a sub name you will probably have to use the full name space when setting the function 
+   e.g., 'main::ha_event' and not just 'ha_event'.
+   
 =head4 ora_taf
 If your Oracle instance has been configured to use TAF events you can
 enable the TAF callback by setting this option to any I<true> value.

Modified: dbd-oracle/branches/FAN/dbdimp.c
==============================================================================
--- dbd-oracle/branches/FAN/dbdimp.c	(original)
+++ dbd-oracle/branches/FAN/dbdimp.c	Fri Oct  5 11:25:26 2012
@@ -458,8 +458,6 @@
 
 	}
 
-PerlIO_printf(DBILOGFP," check 1 \n ");
-
 
 
 #endif /*ORA_OCI_112*/
@@ -501,14 +499,13 @@
 
     }
 
-PerlIO_printf(DBILOGFP," check 2 \n ");
+
 
 
     /* TAF Events */
 
 	imp_dbh->using_taf = 0;
 
-PerlIO_printf(DBILOGFP," check 2a \n ");
 
 	if (DBD_ATTRIB_TRUE(attr,"ora_taf",7,svp)){
 		imp_dbh->using_taf = 1;
@@ -527,15 +524,12 @@
 
     imp_dbh->server_version = 0;
 
-PerlIO_printf(DBILOGFP," check 2b \n ");
 
 	/* check to see if DBD_verbose or ora_verbose is set*/
 	if (DBD_ATTRIB_TRUE(attr,"dbd_verbose",11,svp))
 		DBD_ATTRIB_GET_IV(  attr, "dbd_verbose",  11, svp, dbd_verbose);
 	if (DBD_ATTRIB_TRUE(attr,"ora_verbose",11,svp))
 		DBD_ATTRIB_GET_IV(  attr, "ora_verbose",  11, svp, dbd_verbose);
-
-PerlIO_printf(DBILOGFP," check 2c \n ");
 	/* check to see if success_warn is set. This will */
 	/* warn after some sucessfull operations for tuning results */
 	if (DBD_ATTRIB_TRUE(attr,"ora_oci_success_warn",20,svp))
@@ -547,12 +541,9 @@
 	if (DBD_ATTRIB_TRUE(attr,"ora_objects",11,svp))
 		DBD_ATTRIB_GET_IV(  attr, "ora_objects",11, svp, ora_objects);
 
-PerlIO_printf(DBILOGFP," check 2d \n ");
-
 	if (DBIS->debug >= 6 || dbd_verbose >= 6 )
 		dump_env_to_trace();
 
-PerlIO_printf(DBILOGFP," check 2e \n ");
 
 	/* dbi_imp_data code adapted from DBD::mysql */
 	if (DBIc_has(imp_dbh, DBIcf_IMPSET)) {
@@ -573,8 +564,6 @@
 
 	imp_dbh->envhp = imp_drh->envhp;	/* will be NULL on first connect */
 
-PerlIO_printf(DBILOGFP," check 3 \n ");
-
 
 #if defined(USE_ITHREADS) && defined(PERL_MAGIC_shared_scalar)
 	shared_dbh_priv_svp = (DBD_ATTRIB_OK(attr)?hv_fetch((HV*)SvRV(attr), "ora_dbh_share", 13, 0):NULL) ;
@@ -956,10 +945,9 @@
 #ifdef ORA_OCI_112
 	/* set up HA evnets callback if requested */
 
- PerlIO_printf(DBILOGFP," check 4 \n ");
 
 	if (imp_dbh->ha_function){
-       if (enable_ha(dbh,imp_dbh) == 0) return 0;
+		if (enable_ha(dbh,imp_dbh) == 0) return 0;
 	}
 #endif /* ORA_OCI_112 */
 	return 1;
@@ -1207,16 +1195,17 @@
 		imp_dbh->pool_incr = SvIV (valuesv);
 	}
 	else if (kl==15 && strEQ(key, "ora_ha_function") ) {
-                  if (imp_dbh->ha_function)
-            SvREFCNT_dec(imp_dbh->ha_function);
-          imp_dbh->ha_function = newSVsv(valuesv);
-
-          if (SvTRUE(valuesv)) {
-            enable_ha(dbh, imp_dbh);
-          } else {
-            disable_ha(imp_dbh);
-          }
 
+		if (imp_dbh->ha_function)
+			SvREFCNT_dec(imp_dbh->ha_function);
+
+		imp_dbh->ha_function = newSVsv(valuesv);
+		if (SvTRUE(valuesv)) {
+			enable_ha(dbh, imp_dbh);
+		}
+		else {
+			disable_ha(imp_dbh);
+		}
 	}
 
 #endif
@@ -4415,8 +4404,8 @@
 dTHX;
 	sword	status;
 
-   	ha_ctx_t *ctx = NULL;
-   	ctx->imp_dbh  = NULL;
+	ha_ctx_t *ctx = NULL;
+	ctx->imp_dbh  = NULL;
 	ctx->function = NULL;
 	ctx->ctx_perl = NULL;
 	ctx->dbh_ref  = NULL;
@@ -4428,10 +4417,10 @@
 }
 
 static int enable_ha(
-    SV *dbh,
-    imp_dbh_t *imp_dbh) {
-dTHX;
- sword   status;
+	SV *dbh,
+	imp_dbh_t *imp_dbh) {
+	dTHX;
+	sword	status;
 
 	if (DBIS->debug >= 4 || dbd_verbose >= 4 ) {
 		PerlIO_printf(DBILOGFP,"Setting up HA Event Callback!");
@@ -4444,7 +4433,7 @@
 		return 0;
 	}
 
-   	return 1;
+	return 1;
 
 }
 

Modified: dbd-oracle/branches/FAN/dbdimp.h
==============================================================================
--- dbd-oracle/branches/FAN/dbdimp.h	(original)
+++ dbd-oracle/branches/FAN/dbdimp.h	Fri Oct  5 11:25:26 2012
@@ -71,8 +71,8 @@
 	ub4			pool_incr;
 	char		*driver_name;/*driver name user defined*/
 	ub4			driver_namel;
-	SV		    *ha_function; /*HA function */
-	ha_ctx_t    ha_ctx;       /*HA context  */
+	SV			*ha_function; /*HA function */
+	ha_ctx_t	ha_ctx;       /*HA context  */
 #endif
 	bool		using_taf; /*TAF stuff*/
 	char		*taf_function; /*User supplied TAF function*/

Modified: dbd-oracle/branches/FAN/oci8.c
==============================================================================
--- dbd-oracle/branches/FAN/oci8.c	(original)
+++ dbd-oracle/branches/FAN/oci8.c	Fri Oct  5 11:25:26 2012
@@ -1306,7 +1306,7 @@
 /*  all handled behind the scene and the cluster software does it for you.  With this callback */
 /*  you can receive these events with the caveat that you cannot do allot 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 a hash that contains all the event data. */
+/*  Anyway the callback will return a hash that contains all the event data.and the DBH handle */
 
 
 
@@ -1412,7 +1412,7 @@
 	imp_dbh->ha_ctx.ctx_perl = my_perl;
 	imp_dbh->ha_ctx.imp_dbh  = imp_dbh;
 	imp_dbh->ha_ctx.dbh_ref  = dbh;
-    ctx = &imp_dbh->ha_ctx;
+	ctx = &imp_dbh->ha_ctx;
 
 
 	if (dbd_verbose >= 5 ) {