m_MapperFactory(svc_mapper_factory,
registry, def_mapping),
57m_MaxNumOfConnAttempts(1),
58m_MaxNumOfValidationAttempts(1),
59m_MaxNumOfServerAlternatives(32),
60m_MaxNumOfDispatches(0),
61m_ConnectionTimeout(0),
63m_TryServerToo(
false)
71 const stringsection_name(
"DB_CONNECTION_FACTORY");
92 registry->
GetBool(section_name,
"TRY_SERVER_AFTER_SERVICE",
false);
163 stringvalidator_name;
165validator_name = validator->
GetName();
190 const string& srv_name,
195, m_ServerName(srv_name)
238: driver_ctx(driver_ctx_in), service_info(service_info_in),
251unique_ptr<CDB_Connection> t_con;
266}
else if(ctx_impl !=
NULL) {
277 if( dsp_srv.
Empty() ) {
285 stringsingle_server(params.
GetParam(
"single_server"));
286 stringis_pooled(params.
GetParam(
"is_pooled"));
289 if(single_server !=
"true" 301 if(is_pooled ==
"true") {
305}
else if(single_server !=
"true"&& is_pooled ==
"true") {
338 if(t_con.get() ==
NULL) {
340 if(single_server !=
"true") {
360 if(t_con.get() ==
nullptr) {
366 returnt_con.release();
378 booldo_not_dispatch = params.
GetParam(
"do_not_dispatch") ==
"true";
385list<TSvrRef> tried_servers;
386 boolfull_retry_made =
false;
389 unsigned intalternatives
390=
static_cast<unsigned int>(service_info.
GetOptions().size());
391 if(alternatives < 1) {
392alternatives =
min(2U, max_alternatives);
394alternatives =
min(alternatives * 2U, max_alternatives);
397 if( !do_not_dispatch && !service_name.empty() ) {
399(service_info, params.
GetParam(
"pool_name"),
401params.
GetParam(
"is_pooled") ==
"true"));
403 for( ; !t_con && alternatives > 0; --alternatives ) {
406 if(do_not_dispatch) {
414 else if(!service_name.empty()) {
416 ctx.excluded =
ctx.service_info.GetExcluded();
418dsp_srv = balancer->GetServer(&t_con, ¶ms);
420 ctx.errors.push_back(ex.
Clone());
424 if(dsp_srv.
Empty()) {
427 if(dsp_srv.
Empty()) {
431 if(tried_servers.empty()
432&& (dsp_srv.
Empty()
433|| (dsp_srv->
GetName() == service_name
437 _TRACE(
"List of servers for service "<< service_name
438<<
" is exhausted. Giving excluded a try.");
443 if(dsp_srv.
Empty()) {
444 ctx.errors.push_back(
447 "Service mapper didn't return any server for " 452 if(dsp_srv->
GetName() == service_name
454&& !tried_servers.empty())
456 if(full_retry_made) {
458 ctx.errors.push_back(
462 "No more servers to try (didn't try " 463+ service_name +
" as server name)",
469 _TRACE(
"List of servers for service "<< service_name
470<<
" is exhausted. Giving excluded a try.");
473 ITERATE(list<TSvrRef>, it, tried_servers) {
480(service_info, params.
GetParam(
"pool_name"),
483full_retry_made =
true;
489cur_srv_name = dsp_srv->
GetName();
490cur_host = dsp_srv->
GetHost();
491cur_port = dsp_srv->
GetPort();
492}
else if(params.
GetParam(
"pool_name").empty()) {
494(
"Neither server name nor pool name provided.", 111000);
505 boolneed_exclude =
true;
509 for(; attempts > 0; --attempts) {
521 if(t_con !=
NULL) {
522need_exclude =
false;
527 ctx.handlers.PostMsg(&ex);
533need_exclude =
false;
538 if(do_not_dispatch) {
542 if(cur_srv_name == service_name && cur_host == 0 && cur_port == 0
548 ctx.errors.push_back(
551 "No more services/servers to try",
558balancer->LocallyPenalize(
ctx.last_tried);
567tried_servers.push_back(
ctx.last_tried);
576 ctx.errors.push_back(
579 "Can't try any more alternatives (max number is " 595<<
", port "<< params.
GetPort());
603unique_ptr<CDB_Connection>
conn;
605 if(candidate ==
NULL) {
606 ctx.excluded =
ctx.service_info.GetExcluded();
610 conn.reset(candidate);
613 ctx.last_tried.Reset(
ctx.service_info.GetDispatchedServer());
614 if(
ctx.last_tried.Empty()) {
615 ctx.last_tried.Reset
626 if(
conn->IsReusable() && !params.
GetParam(
"pool_name").empty()) {
627 if(
conn->Host() != 0) {
631 ctx.tried.back() =
conn->ServerName();
635 if(
conn->Host() == 0) {
657 if(
conn->IsReusable()) {
663 "Validation failed against " 668 ctx.handlers.PostMsg(&ex);
677 if(
conn->IsReusable()) {
682 ctx.handlers.PostMsg(&ex);
696 ctx.tried.pop_back();
697 conn->FinishOpening();
700 ctx.last_tried.Reset(
ctx.service_info.GetDispatchedServer());
701 if(
ctx.last_tried.Empty()) {
702 ctx.last_tried.Reset
707 ctx.errors.push_back(
710 "Parameters prohibited creating connection",
713 return conn.release();
718 const string& service_name,
719list<string>* serv_list)
728 const string& service_name,
729 const string& server)
733 if( !server.empty() ) {
738service_info.SetDispatchedServer(svr);
753 if(rctx.
GetProperty(
"_dbapi_last_rid") == rid_str) {
758rctx.
SetProperty(
"_dbapi_connection_no", connection_no);
759 returnconnection_no +
".dbapi_";
762rctx.
SetProperty(
"_dbapi_connection_no",
"1");
781 if(dsp_srv.
Empty()) {
783dsp_srv.
Reset(&stub_dsp_srv);
787 const char* status_str =
"???";
788 switch(
ctx.conn_status) {
790status_str =
"valid";
793status_str =
"invalid";
796status_str =
"temporarily-invalid";
799extra.
Print(prefix +
"conn_status", status_str);
802extra.
Print(prefix +
"resource", service);
804 if( !dsp_srv->
GetName().empty() ) {
805extra.
Print(prefix +
"server_name", dsp_srv->
GetName());
806}
else if(connection !=
NULL&& !connection->
ServerName().empty()) {
810 if(dsp_srv->
GetHost() != 0) {
811extra.
Print(prefix +
"server_ip",
813}
else if(params.
GetHost() != 0) {
815}
else if(connection !=
NULL&& connection->
Host() != 0) {
816extra.
Print(prefix +
"server_ip",
820 if(dsp_srv->
GetPort() != 0) {
821extra.
Print(prefix +
"server_port", dsp_srv->
GetPort());
822}
else if(params.
GetPort() != 0) {
823extra.
Print(prefix +
"server_port", params.
GetPort());
824}
else if(connection !=
NULL&& connection->
Port() != 0) {
825extra.
Print(prefix +
"server_port", connection->
Port());
842 if(connection !=
NULL&& !connection->
PoolName().empty() ) {
844}
else if( !params.
GetParam(
"pool_name").empty() ) {
845extra.
Print(prefix +
"pool", params.
GetParam(
"pool_name"));
849extra.
Print(prefix +
"validator", validator->
GetName());
853 stringdriver_name = ((connection ==
NULL)
854?
ctx.driver_ctx.GetDriverName()
856 if( !driver_name.empty() ) {
857extra.
Print(prefix +
"driver", driver_name);
863 size_tretries =
ctx.tried.size();
867extra.
Print(prefix +
"retries", retries);
868 if( !
ctx.tried.empty() ) {
871 if( !
ctx.excluded.empty() ) {
872extra.
Print(prefix +
"excluded",
ctx.excluded);
874 if(connection !=
NULL) {
878 doublemake_valid_connection_elapsed =
ctx.make_valid_connection_sw.Elapsed();
879 if(make_valid_connection_elapsed != 0.0) {
880extra.
Print(prefix +
"make_valid_connection_time",
881make_valid_connection_elapsed);
884 doubledispatch_server_name_elapsed =
ctx.dispatch_server_name_sw.Elapsed();
885 if(dispatch_server_name_elapsed != 0.0) {
886extra.
Print(prefix +
"dispatch_server_name_time",
887dispatch_server_name_elapsed);
896 if(m_ServiceName.find(
':') !=
NPOS) {
897 if(m_Options.empty()) {
903host =
key.GetHost();
904port =
key.GetPort();
911(m_ServiceName, host, port, 1.0));
913}
else if(m_Options.empty()) {
914m_Mapper->GetServerOptions(m_ServiceName, &m_Options);
921 boolrefresh =
false;
922 for(
const auto&it : m_Options) {
923 if(it->GetExpireTime() < now) {
930m_Mapper->GetServerOptions(m_ServiceName, &options);
931 if( !options.empty() ) {
932 swap(options, m_Options);
942 if(server.
Empty()) {
948m_Dispatched = server;
954++m_NumValidationFailures;
955 autolimit = m_Factory.GetMaxNumOfValidationAttempts();
957 if(limit != 0 && m_NumValidationFailures >= limit) {
965 if( !m_Mapper->HasExclusions(m_ServiceName) ) {
969m_Mapper->GetServerOptions(m_ServiceName, &m_Options);
971 for(
const auto&it : m_Options) {
972 if(it->IsExcluded()) {
974 if(it->GetHost() != 0) {
976 if(it->GetPort() != 0) {
979}
else if( !it->GetName().empty() ) {
980exclusion = it->GetName();
982 if( !exclusion.empty() ) {
983 result+= delim + exclusion;
998m_DBServiceMapper(mapper)
1006 auto& entry = m_ServiceInfoMap[service_name];
1007 if(entry.Empty()) {
1009 new CServiceInfo(*m_Parent, *m_DBServiceMapper, service_name));
1020m_SvcMapperFactory(svc_mapper_factory),
1022m_DefMapping(def_mapping)
1025 "Database service name to server name mapper was not " 1026 "defined properly.",
1038 if(m_SvcMapperFactory) {
1044 if(m_SvcMapperFactory) {
1045 returnm_SvcMapperFactory(m_Registry);
1110 string result(
"CConnValidatorCoR");
1115 result+= (*vr_it)->GetName();
1224unique_ptr<CDB_LangCmd> set_cmd(
conn.LangCmd(
"SELECT id FROM sysobjects"));
1226set_cmd->DumpResults();
1231 conn.SetDatabaseName(
"master");
1242 string result(
"CTrivialConnValidator");
void Push(const CRef< IConnValidator > &validator)
virtual EConnStatus Validate(CDB_Connection &conn)
virtual string GetName(void) const
vector< CRef< IConnValidator > > TValidators
virtual ~CConnValidatorCoR(void)
CRef< IConnValidator > Top(void) const
CMapperFactory(IDBServiceMapper::TFactory svc_mapper_factory, const IRegistry *registry, EDefaultMapping def_mapping)
IDBServiceMapper * Make(void) const
const IDBServiceMapper::TFactory m_SvcMapperFactory
CRuntimeData(const CDBConnectionFactory &parent, const CRef< IDBServiceMapper > &mapper)
const IDBServiceMapper & GetDBServiceMapper(void) const
CServiceInfo & GetServiceInfo(const string &service_name)
string GetMapperName(void) const
bool HasExclusions(void) const
void Exclude(const TSvrRef &server)
TSvrRef GetDispatchedServer(void) const
void SetDispatchedServer(const TSvrRef &server)
unsigned int GetNumOfDispatches(void) const
void IncNumOfValidationFailures(const TSvrRef &dsp_srv)
TSvrRef GetMappedServer(void) override
unsigned int GetNumOfValidationFailures(void) const
const TOptions & GetOptions(void) override
unsigned int GetMaxNumOfServerAlternatives(void) const
void SetMaxNumOfConnAttempts(unsigned int max_num)
void SetMaxNumOfDispatches(unsigned int max_num)
void x_LogConnection(const SOpeningContext &ctx, const CDB_Connection *connection, const CDBConnParams ¶ms)
void SetLoginTimeout(unsigned int timeout)
CDBConnectionFactory(IDBServiceMapper::TFactory svc_mapper_factory, const IRegistry *registry=NULL, EDefaultMapping def_mapping=eUseDefaultMapper)
CDBConnectionFactory won't take ownership of registry.
unsigned int m_MaxNumOfServerAlternatives
void SetMaxNumOfServerAlternatives(unsigned int max_num)
unsigned int GetMaxNumOfConnAttempts(void) const
friend class CServiceInfo
void ConfigureFromRegistry(const IRegistry *registry=NULL)
unsigned int m_MaxNumOfConnAttempts
void GetServersList(const string &validator_name, const string &service_name, list< string > *serv_list)
unsigned int m_MaxNumOfValidationAttempts
CDB_Connection * DispatchServerName(SOpeningContext &ctx, const CDBConnParams ¶ms)
void SetConnectionTimeout(unsigned int timeout)
CRuntimeData & GetRuntimeData(const CRef< IConnValidator > validator)
CFastMutex m_ValidatorSetMutex
unsigned int m_LoginTimeout
virtual void Configure(const IRegistry *registry=NULL)
Configure connection policy using registry.
void WorkWithSingleServer(const string &validator_name, const string &service_name, const string &server)
CDB_Connection * MakeValidConnection(SOpeningContext &ctx, const CDBConnParams ¶ms, CDB_Connection *candidate=NULL)
unsigned int GetMaxNumOfDispatches(void) const
unsigned int m_ConnectionTimeout
unsigned int GetMaxNumOfValidationAttempts(void) const
const CMapperFactory m_MapperFactory
unsigned int m_MaxNumOfDispatches
virtual CDB_Connection * MakeDBConnection(I_DriverContext &ctx, const CDBConnParams ¶ms, CDB_UserHandler::TExceptions &exceptions)
Create new connection object for the given context and connection attributes.
void SetMaxNumOfValidationAttempts(unsigned int max_num)
TValidatorSet m_ValidatorSet
virtual ~CDBGiveUpFactory(void)
CDBGiveUpFactory(IDBServiceMapper::TFactory svc_mapper_factory, const IRegistry *registry=NULL, EDefaultMapping def_mapping=eUseDefaultMapper)
CDBRedispatchFactory(IDBServiceMapper::TFactory svc_mapper_factory, const IRegistry *registry=NULL, EDefaultMapping def_mapping=eUseDefaultMapper)
virtual ~CDBRedispatchFactory(void)
CDBServerOption â CDBServer extended with additional information that helps maintain a balanced pool ...
time_t GetExpireTime(void) const
Uint2 GetPort(void) const
const string & GetName(void) const
Uint4 GetHost(void) const
virtual Uint4 GetHost(void) const
virtual Uint2 GetPort(void) const
const string m_ServerName
impl::CDBHandlerStack & SetOpeningMsgHandlers(void)
impl::CDBHandlerStack m_OpeningMsgHandlers
virtual string GetServerName(void) const
CDB_DBLB_Delegate(const string &srv_name, Uint4 host, Uint2 port, const CDBConnParams &other)
virtual const impl::CDBHandlerStack & GetOpeningMsgHandlers(void) const
virtual ~CDB_DBLB_Delegate(void)
Lightweight representation of just a host and a port.
static CNcbiApplication * Instance(void)
Singleton method.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
CTrivialConnValidator(const string &db_name, int attr=eDefaultValidateAttr)
virtual string GetName(void) const
const string & GetDBName(void) const
virtual ~CTrivialConnValidator(void)
@ eKeepModifiedConnection
virtual EConnStatus Validate(CDB_Connection &conn)
virtual EConnStatus ValidateException(const CDB_Exception &ex)
virtual string GetName(void) const
static CDB_Connection * CtxMakeConnection(I_DriverContext &ctx, const CDBConnParams ¶ms)
Helper method to provide access to a protected method in I_DriverContext for child classses.
virtual bool RecordServer(I_ConnectionExtra &) const
Given a connection that succeeded even though this service mapper was unable to identify a good serve...
list< CRef< CDBServerOption > > TOptions
IDBServiceMapper *(* TFactory)(const IRegistry *registry)
virtual void GetServersList(const string &, list< string > *serv_list) const
Get list of all servers for the given service disregarding any exclusions.
size_t GetSize(void) const
void PostMsg(CDB_Exception *ex, const TDbgInfo *dbg_info=NULL, const CConnection *connection=NULL, const CDBParams *params=NULL) const
void Push(CDB_UserHandler *h, EOwnership ownership=eNoOwnership)
const CDBHandlerStack & GetCtxHandlerStack(void) const
container_type::iterator iterator
const_iterator end() const
iterator_bool insert(const value_type &val)
container_type::value_type value_type
const_iterator find(const key_type &key) const
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
static string s_GetNextLogPrefix(void)
EDefaultMapping
CDBConnectionFactory.
Help distribute connections within a pool across servers.
static CS_CONNECTION * conn
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
@ eRetriable_No
It makes no sense to retry the action.
@ eTakeOwnership
An object can take ownership of another.
virtual CDB_Exception * Clone(void) const
int GetDBErrCode(void) const
#define DATABASE_DRIVER_ERROR(message, err_code)
static CDB_UserHandler & GetDefault(void)
#define CHECK_DRIVER_ERROR(failed, message, err_code)
EErrCode
Error types that can be generated.
deque< CDB_Exception * > TExceptions
Exception container type.
virtual const impl::CDBHandlerStack & GetOpeningMsgHandlers(void) const =0
virtual Uint4 GetHost(void) const =0
virtual string GetServerName(void) const =0
virtual Uint2 GetPort(void) const =0
virtual string GetDatabaseName(void) const =0
virtual CRef< IConnValidator > GetConnValidator(void) const =0
virtual string GetUserName(void) const =0
virtual string GetParam(const string &key) const =0
Parameters, which are not listed above explicitly, should be retrieved via SetParam() method.
virtual string GetDriverName(void) const
virtual Uint4 Host() const
Get the host.
unsigned int GetReuseCount() const
Indicate how many times (if at all) this connection has been previously used.
virtual const string & PoolName() const
Find out which connection pool this connection belongs to.
virtual const string & ServerName() const
Get the server name.
virtual Uint2 Port() const
Get the port.
CDiagContext_Extra & Print(const string &name, const string &value)
The method does not print the argument, but adds it to the string.
CDiagContext & GetDiagContext(void)
Get diag context instance.
CDiagContext_Extra Extra(void) const
Create a temporary CDiagContext_Extra object.
#define DIAG_COMPILE_INFO
Make compile time diagnostic information object to use in CNcbiDiag and CException.
const string & GetProperty(const string &name) const
Get property value or empty string.
void SetProperty(const string &name, const string &value)
Add/change property.
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
TCount GetRequestID(void) const
Get request ID (or zero if not set).
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
@ eDiag_Error
Error message.
@ eDiag_Warning
Warning message.
@ eDiagSevMax
Verbosity level for max. severity.
void Warning(CExceptionArgs_Base &args)
bool NotNull(void) const THROWS_NONE
Check if pointer is not null â same effect as NotEmpty().
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
void Reset(void)
Reset reference object.
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty â pointing to an object and has a non-null value.
TObjectType * Release(void)
Release a reference to the object and return a pointer to the object.
bool Empty(void) const THROWS_NONE
Check if CRef is empty â not pointing to any object, which means having a null value.
uint32_t Uint4
4-byte (32-bit) unsigned integer
uint16_t Uint2
2-byte (16-bit) unsigned integer
virtual bool GetBool(const string §ion, const string &name, bool default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get boolean value of specified parameter name.
virtual int GetInt(const string §ion, const string &name, int default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get integer value of specified parameter name.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static TNumeric StringToNumeric(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to a numeric value.
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
unsigned short m_Port
TCP port to listen on.
CTime CurrentTime(CTime::ETimeZone tz=CTime::eLocal, CTime::ETimeZonePrecision tzp=CTime::eTZPrecisionDefault)
time_t GetTimeT(void) const
Get time in time_t format.
@ eUTC
UTC (Universal Coordinated Time)
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
string ConvertN2A(Uint4 host)
const struct ncbi::grid::netcache::search::fields::KEY key
CRef< CDBServer > TSvrRef
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines CRequestContext class for NCBI C++ diagnostic API.
IConnValidator::EConnStatus conn_status
SOpeningContext(I_DriverContext &driver_ctx_in, CServiceInfo &service_info_in, CDB_UserHandler::TExceptions &exceptions)
impl::CDBHandlerStack handlers
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4