Do configuration outside of constructors

Configuration errors can be resolved before the instance is created. This
avoids the unnecessary throws that were generated when an error occured.

As the configuration is stored in the router, the router sessions can use
a pointer to it instead of copying it locally. This should avoid some
unnecessary copying if more complex configuration parameters are added.
This commit is contained in:
Markus Mäkelä
2017-03-27 18:37:57 +03:00
parent b9fae58891
commit f5a259ba57
5 changed files with 112 additions and 89 deletions

View File

@ -24,6 +24,8 @@
using std::string;
using std::set;
using schemarouter::Config;
using schemarouter::Stats;
class SchemaRouterSession;
@ -43,19 +45,12 @@ private:
friend class SchemaRouterSession;
/** Internal functions */
SchemaRouter(SERVICE *service, char **options);
SchemaRouter(SERVICE *service, Config& config);
/** Member variables */
schemarouter_config_t m_config; /*< expanded config info from SERVICE */
Config m_config; /*< expanded config info from SERVICE */
ShardManager m_shard_manager; /*< Shard maps hashed by user name */
SERVICE* m_service; /*< Pointer to service */
SPINLOCK m_lock; /*< Lock for the instance data */
ROUTER_STATS m_stats; /*< Statistics for this router */
set<string> m_ignored_dbs; /*< List of databases to ignore when the
* database mapping finds multiple servers
* with the same database */
pcre2_code* m_ignore_regex; /*< Databases matching this regex will
* not cause the session to be terminated
* if they are found on more than one server. */
pcre2_match_data* m_ignore_match_data;
Stats m_stats; /*< Statistics for this router */
};