pgpool mysql_pgpool分析二
pgpool就是一個架在數據庫與應用系統之間的中間層,用于實現cluster或分布式數據庫,實現數據庫的大規模集成應用,類以于oracle的Tuxedo;不過這個是開源的,功能上也有一些限制,具體應用去它的官網上去看,下面主要分析它的實現原理
對于replication,它和MysqL一樣是通過傳遞sql實現的,對于分布式存儲,它是把sql經過parse,rewrite之后,生成經過優化后的sql分別在結點上執行,再把結果匯總。
對postgresql的通訊是通過libpq和socket實現的,對于自身多結點的通訊是通過socket實現的,對于一臺機器的多個進程間是通過pipe和unix domain socket通信的
pgpool也和postgresql一樣是多進程的,主要分為main進程,child進程,pcp進程,main進程主要是health check和消息中轉,child進程負責與postgresql通訊,pcp進程負責與其它的pgpool進程通訊和用戶名密碼的檢查,pcp之間的通訊全是用一個字母代表語義,這個通訊協議還需要看看是不是采用的是postgresql中的通訊協議,在pcp目錄下面,還保存了一些用戶管理pgpool的工具
pgpool的數據庫結點分為兩類,第一是node db就是普通的數據庫結點,第二是system db這個在分布式存儲中主要存儲分布的規則,在query cache中用來保存cache,這在一個pgpool的緩沖池中只有一個
在結構體中,第一個最重要的是
typedef struct {
char *listen_addresses; /* hostnames/IP addresses to listen on */
int port; /* port # to bind */
int pcp_port; /* PCP port # to bind */
char *socket_dir; /* pgpool socket directory */
char *pcp_socket_dir; /* PCP socket directory */
int pcp_timeout; /* PCP timeout for an idle client */
int num_init_children; /* # of children initially pre-forked */
int child_life_time; /* if idle for this seconds,child exits */
int connection_life_time; /* if idle for this seconds,connection closes */
int child_max_connections; /* if max_connections received,child exits */
int client_idle_limit; /* If client_idle_limit is n (n > 0),the client is forced to be
disconnected after n seconds idle */
int authentication_timeout; /* maximum time in seconds to complete client authentication */
int max_pool; /* max # of connection pool per child */
char *logdir; /* logging directory */
char *pid_file_name; /* pid file name */
char *backend_socket_dir; /* Unix domain socket directory for the Postgresql server */
int replication_mode; /* replication mode */
int log_connections; /* 0:false,1:true - logs incoming connections */
int log_hostname; /* 0:false,1:true - resolve hostname */
int enable_pool_hba; /* 0:false,1:true - enables pool_hba.conf file authentication */
int load_balance_mode; /* load balance mode */
int replication_stop_on_mismatch; /* if there's a data mismatch between master and secondary
* start degenration to stop replication mode
*/
int replicate_select; /* if non 0,replicate SELECT statement when load balancing is disabled. */
char **reset_query_list; /* comma separated list of quries to be issued at the end of session */
int print_timestamp; /* if non 0,print time stamp to each log line */
int master_slave_mode; /* if non 0,operate in master/slave mode */
int connection_cache; /* if non 0,cache connection pool */
int health_check_timeout; /* health check timeout */
int health_check_period; /* health check period */
char *health_check_user; /* Postgresql user name for health check */
char *failover_command; /* execute command when failover happens */
char *failback_command; /* execute command when failback happens */
/*
* If true,trigger fail over when writing to the backend
* communication socket fails. This is the same behavior of
* pgpool-II 2.2.x or earlier. If set to false,pgpool will report
* an error and disconnect the session.
*/
int fail_over_on_backend_error;
char *recovery_user; /* Postgresql user name for online recovery */
char *recovery_password; /* Postgresql user password for online recovery */
char *recovery_1st_stage_command; /* Online recovery command in 1st stage */
char *recovery_2nd_stage_command; /* Online recovery command in 2nd stage */
int recovery_timeout; /* maximum time in seconds to wait for remote start-up */
int client_idle_limit_in_recovery; /* If > 0,the client is forced to be
* disconnected after n seconds idle
* This parameter is only valid while in recovery 2nd statge */
int insert_lock; /* if non 0,automatically lock table with INSERT to keep SERIAL
data consistency */
int ignore_leading_white_space; /* ignore leading white spaces of each query */
int log_statement; /* 0:false,1: true - logs all sql statements */
int log_per_node_statement; /* 0:false,1: true - logs per node detailed sql statements */
int parallel_mode; /* if non 0,run in parallel query mode */
int enable_query_cache; /* if non 0,use query cache. 0 by default */
char *pgpool2_hostname; /* pgpool2 hostname */
char *system_db_hostname; /* system DB hostname */
int system_db_port; /* system DB port number */
char *system_db_dbname; /* system DB name */
char *system_db_schema; /* system DB schema name */
char *system_db_user; /* user name to access system DB */
char *system_db_password; /* password to access system DB */
char *lobj_lock_table; /* table name to lock for rewriting lo_creat */
BackendDesc *backend_desc; /* Postgresql Server description. Placed on shared memory */
LOAD_BALANCE_STATUS load_balance_status[MAX_NUM_BACKENDS]; /* to remember which DB node is selected for load balancing */
/* followings do not exist in the configuration file */
int current_slot; /* current backend slot # */
int replication_enabled; /* replication mode enabled */
int master_slave_enabled; /* master/slave mode enabled */
int num_reset_queries; /* number of queries in reset_query_list */
/* ssl configuration */
int ssl; /* if non 0,activate ssl support (frontend+backend) */
char *ssl_cert; /* path to ssl certificate (frontend only) */
char *ssl_key; /* path to ssl key (frontend only) */
char *ssl_ca_cert; /* path to root (CA) certificate */
char *ssl_ca_cert_dir; /* path to directory containing CA certificates */
} POOL_CONFIG;
POOL_CONFIG里面保存了pgpool的配置信息,是從配置文件中讀入的,這里面最重要的是BackendDesc *backend_desc,它里面保存了pgpool和數據庫的連接信息,是放在共享內存中,供所有pgpool的child進程共享的。其余的字段看注釋就可以了
每一個BackendInfo對應一個數據庫連接,其實就是postgresql的一個進程
/*
* Postgresql backend descriptor. Placed on shared memory area.
*/
typedef struct {
char backend_hostname[MAX_DB_HOST_NAMELEN]; /* backend host name */
int backend_port; /* backend port numbers */
BACKEND_STATUS backend_status; /* backend status */
double backend_weight; /* normalized backend load balance ratio */
double unnormalized_weight; /* descripted parameter */
char backend_data_directory[MAX_PATH_LENGTH];
} BackendInfo;
typedef struct {int num_backends; /* number of used Postgresql backends */BackendInfo backend_info[MAX_NUM_BACKENDS];} BackendDesc;
相關文章
總結
以上是編程之家為你收集整理的pgpool分析二全部內容,希望文章能夠幫你解決pgpool分析二所遇到的程序開發問題。
如果覺得編程之家網站內容還不錯,歡迎將編程之家網站推薦給程序員好友。
本圖文內容來源于網友網絡收集整理提供,作為學習參考使用,版權屬于原作者。
如您喜歡交流學習經驗,點擊鏈接加入交流1群:1065694478(已滿)交流2群:163560250
總結
以上是生活随笔為你收集整理的pgpool mysql_pgpool分析二的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【JUC】Fork / Join 拆分合
- 下一篇: pgpool mysql_pgpool