48
48
49
49
#include < iostream>
50
50
51
+ // Error numbers to set the drop_sess flag in sessionRelease()
52
+ #define DPI_CONNERR_INVALID_SESS 22
53
+ #define DPI_CONNERR_SESS_KILLED 28
54
+ #define DPI_CONNERR_SESS_MARKED_KILL 31
55
+ #define DPI_CONNERR_SESS_TERM_NO_REPLY 45
56
+ #define DPI_CONNERR_ORA_NOT_LOGGED_ON 1012
57
+ #define DPI_CONNERR_MAX_IDLE_TIMEOUT 2396
58
+
51
59
using namespace std ;
52
60
53
61
@@ -80,7 +88,7 @@ ConnImpl::ConnImpl(EnvImpl *env, OCIEnv *envh, bool externalAuth,
80
88
81
89
try : env_(env), pool_(NULL ),
82
90
envh_(envh), errh_(NULL ), auth_(NULL ), svch_(NULL ), sessh_(NULL ),
83
- hasTxn_(false )
91
+ hasTxn_(false ), srvh_( NULL ), dropConn_( false )
84
92
{
85
93
86
94
this ->initConnImpl ( false , externalAuth, connClass,
@@ -122,7 +130,7 @@ ConnImpl::ConnImpl(PoolImpl *pool, OCIEnv *envh, bool externalAuth,
122
130
123
131
try : env_(NULL ), pool_(pool),
124
132
envh_(envh), errh_(NULL ), auth_(NULL ),
125
- svch_(NULL ), sessh_(NULL ), hasTxn_(false )
133
+ svch_(NULL ), sessh_(NULL ), hasTxn_(false ), srvh_( NULL ), dropConn_( false )
126
134
{
127
135
this ->initConnImpl ( true , externalAuth, connClass, poolName, poolNameLen,
128
136
" " , " " );
@@ -473,6 +481,46 @@ void ConnImpl::breakExecution()
473
481
}
474
482
}
475
483
484
+ /* ****************************************************************************/
485
+ /*
486
+ DESCRIPTION
487
+ set the flag if the non-recoverable error happens to connection
488
+
489
+ PARAMETERS
490
+ errNum - Error number
491
+
492
+ RETURNS:
493
+ -NONE_
494
+ */
495
+ void ConnImpl::setErrState ( int errNum )
496
+ {
497
+ /*
498
+ * This flag applicable for only Pool, non pooled connection anyway gets
499
+ * terminated upon release. This code is NOT thread-safe. But, we are only
500
+ * setting the flag to TRUE - multiple threads can try and only will update
501
+ * to TRUE only, so it is okay setting this flag.
502
+ */
503
+
504
+ if ( pool_ )
505
+ {
506
+ switch ( errNum )
507
+ {
508
+ // Error numbers to set drop_sess flag
509
+ case DPI_CONNERR_INVALID_SESS:
510
+ case DPI_CONNERR_SESS_KILLED:
511
+ case DPI_CONNERR_SESS_MARKED_KILL:
512
+ case DPI_CONNERR_SESS_TERM_NO_REPLY:
513
+ case DPI_CONNERR_ORA_NOT_LOGGED_ON:
514
+ case DPI_CONNERR_MAX_IDLE_TIMEOUT:
515
+ dropConn_ = true ;
516
+ break ;
517
+
518
+ default :
519
+ break ;
520
+ }
521
+ }
522
+ }
523
+
476
524
477
525
/* ---------------------------------------------------------------------------
478
526
PRIVATE METHODS
@@ -499,7 +547,6 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
499
547
const string& connClass, OraText *poolNmRconnStr,
500
548
ub4 nameLen, const string &user, const string &password )
501
549
{
502
- OCIServer *srvh = NULL ;
503
550
ub4 mode = OCI_DEFAULT;
504
551
ub2 csid = 0 ;
505
552
@@ -551,14 +598,15 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
551
598
OCI_ATTR_SESSION, errh_ ), errh_ );
552
599
553
600
// Initialize the server handle from service handle
554
- ociCall ( OCIAttrGet ( svch_, OCI_HTYPE_SVCCTX, ( void * ) &srvh , 0 ,
601
+ ociCall ( OCIAttrGet ( svch_, OCI_HTYPE_SVCCTX, ( void * ) &srvh_ , 0 ,
555
602
( ub4 ) OCI_ATTR_SERVER, errh_ ), errh_ );
556
603
557
604
// Get the DBCHARSET from server
558
- ociCall ( OCIAttrGet ( srvh , ( ub4 ) OCI_HTYPE_SERVER, ( void * ) &csid,
605
+ ociCall ( OCIAttrGet ( srvh_ , ( ub4 ) OCI_HTYPE_SERVER, ( void * ) &csid,
559
606
( ub4 * ) 0 , ( ub4 ) OCI_ATTR_CHARSET_ID, errh_ ),
560
607
errh_ );
561
- csratio_ = getCsRatio ( csid );
608
+
609
+ csratio_ = getCsRatio ( csid );
562
610
}
563
611
564
612
/* ****************************************************************************/
@@ -579,9 +627,25 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
579
627
580
628
void ConnImpl::cleanup ()
581
629
{
630
+ ub4 relMode = OCI_DEFAULT;
631
+ ub4 serverStatus = OCI_SERVER_NORMAL;
632
+
582
633
if (svch_)
583
634
{
584
- OCISessionRelease (svch_, errh_, NULL , 0 , OCI_DEFAULT);
635
+ if ( pool_ )
636
+ {
637
+ // Get the connection status
638
+ if ( !dropConn_ )
639
+ ociCall ( OCIAttrGet ( ( void * ) srvh_, OCI_HTYPE_SERVER,
640
+ ( void * ) &serverStatus, ( ub4 * ) 0 ,
641
+ OCI_ATTR_SERVER_STATUS, errh_ ), errh_ );
642
+
643
+ // Remove the session from pool in case of unusable
644
+ if ( dropConn_ || ( serverStatus != OCI_SERVER_NORMAL ) )
645
+ relMode |= OCI_SESSRLS_DROPSESS;
646
+ }
647
+
648
+ OCISessionRelease (svch_, errh_, NULL , 0 , relMode);
585
649
svch_ = NULL ;
586
650
}
587
651
0 commit comments