[svn:dbd-oracle] r15366 - in dbd-oracle/trunk: . lib/DBD t

[email protected] Thu, 16 Aug 2012 02:43:43 -0700 (PDT)
Newsgroups perl.dbd.oracle.changes
Message-ID <[email protected]>
Author: mjevans
Date: Thu Aug 16 02:43:39 2012
New Revision: 15366

Modified:
   dbd-oracle/trunk/Changes
   dbd-oracle/trunk/dbdimp.c
   dbd-oracle/trunk/dbdimp.h
   dbd-oracle/trunk/lib/DBD/Oracle.pm
   dbd-oracle/trunk/oci8.c
   dbd-oracle/trunk/t/38taf.t   (contents, props changed)

Log:
Remove ora_taf and ora_taf_sleep, reorg TAF support and fix some bugs

t/38taf.t:
  change to unix line endings and set eol-style
oci8.c:
  remove sleep in taf callback - sleep can be done in user callback now
dbdimp.h:
  remove sleep from taf_callback_st
  remove using_taf from dbh_st
  remove taf_sleep from dbh_st
dbdimp.c:
  wrote enable_taf and disable_taf
  in connect change all the taf stuff to just handle ora_taf_function and
    delete it so it does not end up in STORE
    also call enable_taf if someone sets ora_taf_function
  in destroy disable taf if enabled
  in dbh STORE enable or disable taf depending on what ora_taf_function is set to
Oracle.pm:
  update for all of above


Modified: dbd-oracle/trunk/Changes
==============================================================================
--- dbd-oracle/trunk/Changes	(original)
+++ dbd-oracle/trunk/Changes	Thu Aug 16 02:43:39 2012
@@ -27,16 +27,25 @@
     once handled. Code now leaves the setting to the later STORE DBI
     calls (Martin J. Evans)
 
+  [CHANGE IN BEHAVIOUR]
+
+  - ora_taf and ora_taf_sleep were redundant and have been removed.
+    To enable/disable TAF simply set ora_taf_function and if you
+    want to sleep do it in your callback (Martin J. Evans)
+
   - ora_taf_function can now be a code reference as well as a string
     (Martin J. Evans)
 
-  - the ora_taf_function is now passed a third argument of the
-    connection handle (Martin J. Evans)
+  [ENHANCEMENTS]
 
-  [CHANGE IN BEHAVIOUR]
+  - the ora_can_taf method was virtually useless since you can only
+    call it after connecting and to enable TAF you had to do it in the
+    connect call. Now you enable and disable TAF at any time by
+    simply setting or clearing the ora_taf_function (see RT78811)
+    (Martin J. Evans)
 
-  - In future versions taf_sleep will be withdrawn as you can simply
-    sleep in your own callback.
+  - the ora_taf_function is now passed a third argument of the
+    connection handle (Martin J. Evans)
 
   [MISCELLANEOUS]
 

Modified: dbd-oracle/trunk/dbdimp.c
==============================================================================
--- dbd-oracle/trunk/dbdimp.c	(original)
+++ dbd-oracle/trunk/dbdimp.c	Thu Aug 16 02:43:39 2012
@@ -59,6 +59,8 @@
 	int scale;
 };
 static sql_fbh_t ora2sql_type _((imp_fbh_t* fbh));
+static void disable_taf(imp_dbh_t *imp_dbh);
+static int enable_taf(SV *dbh, imp_dbh_t *imp_dbh);
 
 void ora_free_phs_contents _((imp_sth_t *imp_sth, phs_t *phs));
 static void dump_env_to_trace(imp_dbh_t *imp_dbh);
@@ -432,43 +434,17 @@
 #endif
 
     /* TAF Events */
-	imp_dbh->using_taf = 0;
-
-	if (DBD_ATTRIB_TRUE(attr,"ora_taf",7,svp)){
-		imp_dbh->using_taf = 1;
-		imp_dbh->taf_sleep = 5; /* 5 second default */
-
-        /* avoid later STORE: */
-        /* See DBI::DBB problem with ATTRIBI_DELETE until DBI 1.607 */
-        /* DBD_ATTRIB_DELETE(attr, "ora_taf", 7); */
-        (void)hv_delete((HV*)SvRV(attr), "ora_taf", 7, G_DISCARD);
-
-    	DBD_ATTRIB_GET_IV( attr, "ora_taf_sleep",  13, svp, imp_dbh->taf_sleep);
+    if ((svp=DBD_ATTRIB_GET_SVP(attr, "ora_taf_function",  16)) && SvOK(*svp)) {
+        if ((SvROK(*svp) && (SvTYPE(SvRV(*svp)) == SVt_PVCV)) ||
+            (SvPOK(*svp))) {
+            imp_dbh->taf_function = newSVsv(*svp);
+        } else {
+            croak("ora_taf_function needs to be a string or code reference");
+        }
         /* avoid later STORE: */
-        /* See DBI::DBB problem with ATTRIBI_DELETE until DBI 1.607 */
-        /* DBD_ATTRIB_DELETE(attr, "ora_taf_sleep", 13); */
-        (void)hv_delete((HV*)SvRV(attr), "ora_taf_sleep", 13, G_DISCARD);
-
-		if ((svp=DBD_ATTRIB_GET_SVP(attr, "ora_taf_function",  16)) && SvOK(*svp)) {
-            if ((SvROK(*svp) && (SvTYPE(SvRV(*svp)) == SVt_PVCV)) ||
-                (SvPOK(*svp))) {
-                imp_dbh->taf_function = newSVsv(*svp);
-            } else {
-				croak("ora_taf_function needs to be a string or code reference");
-            }
-            /* avoid later STORE: */
-            /* See DBI::DBB problem with ATTRIB_DELETE until DBI 1.607 */
-            /* DBD_ATTRIB_DELETE(attr, "ora_taf_function", 16); */
-            (void)hv_delete((HV*)SvRV(attr), "ora_taf_function", 16, G_DISCARD);
-		}
-#ifdef DONT_DO_NOW
-        if (DBIc_DBISTATE(imp_dbh)->debug || dbd_verbose >= 3)
-            PerlIO_printf(
-                DBIc_LOGPIO(imp_dbh),
-                "taf sleep = %d, taf_function = %s\n",
-                imp_dbh->taf_sleep,
-                (imp_dbh->taf_function ? imp_dbh->taf_function : "");
-#endif
+        /* See DBI::DBB problem with ATTRIB_DELETE until DBI 1.607 */
+        /* DBD_ATTRIB_DELETE(attr, "ora_taf_function", 16); */
+        (void)hv_delete((HV*)SvRV(attr), "ora_taf_function", 16, G_DISCARD);
 	}
 
     imp_dbh->server_version = 0;
@@ -887,33 +863,8 @@
 
     /* set up TAF callback if wanted */
 
-
-    if (imp_dbh->using_taf){
-		bool	can_taf;
-        can_taf = 0;
-
-#ifdef OCI_ATTR_TAF_ENABLED
-		OCIAttrGet_log_stat(imp_dbh, imp_dbh->srvhp, OCI_HTYPE_SERVER, &can_taf, NULL,
-				OCI_ATTR_TAF_ENABLED, imp_dbh->errhp, status);
-#endif
-
-		if (!can_taf){
-			croak("You are attempting to enable TAF on a server that is not TAF Enabled \n");
-		}
-#ifdef DONT_DO_KNOW
-		if (DBIc_DBISTATE(imp_dbh)->debug >= 4 || dbd_verbose >= 4 ) {
-        	PerlIO_printf(
-                DBIc_LOGPIO(imp_dbh),
-                "Setting up TAF with wait time of %d seconds\n",
-                imp_dbh->taf_sleep);
-		}
-#endif
-		status = reg_taf_callback(dbh, imp_dbh);
-		if (status != OCI_SUCCESS) {
-			oci_error(dbh, NULL, status,
-				"Setting TAF Callback Failed! ");
-			return 0;
-		}
+    if (imp_dbh->taf_function){
+        if (enable_taf(dbh, imp_dbh) == 0) return 0;
 	}
 
 	return 1;
@@ -1082,14 +1033,8 @@
 		if (is_extproc)
 			goto dbd_db_destroy_out;
 
-		if (imp_dbh->using_taf){
-			OCIFocbkStruct 	tafailover;
-			tafailover.fo_ctx = NULL;
-			tafailover.callback_function = NULL;
-			OCIAttrSet_log_stat(imp_dbh, imp_dbh->srvhp, (ub4) OCI_HTYPE_SERVER,
-							(dvoid *) &tafailover, (ub4) 0,
-							(ub4) OCI_ATTR_FOCBK, imp_dbh->errhp, status);
-
+		if (imp_dbh->taf_function){
+            disable_taf(imp_dbh);
 		}
 
         if (imp_dbh->taf_function) {
@@ -1164,16 +1109,16 @@
 		imp_dbh->pool_incr = SvIV (valuesv);
 	}
 #endif
-	else if (kl==7 && strEQ(key, "ora_taf") ) {
-		imp_dbh->using_taf = 1;
-	}
 	else if (kl==16 && strEQ(key, "ora_taf_function") ) {
         if (imp_dbh->taf_function)
             SvREFCNT_dec(imp_dbh->taf_function);
         imp_dbh->taf_function = newSVsv(valuesv);
-	}
-	else if (kl==13 && strEQ(key, "ora_taf_sleep") ) {
-			imp_dbh->taf_sleep = SvIV (valuesv);
+
+        if (SvTRUE(valuesv)) {
+            enable_taf(dbh, imp_dbh);
+        } else {
+            disable_taf(imp_dbh);
+        }
 	}
 #ifdef OCI_ATTR_ACTION
 	else if (kl==10 && strEQ(key, "ora_action") ) {
@@ -1285,17 +1230,11 @@
 		retsv = newSViv(imp_dbh->pool_incr);
 	}
 #endif
-	else if (kl==7 && strEQ(key, "ora_taf") ) {
-		retsv = newSViv(imp_dbh->using_taf);
-	}
 	else if (kl==16 && strEQ(key, "ora_taf_function") ) {
         if (imp_dbh->taf_function) {
             retsv = newSVsv(imp_dbh->taf_function);
         }
 	}
-	else if (kl==13 && strEQ(key, "ora_taf_sleep") ) {
-		retsv = newSViv(imp_dbh->taf_sleep);
-	}
 #ifdef OCI_ATTR_ACTION
 	else if (kl==10 && strEQ(key, "ora_action")) {
 		retsv =  newSVpv((char *)imp_dbh->action,0);
@@ -4511,3 +4450,42 @@
 	} while ((char*)environ[i] != '\0');
 }
 
+static void disable_taf(
+    imp_dbh_t *imp_dbh) {
+
+    sword status;
+    OCIFocbkStruct 	tafailover;
+
+    tafailover.fo_ctx = NULL;
+    tafailover.callback_function = NULL;
+    OCIAttrSet_log_stat(imp_dbh, imp_dbh->srvhp, (ub4) OCI_HTYPE_SERVER,
+                        (dvoid *) &tafailover, (ub4) 0,
+                        (ub4) OCI_ATTR_FOCBK, imp_dbh->errhp, status);
+    return;
+}
+
+static int enable_taf(
+    SV *dbh,
+    imp_dbh_t *imp_dbh) {
+
+    bool can_taf = 0;
+    sword status;
+
+#ifdef OCI_ATTR_TAF_ENABLED
+    OCIAttrGet_log_stat(imp_dbh, imp_dbh->srvhp, OCI_HTYPE_SERVER, &can_taf, NULL,
+                        OCI_ATTR_TAF_ENABLED, imp_dbh->errhp, status);
+#endif
+
+    if (!can_taf){
+        croak("You are attempting to enable TAF on a server that is not TAF Enabled \n");
+    }
+
+	status = reg_taf_callback(dbh, imp_dbh);
+    if (status != OCI_SUCCESS) {
+        oci_error(dbh, NULL, status, "Setting TAF Callback Failed! ");
+        return 0;
+    }
+    return 1;
+}
+
+

Modified: dbd-oracle/trunk/dbdimp.h
==============================================================================
--- dbd-oracle/trunk/dbdimp.h	(original)
+++ dbd-oracle/trunk/dbdimp.h	Thu Aug 16 02:43:39 2012
@@ -12,7 +12,6 @@
 
 struct taf_callback_st {
 	SV   *function; /*User supplied TAF functiomn*/
-	int  sleep;
     SV   *dbh_ref;
 };
 
@@ -57,9 +56,7 @@
 	ub4			pool_incr;
 	char		*driver_name;/*driver name user defined*/
 #endif
-    bool		using_taf; /*TAF stuff*/
     SV          *taf_function; /*User supplied TAF functiomn*/
-    int			taf_sleep;
     taf_callback_t taf_ctx;
     char		*client_info;  /*user defined*/
     ub4			client_infol;

Modified: dbd-oracle/trunk/lib/DBD/Oracle.pm
==============================================================================
--- dbd-oracle/trunk/lib/DBD/Oracle.pm	(original)
+++ dbd-oracle/trunk/lib/DBD/Oracle.pm	Thu Aug 16 02:43:39 2012
@@ -401,10 +401,7 @@
                  ora_client_info	=> undef,
                  ora_client_identifier	=> undef,
                  ora_action		=> undef,
-                 ora_taf		=> undef,
                  ora_taf_function	=> undef,
-                 ora_taf_sleep		=> undef,
-
                  };
     }
 
@@ -1407,9 +1404,7 @@
   # NOTE from 1.49_00 ora_taf_function can accept a code ref as well
   #      as a sub name as it now uses call_sv
   my $dbh = DBI->connect('dbi:Oracle:XE', 'hr', 'hr',
-                         {ora_taf => 1,
-                          ora_taf_sleep => 5,
-                          ora_taf_function => 'main::handle_taf'});
+                         {ora_taf_function => 'main::handle_taf'});
 
   #create the perl TAF event function
 
@@ -1438,9 +1433,8 @@
        print " Failed over user. Resuming services\n";
     }
     elsif ($fo_event == OCI_FO_ERROR){
-       print " Failover error Sleeping...\n";
-       # DBD::Oracle will sleep for ora_taf_sleep if you return OCI_FO_RETRY
-       # If you want to stop retrying just return 0
+       print " Failover error ...\n";
+       sleep 5;                 # sleep before having another go
        return OCI_FO_RETRY;
     }
     else {
@@ -1537,15 +1531,14 @@
 
 =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.
-
-NOTE: All the ora_taf* attributes must currently be set in the connect
-method if you want TAF enabled at the moment i.e., after connect you
-can change the callback but you cannot disable TAF.
+This attribute was removed in 1.49_00 as it was redundant. To
+enable TAF simply set L</ora_taf_function>.
 
 =head4 ora_taf_function
 
+If your Oracle instance has been configured to use TAF events you can
+enable the TAF callback by setting this option.
+
 The name of the Perl subroutine (or a code ref from 1.49_00) that will
 be called from OCI when a TAF event occurs. You must supply a perl
 function to use the callback and it will always receive at least two
@@ -1568,13 +1561,8 @@
 
 =head4 ora_taf_sleep
 
-The amount of time in seconds DBD::Oracle will sleep between attempting
-successive failover events when the event is OCI_FO_ERROR and OCI_FO_RETRY
-is returned from the TAF handler.
-
-NOTE: This attribute will be withdrawn in the future so I suggest you
-don't use it and if you want to sleep, add it to your own callback
-sub.
+This attribute was removed in 1.49_00 as it was redundant. If you want
+to sleep between retries simple add a sleep to your callback sub.
 
 =head4 ora_session_mode
 

Modified: dbd-oracle/trunk/oci8.c
==============================================================================
--- dbd-oracle/trunk/oci8.c	(original)
+++ dbd-oracle/trunk/oci8.c	Thu Aug 16 02:43:39 2012
@@ -1340,7 +1340,6 @@
 		case OCI_FO_ERROR:
 		{
             if (ret == OCI_FO_RETRY) {
-                sleep(cb->sleep);
                 return OCI_FO_RETRY;
             }
 			break;
@@ -1365,7 +1364,6 @@
 	sword 			status;
 
     imp_dbh->taf_ctx.function = imp_dbh->taf_function;
-    imp_dbh->taf_ctx.sleep = imp_dbh->taf_sleep;
     imp_dbh->taf_ctx.dbh_ref = newRV_inc(dbh);
 
 	if (dbd_verbose >= 5 ) {

Modified: dbd-oracle/trunk/t/38taf.t
==============================================================================
--- dbd-oracle/trunk/t/38taf.t	(original)
+++ dbd-oracle/trunk/t/38taf.t	Thu Aug 16 02:43:39 2012
@@ -1,62 +1,52 @@
-#!perl -w
-# $Id$
-
-use DBI;
-use DBD::Oracle(qw(:ora_fail_over));
-use strict;
-#use Devel::Peek qw(SvREFCNT Dump);
-
-use Test::More;
-unshift @INC ,'t';
-require 'nchar_test_lib.pl';
-
-$| = 1;
-
-
-# create a database handle
-my $dsn = oracle_test_dsn();
-my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
-
-my $dbh = eval { DBI->connect($dsn, $dbuser, '',) }
-    or plan skip_all => "Unable to connect to Oracle";
-
-$dbh->disconnect;
-
-if ( !$dbh->ora_can_taf ){
-
-    eval {
-        $dbh = DBI->connect(
-            $dsn, $dbuser, '',
-            {ora_taf=>1, ora_taf_sleep=>15,ora_taf_function=>'taf'})
-    };
-  ok($@    =~ /You are attempting to enable TAF/, "'$@' expected! ");
-
-
-}
-else {
-   ok $dbh = DBI->connect($dsn, $dbuser, '',
-                          {ora_taf=>1, ora_taf_sleep=>15,
-                           ora_taf_function=>'taf'});
-
-   is($dbh->{ora_taf}, 1, 'TAF enabled');
-   is($dbh->{ora_taf_sleep}, 15, 'TAF sleep set');
-   is($dbh->{ora_taf_function}, 'taf', 'TAF callback');
-
-   $dbh->{ora_taf} = 0;
-   is($dbh->{ora_taf}, 0, 'TAF disabled');
-
-   $dbh->{ora_taf_sleep} = 10;
-   is($dbh->{ora_taf_sleep}, 10, 'TAF sleep set');
-
-   my $x = sub {};
-#   diag(SvREFCNT($x));
-#   diag(Dump($x));
-   $dbh->{ora_taf_function} = $x;
-   is(ref($dbh->{ora_taf_function}), 'CODE', 'TAF code ref');
-
-#   diag(SvREFCNT($x));
-}
-
-$dbh->disconnect;
-
-done_testing();
+#!perl -w
+# $Id$
+
+use DBI;
+use DBD::Oracle(qw(:ora_fail_over));
+use strict;
+#use Devel::Peek qw(SvREFCNT Dump);
+
+use Test::More;
+unshift @INC ,'t';
+require 'nchar_test_lib.pl';
+
+$| = 1;
+
+# create a database handle
+my $dsn = oracle_test_dsn();
+my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
+
+my $dbh = eval { DBI->connect($dsn, $dbuser, '',) }
+    or plan skip_all => "Unable to connect to Oracle";
+
+$dbh->disconnect;
+
+if ( !$dbh->ora_can_taf ){
+
+    eval {
+        $dbh = DBI->connect(
+            $dsn, $dbuser, '',
+            {ora_taf_function=>'taf'})
+    };
+  ok($@    =~ /You are attempting to enable TAF/, "'$@' expected! ");
+
+
+}
+else {
+   ok $dbh = DBI->connect($dsn, $dbuser, '',
+                          {ora_taf_function=>'taf'});
+
+   is($dbh->{ora_taf_function}, 'taf', 'TAF callback');
+
+   my $x = sub {};
+#   diag(SvREFCNT($x));
+#   diag(Dump($x));
+   $dbh->{ora_taf_function} = $x;
+   is(ref($dbh->{ora_taf_function}), 'CODE', 'TAF code ref');
+
+#   diag(SvREFCNT($x));
+}
+
+$dbh->disconnect;
+
+done_testing();