Front page | perl.dbd.oracle.changes |
Postings from March 2012
[svn:dbd-oracle] r15207 - dbd-oracle/branches/FAN
From:
byterock
Date:
March 9, 2012 05:33
Subject:
[svn:dbd-oracle] r15207 - dbd-oracle/branches/FAN
Message ID:
20120309133341.BAD65184B81@xx12.develooper.com
Author: byterock
Date: Fri Mar 9 05:33:39 2012
New Revision: 15207
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:
Well getting close to it
Modified: dbd-oracle/branches/FAN/Oracle.pm
==============================================================================
--- dbd-oracle/branches/FAN/Oracle.pm (original)
+++ dbd-oracle/branches/FAN/Oracle.pm Fri Mar 9 05:33:39 2012
@@ -1131,43 +1131,43 @@
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 Availabily Event Notification)
-For RAC clustes OCI provides a mechanism to quickly tell if a server instance, node or cluster
-has failed called the HA Event. DBD::Oracle can now receive these notifications
-as a callback to a function in perl that you provide.
-To use the HA callback events the OCI Environment must be initialized in OCI_EVENTS mode,
-connect to a service that has notifications enabled by useing the DBMS_SERVICE.MODIFY_SERVICE
-procedure to set AQ_HA_NOTIFICATIONS to TRUE and is using threaded Perl. Needless to say
-you must connect to a RAC instance for this callback to work.
-The way HA evnets work can be a little confusing as they seem to work opposite to what one would expect.
+=head3 HA (High Availably Event Notification)
+For RAC clusters OCI provides a mechanism, called the 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.
+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,
which will then disconnect the two connections to instance B, and invoke the callback if there happens to
be another instance, C, and it goes down, the client will not be notified as the event does not affect
any of the client's connections.
-Long story short HA events are what drives FAN (Fast Application Notification) and in pratice you will be
-notified when an instace goes down or up but only connections that are not effected will be notified. Which makes
-sense as if you are writing a load balancer or connection pool it would be a good thing to know when a node, instace or
+Long story short HA events are what drives FAN (Fast Application Notification) and in practice you will be
+notified when an instance goes down or up but only connections that are not effected will be notified. Which makes
+sense as if you are writing a load balancer or connection pool it would be a good thing to know when a node, instance or
service has gone down or has come up.
-Now what use it this? You can now monitior your instances with perl as well you can escape a perl application if you
-get a notification that an instace is down. One problem with the code as it stands it you cannot get any of the
+Now what use it this? You can now monitor your instances with Perl and detect disrucption in serves very quickly.
+As well you can escape a Perl application if you get a notification that an instance is down rather than waitying for a
+connection to time out. One problem with the code as it stands it you cannot get any of the
DBI handles that might be effected by the event as the callback is a zombie thread created in OCI.
-To get HA evnets you will have to have a properly configured RAC instace with at least two nodes, you will also have
-to create your own perl function that will be called from the client. You can name it anything you want and it will
+To receive HA events you will have to have a properly configured RAC instance with at least two nodes, you will also have
+to create your own Perl function that will be called from the client. You can name it anything you want and it will
be passed one parameter, the HA event.
use DBD::Oracle;
use Data::Dumper;
#import the ora fail over constants
- #set up a connection that will listen for HA evnents
- my $dbh = DBI->connect('dbi:Oracle:RAC_XE','hr','hr',{ora_ha=>1,ora_ha_function=>'handle_ha'});
- #create the perl HA event function
+ #set up a connection that will listen for HA events
+ 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) = @_;
print Dumper($ha_event);
}
The HA event is an array hash with the following keys
=head4 HA_Source
-A scalar value that describes where the event orginated. It can be one of "INSATNCE","DATABASE","NODE",
+A scalar value that describes where the event originated. It can be one of "INSATNCE","DATABASE","NODE",
"SERVICE","SERVICE_MEMBER","ASM_INSTANCE" or "SERVICE_PRECONNECT".
=head4 HA_Status
A scalar value that describes the status of the 'Source' key. The only valid values are 'UP' and 'DOWN'.
@@ -1184,7 +1184,7 @@
=head4 Time_Stamp
A scalar value of the time that the HA event occurred.
=head4 Instances
-An array of all the DB instaces that where effected by this event.
+An array of all the DB instances that where effected by this event.
So a typical hash ref return passed to this function would look like this
$ha_event = {HA_Source=>'INSATNCE',
HA_Status=>'DOWN',
@@ -1219,7 +1219,7 @@
(METHOD=basic)
(RETRIES=10)
(DELAY=10))
-You will also have to create your own perl function that will be
+You will also have to create your own Perl function that will be
called from the client. You can name it anything you want and it will
always be passed two parameters, the failover event value and the
failover type. You can also set a sleep value in case of failover
@@ -1229,7 +1229,7 @@
#import the ora fail over constants
#set up TAF on the connection
my $dbh = DBI->connect('dbi:Oracle:XE','hr','hr',{ora_taf=>1,taf_sleep=>5,ora_taf_function=>'handle_taf'});
- #create the perl TAF event function
+ #create the Perl TAF event function
sub handle_taf {
my ($fo_event,$fo_type) = @_;
if ($fo_event == OCI_FO_BEGIN){
@@ -1324,7 +1324,7 @@
enable the TAF callback by setting this option to any I<true> value.
=head4 ora_taf_function
The name of the Perl subroutine that will be called from OCI when a
-TAF event occurs. You must supply a perl function to use the callback
+TAF event occurs. You must supply a Perl function to use the callback
and it will always receive two parameters, the failover event value
and the failover type. Below is an example of a TAF function
sub taf_event{
@@ -2472,7 +2472,7 @@
calling this method, unless L</RaiseError> has been enabled.
If C<$slice> is an array reference, fetchall_arrayref uses the L</fetchrow_arrayref> method to fetch each
row as an array ref. If the C<$slice> array is not empty then it is used as a slice to select individual
-columns by perl array index number (starting at 0, unlike column and parameter numbers which start at 1).
+columns by Perl array index number (starting at 0, unlike column and parameter numbers which start at 1).
With no parameters, or if $slice is undefined, fetchall_arrayref acts as if passed an empty array ref.
If C<$slice> is a hash reference, fetchall_arrayref uses L</fetchrow_hashref> to fetch each row as a hash reference.
See the DBI documentation for a complete discussion.
Modified: dbd-oracle/branches/FAN/dbdimp.c
==============================================================================
--- dbd-oracle/branches/FAN/dbdimp.c (original)
+++ dbd-oracle/branches/FAN/dbdimp.c Fri Mar 9 05:33:39 2012
@@ -202,7 +202,7 @@
int
dbd_discon_all(SV *drh, imp_drh_t *imp_drh)
{
-
+
dTHX;
/* The disconnect_all concept is flawed and needs more work */
if (!PL_dirty && !SvTRUE(perl_get_sv("DBI::PERL_ENDING",0))) {
@@ -385,7 +385,7 @@
int
dbd_db_login6(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *uid, char *pwd, SV *attr)
{
-
+
dTHX;
sword status;
SV **svp;
@@ -400,7 +400,6 @@
SV * shared_dbh_priv_sv ;
STRLEN shared_dbh_len = 0 ;
-PerlIO_printf(DBILOGFP,"Use threads.\n");
#endif
@@ -440,20 +439,21 @@
/* HA Events */
- imp_dbh->using_ha = 0;
+ imp_dbh->using_ha = 0;
- if (DBD_ATTRIB_TRUE(attr,"ora_ha",6,svp)){
- imp_dbh->using_ha = 1;
+ if (DBD_ATTRIB_TRUE(attr,"ora_ha_function",15,svp)){
+ imp_dbh->using_ha = 1;
+ if ((svp=DBD_ATTRIB_GET_SVP(attr, "ora_ha_function", 15)) && SvOK(*svp)) {
+ STRLEN svp_len;
- if ((svp=DBD_ATTRIB_GET_SVP(attr, "ora_ha_function", 15)) && SvOK(*svp)) {
- STRLEN svp_len;
- if (!SvPOK(*svp))
- croak("ora_ha_function is not a string");
- imp_dbh->ha_function = (char *) SvPV (*svp, svp_len );
+ if (!SvPOK(*svp))
+ croak("ora_ha_function is not a string");
- }
- }
+ imp_dbh->ha_function = (char *) SvPV (*svp, svp_len );
+
+ }
+ }
#endif /*ORA_OCI_112*/
@@ -496,7 +496,7 @@
}
/* TAF Events */
-
+
imp_dbh->using_taf = 0;
if (DBD_ATTRIB_TRUE(attr,"ora_taf",7,svp)){
@@ -522,7 +522,6 @@
if (DBD_ATTRIB_TRUE(attr,"ora_verbose",11,svp))
DBD_ATTRIB_GET_IV( attr, "ora_verbose", 11, svp, dbd_verbose);
-dbd_verbose=15;
/* 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))
@@ -610,7 +609,7 @@
DBD_ATTRIB_GET_IV(attr, "ora_init_mode",13, init_mode_sv, init_mode);
- {
+ {
size_t rsize = 0;
/* Get CLIENT char and nchar charset id values */
OCINlsEnvironmentVariableGet_log_stat( &charsetid,(size_t) 0, OCI_NLS_CHARSET_ID, 0, &rsize ,status );
@@ -650,8 +649,6 @@
OCIEnvNlsCreate_log_stat( &imp_dbh->envhp,init_mode, (dvoid *) 0,(dvoid * (*)(dvoid *,size_t)) 0, (dvoid * (*)(dvoid *, dvoid *, size_t)) 0, (void (*)(dvoid *, dvoid *)) 0, (size_t)0, (dvoid **)0,
charsetid, ncharsetid, status );
- PerlIO_printf(DBILOGFP, " well I am here 1\n");
-
if (status != OCI_SUCCESS) {
oci_error(dbh, NULL, status,
"OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var or PATH (Windows) and or NLS settings, permissions, etc.");
@@ -690,7 +687,6 @@
if (new_charsetid) charsetid = new_charsetid;
if (new_ncharsetid) ncharsetid = new_ncharsetid;
imp_dbh->envhp = NULL;
-PerlIO_printf(DBILOGFP, " well I am here 2\n");
OCIEnvNlsCreate_log_stat( &imp_dbh->envhp, OCI_EVENTS, 0, NULL, NULL, NULL, 0, 0,
charsetid, ncharsetid, status );
if (status != OCI_SUCCESS) {
@@ -914,7 +910,7 @@
/* set up TAF callback if wanted */
-
+
if (imp_dbh->using_taf){
bool can_taf;
@@ -939,22 +935,20 @@
#ifdef ORA_OCI_112
/* set up HA evnets callback if requested */
- if (imp_dbh->using_ha){
-
- if (DBIS->debug >= 4 || dbd_verbose >= 4 ) {
- PerlIO_printf(DBILOGFP,"Setting up HA Event Callback!");
- }
-
- status = reg_ha_callback(imp_dbh);
-
- if (status != OCI_SUCCESS) {
- oci_error(dbh, NULL, status,
- "Setting HA Event Callback Failed! ");
- return 0;
- }
- }
+ if (imp_dbh->using_ha){
+
+ if (DBIS->debug >= 4 || dbd_verbose >= 4 ) {
+ PerlIO_printf(DBILOGFP,"Setting up HA Event Callback!");
+ }
+
+ status = reg_ha_callback(imp_dbh);
+
+ 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;
}
@@ -1057,7 +1051,7 @@
dbd_db_disconnect(SV *dbh, imp_dbh_t *imp_dbh)
{
dTHX;
-
+
int refcnt = 1 ;
#if defined(USE_ITHREADS) && defined(PERL_MAGIC_shared_scalar)
@@ -1119,30 +1113,30 @@
if (DBIc_ACTIVE(imp_dbh))
dbd_db_disconnect(dbh, 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;
+ OCIFocbkStruct taf_failover;
+ taf_failover.fo_ctx = NULL;
+ taf_failover.callback_function = NULL;
OCIAttrSet_log_stat(imp_dbh->srvhp, (ub4) OCI_HTYPE_SERVER,
- (dvoid *) &tafailover, (ub4) 0,
+ (dvoid *) &taf_failover, (ub4) 0,
(ub4) OCI_ATTR_FOCBK, imp_dbh->errhp, status);
-
}
+
#ifdef ORA_OCI_112
- if (imp_dbh->using_ha){
- OCIFocbkStruct ha_failover;
- ha_failover.fo_ctx = NULL;
- ha_failover.callback_function = NULL;
- OCIAttrSet_log_stat(imp_dbh->srvhp, (ub4) OCI_HTYPE_SERVER,
- (dvoid *) &ha_failover, (ub4) 0,
- (ub4) OCI_ATTR_FOCBK, imp_dbh->errhp, status);
+ if (imp_dbh->using_ha){
+ ha_ctx_t *ctx = NULL;
+ ctx->function = NULL;
+ ctx->ctx_perl = NULL;
+ ctx->imp_dbh = NULL;
+ OCIAttrSet_log_stat(imp_dbh->envhp, OCI_HTYPE_ENV,
+ ctx,0,OCI_ATTR_EVTCTX, imp_dbh->errhp , status);
+ }
- }
-
if (imp_dbh->using_drcp) {
OCIHandleFree_log_stat(imp_dbh->authp, OCI_HTYPE_SESSION,status);
@@ -1161,7 +1155,7 @@
}
OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
-dbd_db_destroy_out:
+ dbd_db_destroy_out:
DBIc_IMPSET_off(imp_dbh);
}
@@ -1203,12 +1197,10 @@
else if (kl==13 && strEQ(key, "ora_drcp_incr") ) {
imp_dbh->pool_incr = SvIV (valuesv);
}
- else if (kl==6 && strEQ(key, "ora_ha") ) {
- imp_dbh->using_ha = 1;
- }
- else if (kl==15 && strEQ(key, "ora_ha_function") ) {
- imp_dbh->ha_function = (char *) SvPV (valuesv, vl );
- }
+ else if (kl==15 && strEQ(key, "ora_ha_function") ) {
+ imp_dbh->ha_function = (char *) SvPV (valuesv, vl );
+
+ }
#endif
else if (kl==7 && strEQ(key, "ora_taf") ) {
@@ -1329,12 +1321,9 @@
else if (kl==13 && strEQ(key, "ora_drcp_incr") ) {
retsv = newSViv(imp_dbh->pool_incr);
}
- else if (kl==6 && strEQ(key, "ora_ha") ) {
- retsv = newSViv(imp_dbh->using_ha);
- }
- else if (kl==15 && strEQ(key, "ora_ha_function") ) {
- retsv = newSVpv((char *)imp_dbh->ha_function,0);
- }
+ else if (kl==15 && strEQ(key, "ora_ha_function") ) {
+ retsv = newSVpv((char *)imp_dbh->ha_function,0);
+ }
#endif
else if (kl==7 && strEQ(key, "ora_taf") ) {
retsv = newSViv(imp_dbh->using_taf);
@@ -1412,7 +1401,7 @@
createxmlfromstring(SV *sth, imp_sth_t *imp_sth, SV *source){
dTHX;
-
+
OCIXMLType *xml = NULL;
STRLEN len;
ub4 buflen;
@@ -1696,7 +1685,7 @@
int ora_realloc_phs_array(phs_t *phs,int newentries, int newbufsize){
dTHX;
-
+
int i; /* Loop variable */
unsigned short *newal;
@@ -2663,7 +2652,7 @@
pp_rebind_ph_rset_in(SV *sth, imp_sth_t *imp_sth, phs_t *phs)
{
dTHX;
-
+
SV * sth_csr = phs->sv;
D_impdata(imp_sth_csr, imp_sth_t, sth_csr);
sword status;
@@ -3316,7 +3305,7 @@
int
dbd_st_execute(SV *sth, imp_sth_t *imp_sth) /* <= -2:error, >=0:ok row count, (-1=unknown count) */
{
-
+
dTHX;
ub4 row_count = 0;
int debug = DBIS->debug;
@@ -3643,7 +3632,7 @@
SV *err_count;
{
dTHX;
-
+
ub4 row_count = 0;
int debug = DBIS->debug;
D_imp_dbh_from_sth;
@@ -3971,7 +3960,7 @@
int
dbd_st_finish(SV *sth, imp_sth_t *imp_sth)
{
-
+
dTHX;
D_imp_dbh_from_sth;
sword status;
Modified: dbd-oracle/branches/FAN/dbdimp.h
==============================================================================
--- dbd-oracle/branches/FAN/dbdimp.h (original)
+++ dbd-oracle/branches/FAN/dbdimp.h Fri Mar 9 05:33:39 2012
@@ -8,13 +8,14 @@
/* ====== define data types ====== */
-typedef struct ha_context_st ha_context_t;
+/*--------------------------FAN Callback Structure ---------------------*/
-struct ha_context_st {
- PerlInterpreter *ct_perl;
- SV *dbh;
- imp_dbh_t *imp_dbh;
- char *function;
+typedef struct ha_ctx_st ha_ctx_t;
+
+struct ha_ctx_st {
+ PerlInterpreter *ctx_perl;
+ imp_dbh_t *imp_dbh;
+ char *function;
};
/*--------------------------TAF Callback Structure ---------------------*/
@@ -57,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;
@@ -68,30 +69,28 @@
ub4 pool_incr;
char *driver_name;/*driver name user defined*/
ub4 driver_namel;
- bool using_ha;
- ha_context_t *ha_context;
- 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 Fri Mar 9 05:33:39 2012
@@ -3,7 +3,7 @@
oci8.c
Copyright (c) 1998-2006 Tim Bunce Ireland
- Copyright (c) 2006-2008 John Scoles (The Pythian Group), Canada
+ Copyright (c) 2006-2011 John Scoles (The Pythian Group), Canada
See the COPYRIGHT section in the Oracle.pm file for terms.
@@ -1299,178 +1299,129 @@
}
-//pthread_mutex_t mutex;
+/* HA or High Availability callback also called FAN Fast Application Notification */
-//static pthread_mutex_t mutex=PHTREAD_MUTEX_INITIALIZER;
+/* 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. Normally this is */
+/* 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. */
-void
-hacb_fn( dvoid *ha_ctx, OCIEvent *eventhp) {
-
- ha_context_t *ctx =(ha_context_t*)ha_ctx;
- imp_dbh_t *imp_dbh = (imp_dbh_t*)ctx->imp_dbh;
- pthread_mutex_t mutex;
- pthread_mutex_init(&mutex, NULL);
- pthread_mutex_lock(&mutex);
- PERL_SET_CONTEXT(ctx->ct_perl);
- do_ha_perl(imp_dbh,eventhp,ctx->function);
- pthread_mutex_destroy(&mutex);
-}
-void
-do_ha_perl( imp_dbh_t *imp_dbh, OCIEvent *eventhp,char *function) {
-
- dTHX;
- dSP;
- OCIServer *srvhp;
- sword status;
- text *event_att;
- OCIDateTime *event_ts;
- OraText tsbuff[50];
- ub4 event_att_len;
- ub4 event_code;
- HV* ha_event;
- AV* servers;
- ha_event = newHV();
- servers = newAV();
- PUSHMARK(SP);
-
- PerlIO_printf(DBILOGFP, "DBIc_ACTIVE=%d\n",DBIc_ACTIVE(imp_dbh));
-
- //sv_bless(dbh,dbh_h);
- /*if (dbh){
- PerlIO_printf(DBILOGFP, " dhb is object cb_f=%d\n",sv_isobject(SvRV(dbh)));
- }
- //PerlIO_printf(DBILOGFP, " dhb isa DBI::db cb_f=%d\n",sv_derived_from(dbh,"DBI::db"));
-
-PerlIO_printf(DBILOGFP, " dhb isa cb_f=%d\n",sv_derived_from(SvRV(dbh),"DBI::db"));
-
-//PerlIO_printf(DBILOGFP, " dhb isa cb_f=%s\n", HvNAME(dbh_h));
-
-
-
-*/
-// PerlIO_printf(DBILOGFP, " dhb isa DBI::db cb_f=%d\n",sv_derived_from(dbh,"DBI::db"));
-
-
- 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);
+void
+ha_cbk( dvoid *ha_ctx, OCIEvent *eventhp)
+{
- 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);
-
- 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);
+ 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);
+ OCIAttrGet_log_stat(eventhp, OCI_HTYPE_EVENT, (dvoid *)&event_code, 0, OCI_ATTR_HA_SOURCE, imp_dbh->errhp, status);
- hv_store(ha_event,"Service",7,sv_2mortal(newSVpv((char*)event_att,event_att_len)),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);
+ 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,"HA_Status",9,sv_2mortal(newSVpv("UP",2)),0);
+ }
+ else {
+ hv_store(ha_event,"HA_Status",9,sv_2mortal(newSVpv("DOWN",4)),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 *)&event_att, &event_att_len, OCI_ATTR_DBDOMAIN, imp_dbh->errhp, status);
+ hv_store(ha_event,"DB_Domain",9,sv_2mortal(newSVpv((char*)event_att,event_att_len)),0);
- 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);
+ 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,"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);
+ 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 *)&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_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(srvhp, OCI_HTYPE_SERVER, (dvoid *)&event_att,&event_att_len, OCI_ATTR_INSTNAME, imp_dbh->errhp, status);
+ hv_store(ha_event,"Service_Name",12,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,"Time_Stamp",10,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);
- //sv_2mortal(newRV_inc((SV*)DBIc_MY_H(imp_xxh)))
- XPUSHs(sv_2mortal(newRV((SV*)DBIc_MY_H(imp_dbh))));
- XPUSHs(sv_2mortal(newRV((SV*)ha_event)));
- PUTBACK;
- call_pv(function, G_DISCARD);
+ 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 Availability Callback */
+/* Works like this. The function below is registered on the cluster,*/
+/* when a node on a cluster goes up or down then messages are propagated */
+/* to the other nodes on the cluster. Used for load balancing are reconnecting. */
+/* Not very useful to perl as you cannot do much but monitor events as this */
+/* is using 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_context_t *ctx = NULL;
- // SV* dbhref = newRV(dbh);// = sv_setref_iv(dbh, "DBI::db");
-// = newSVrv((SV*) dbh, "DBI::db");
-//newRV_noinc((SV*) dbh);
-/*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;
- //sv_setref_pv(dbhref,"DBI::db", dbh);
- // ctx->dbh = dbhref; //newSVrv( dbh, "DBI::db");
-
-
-
-
-
-//sv_bless(dbhref, gv_stashpv("DBI::db", 0));
- strcpy((char *)ctx->function,imp_dbh->ha_function);
-
-
-
-PerlIO_printf(DBILOGFP, "reg callback DBIc_ACTIVE=%d\n",DBIc_ACTIVE(imp_dbh));
-
- PerlIO_printf(DBILOGFP, " In reg_ha_callback reg OCI_ATTR_FOCBK =%d, OCI_ATTR_EVTCTX=%d\n",OCI_ATTR_EVTCBK,OCI_ATTR_EVTCTX);
+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;
- OCIAttrSet_log_stat(imp_dbh->envhp, (ub4) OCI_HTYPE_ENV,(dvoid *)hacb_fn ,(ub4)0,(ub4)OCI_ATTR_EVTCBK, imp_dbh->errhp, status);
+ if (dbd_verbose >= 5 ) {
+ PerlIO_printf(DBILOGFP, " Register HA callback %s\n",imp_dbh->ha_function);
+ }
- 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);
+ 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;
}
-
[svn:dbd-oracle] r15207 - dbd-oracle/branches/FAN
by byterock