@@ -1731,7 +1731,21 @@ static void read_comdb2db_environment_cfg(cdb2_hndl_tp *hndl, const char *comdb2
17311731 pthread_mutex_unlock (& cdb2_sockpool_mutex );
17321732}
17331733
1734- static void only_read_config (cdb2_hndl_tp * , int * ); /* FORWARD */
1734+ struct db_info {
1735+ char name [DBNAME_LEN ];
1736+ char hosts [MAX_NODES ][CDB2HOSTNAME_LEN ];
1737+ int ports [MAX_NODES ];
1738+ int n_hosts ;
1739+ int found ;
1740+ int num ;
1741+ };
1742+
1743+ struct cluster_info {
1744+ struct db_info metadb ;
1745+ struct db_info db ;
1746+ };
1747+
1748+ static void only_read_config (cdb2_hndl_tp * , struct cluster_info * , int * ); /* FORWARD */
17351749
17361750static int cdb2_max_room_num = 0 ;
17371751static int cdb2_has_room_distance = 0 ;
@@ -7962,9 +7976,14 @@ static int cdb2_dbinfo_query(cdb2_hndl_tp *hndl, const char *type, const char *d
79627976 return rc ;
79637977}
79647978
7965- static inline void only_read_config (cdb2_hndl_tp * hndl , int * default_err )
7979+ static inline void only_read_config (cdb2_hndl_tp * hndl , struct cluster_info * c , int * default_err )
79667980{
7967- read_available_comdb2db_configs (NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL );
7981+ char * dbname = hndl -> dbname ;
7982+ strcpy (c -> db .name , dbname );
7983+ strcpy (c -> metadb .name , COMDB2DB );
7984+
7985+ read_available_comdb2db_configs (hndl , c -> metadb .hosts , c -> metadb .name , & c -> metadb .n_hosts , & c -> metadb .num ,
7986+ c -> db .name , c -> db .hosts , & c -> db .n_hosts , & c -> db .num , NULL , NULL );
79687987 if (default_err && strcasecmp (hndl -> type , "default" ) == 0 ) {
79697988 if (cdb2_default_cluster [0 ] != '\0' ) {
79707989 strncpy (hndl -> type , cdb2_default_cluster , sizeof (hndl -> type ) - 1 );
@@ -8213,15 +8232,6 @@ const char *cdb2_dbname(cdb2_hndl_tp *hndl)
82138232 return NULL ;
82148233}
82158234
8216- struct db_info {
8217- char name [DBNAME_LEN ];
8218- char hosts [MAX_NODES ][CDB2HOSTNAME_LEN ];
8219- int ports [MAX_NODES ];
8220- int n_hosts ;
8221- int found ;
8222- int num ;
8223- };
8224-
82258235static void hndl_set_comdb2buf (cdb2_hndl_tp * hndl , COMDB2BUF * sb , int idx )
82268236{
82278237 cdb2buf_settimeout (sb , hndl -> socket_timeout , hndl -> socket_timeout );
@@ -8285,9 +8295,9 @@ static void after_discovery(cdb2_hndl_tp *hndl)
82858295 }
82868296}
82878297
8288- static int get_connection_int (cdb2_hndl_tp * hndl , int * err )
8298+ static int get_connection_int (cdb2_hndl_tp * hndl , struct cluster_info * c , int * err )
82898299{
8290- only_read_config (hndl , err );
8300+ only_read_config (hndl , c , err );
82918301 if (get_dbinfo || * err )
82928302 return -1 ;
82938303 before_discovery (hndl );
@@ -8332,9 +8342,13 @@ static int get_connection(cdb2_hndl_tp *hndl, int *err)
83328342 } else if (get_dbinfo || sockpool_enabled == -1 || cdb2cfg_override ) {
83338343 return -1 ;
83348344 }
8345+ struct cluster_info * c = calloc (1 , sizeof (struct cluster_info ));
8346+ if (!c )
8347+ return -1 ;
83358348 LOG_CALL ("%s: calling get_connection_int\n" , __func__ );
8336- int rc = get_connection_int (hndl , err );
8349+ int rc = get_connection_int (hndl , c , err );
83378350 LOG_CALL ("%s: get_connection_int returned rc %d\n" , __func__ , rc );
8351+ free (c );
83388352 return rc ;
83398353}
83408354
@@ -8391,7 +8405,9 @@ static int configure_from_literal(cdb2_hndl_tp *hndl, const char *type)
83918405 assert (type_copy [0 ] == '@' );
83928406 char * s = type_copy + 1 ; // advance past the '@'
83938407
8394- only_read_config (hndl , NULL ); // don't care about default here
8408+ struct cluster_info * c = calloc (1 , sizeof (struct cluster_info ));
8409+ only_read_config (hndl , c , NULL ); // don't care about default here
8410+ free (c );
83958411
83968412 char * machine ;
83978413 machine = strtok_r (s , "," , & eomachine );
@@ -8921,7 +8937,9 @@ int cdb2_open(cdb2_hndl_tp **handle, const char *dbname, const char *type,
89218937
89228938 if ((hndl -> flags & CDB2_DIRECT_CPU ) || (hndl -> flags & CDB2_ADMIN )) {
89238939 /* Get defaults from comdb2db.cfg */
8924- only_read_config (hndl , & rc );
8940+ struct cluster_info * c = calloc (1 , sizeof (struct cluster_info ));
8941+ only_read_config (hndl , c , & rc );
8942+ free (c );
89258943 if (rc )
89268944 goto out ;
89278945 hndl -> got_dbinfo = 1 ;
0 commit comments