// OpenTopology returns a DB instance to access a topology instance func OpenTopology(host string, port int) (*sql.DB, error) { mysql_uri := fmt.Sprintf("%s:%s@tcp(%s:%d)/?timeout=%ds", config.Config.MySQLTopologyUser, config.Config.MySQLTopologyPassword, host, port, config.Config.MySQLConnectTimeoutSeconds) if config.Config.MySQLTopologyUseMutualTLS { mysql_uri, _ = SetupMySQLTopologyTLS(mysql_uri) } db, _, err := sqlutils.GetDB(mysql_uri) db.SetMaxOpenConns(config.Config.MySQLTopologyMaxPoolConnections) db.SetMaxIdleConns(config.Config.MySQLTopologyMaxPoolConnections) return db, err }
// OpenTopology returns the DB instance for the orchestrator backed database func OpenOrchestrator() (*sql.DB, error) { if config.Config.DatabaselessMode__experimental { return nil, nil } mysql_uri := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?timeout=%ds", config.Config.MySQLOrchestratorUser, config.Config.MySQLOrchestratorPassword, config.Config.MySQLOrchestratorHost, config.Config.MySQLOrchestratorPort, config.Config.MySQLOrchestratorDatabase, config.Config.MySQLConnectTimeoutSeconds) if config.Config.MySQLOrchestratorUseMutualTLS { mysql_uri, _ = SetupMySQLOrchestratorTLS(mysql_uri) } db, fromCache, err := sqlutils.GetDB(mysql_uri) if err == nil && !fromCache { if !config.Config.SkipOrchestratorDatabaseUpdate { initOrchestratorDB(db) } db.SetMaxIdleConns(10) } return db, err }