library/src/databases/bpdb/BP-DB.cc
// Attempts to checkout/fetch a mariadb connection which is available and ready for
// interaction with a bpdb handle.
Attempts to checkout/fetch a mariadb connection which is available and ready for
interaction with a bpdb handle.
Attempts to checkout / fetch a mariadb connection which is available and ready for interaction with a bpdb handle .
P_BP_MYSQL_SESSION BP_DBCheckOutAvailableMariadbConnection(P_BPDB bpdb)
{
	if(!bpdb)
		return NULL;
	if(!bpdb->system_hreg)
		return NULL;
	BPDB_ENTER_CRITICAL_SECTION;
	char * lookup_path[] = { "mariadb_connections", NULL };
	BP_HASH_ITER_FROM_LOOKUP_PATH_OPEN(bpdb->system_hreg, (char **) &lookup_path, connection_iter)
	{
		P_BP_MYSQL_SESSION * session_lookup = (P_BP_MYSQL_SESSION *) connection_iter->data;
		if(!*session_lookup)
		{
			BP_DBAddErrorMsg(bpdb, "BP_DBCheckOutAvailableMariadbConnection found NULL session lookup during search for available connection.  Potentially corrupt pool detected.");
			BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN(NULL);
		}
		P_BP_MYSQL_SESSION mysqli = *session_lookup;
		if(mysqli->pool_available)
		{
			mysqli->pool_available = BP_FALSE;
			BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN(mysqli);
		}
		else
		{
		}
	} BP_HASH_ITER_FROM_LOOKUP_PATH_CLOSE;
	BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN(NULL);
}
P_BP_MYSQL_SESSION BP_DBCheckOutAvailableMariadbConnection ( P_BPDB bpdb ) { if ( ! bpdb ) return NULL ; if ( ! bpdb -> system_hreg ) return NULL ; BPDB_ENTER_CRITICAL_SECTION ; char * lookup_path [ ] = { " " , NULL } ; BP_HASH_ITER_FROM_LOOKUP_PATH_OPEN ( bpdb -> system_hreg , ( char * * ) & lookup_path , connection_iter ) { P_BP_MYSQL_SESSION * session_lookup = ( P_BP_MYSQL_SESSION * ) connection_iter -> data ; if ( ! * session_lookup ) { BP_DBAddErrorMsg ( bpdb , " " ) ; BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN ( NULL ) ; } P_BP_MYSQL_SESSION mysqli = * session_lookup ; if ( mysqli -> pool_available ) { mysqli -> pool_available = BP_FALSE ; BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN ( mysqli ) ; } else { } } BP_HASH_ITER_FROM_LOOKUP_PATH_CLOSE ; BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN ( NULL ) ; }
Attempts to checkout/fetch a mariadb connection which is available and ready for
interaction with a bpdb handle.
Attempts to checkout / fetch a mariadb connection which is available and ready for interaction with a bpdb handle .
// ensure we have a bpdb structure // enter critical section // set lookup path to the mariadb connections table // open an iterator to walk all connections // set session lookup // exit if there is no session to deref into // leave critical section and return // create mysqli reference // if the pool entry is available, return the mysqli // only uncomment if you need to debug the loop // BP_DBAddErrorMsg(bpdb, "BP_DBCheckOutAvailableMariadbConnection reports that pool is not available?"); // return null if we can't find a connection which hasn't been checked out