Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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


git-svn-id: http://svn.perl.org/modules/dbd-oracle/trunk@15366 50811bd7-b8ce-0310-adc1-d9db26280581
  • Loading branch information...
commit 44c2d0ac2ceb019f19e4a26511f7b08f65d7490c 1 parent ef96e2b
mjevans authored
Showing with 137 additions and 177 deletions.
  1. +14 −5 Changes
  2. +61 −83 dbdimp.c
  3. +0 −3  dbdimp.h
  4. +10 −22 lib/DBD/Oracle.pm
  5. +0 −2  oci8.c
  6. +52 −62 t/38taf.t
View
19 Changes
@@ -27,16 +27,25 @@ NEXTRELEASE
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]
View
144 dbdimp.c
@@ -59,6 +59,8 @@ struct sql_fbh_st {
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 @@ dbd_db_login6(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *uid, char *pwd, S
#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 @@ dbd_db_login6(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *uid, char *pwd, S
/* 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 @@ dbd_db_destroy(SV *dbh, imp_dbh_t *imp_dbh)
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 @@ dbd_db_STORE_attrib(SV *dbh, imp_dbh_t *imp_dbh, SV *keysv, SV *valuesv)
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 @@ dbd_db_FETCH_attrib(SV *dbh, imp_dbh_t *imp_dbh, SV *keysv)
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 @@ dump_env_to_trace(imp_dbh_t *imp_dbh) {
} 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;
+}
+
+
View
3  dbdimp.h
@@ -12,7 +12,6 @@ typedef struct taf_callback_st taf_callback_t;
struct taf_callback_st {
SV *function; /*User supplied TAF functiomn*/
- int sleep;
SV *dbh_ref;
};
@@ -57,9 +56,7 @@ struct imp_dbh_st {
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;
View
32 lib/DBD/Oracle.pm
@@ -401,10 +401,7 @@ BEGIN {
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 @@ attempts another event.
# 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 @@ attempts another event.
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 @@ variable.
=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 @@ not just 'my_taf_function'.
=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
View
2  oci8.c
@@ -1340,7 +1340,6 @@ taf_cbk(dvoid *svchp, dvoid *envhp, dvoid *fo_ctx,ub4 fo_type, ub4 fo_event )
case OCI_FO_ERROR:
{
if (ret == OCI_FO_RETRY) {
- sleep(cb->sleep);
return OCI_FO_RETRY;
}
break;
@@ -1365,7 +1364,6 @@ reg_taf_callback(SV *dbh, imp_dbh_t *imp_dbh)
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 ) {
View
114 t/38taf.t
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.