static POOL_CONNECTION_POOL *new_connection(POOL_CONNECTION_POOL *p) { /* create master connection */ MASTER_CONNECTION(p) = malloc(sizeof(POOL_CONNECTION_POOL_SLOT)); if (MASTER_CONNECTION(p) == NULL) { pool_error("pool_create_cp: malloc() failed"); return NULL; } create_cp(MASTER_CONNECTION(p), 0); /* initialize Paramter Status save structure */ if (pool_init_params(&MASTER(p)->params)) { return NULL; } p->num = 1; /* number of slots */ /* create secondary connection */ if (DUAL_MODE) { SECONDARY_CONNECTION(p) = malloc(sizeof(POOL_CONNECTION_POOL_SLOT)); if (SECONDARY_CONNECTION(p) == NULL) { pool_error("pool_create_cp: malloc() failed"); return NULL; } create_cp(SECONDARY_CONNECTION(p), 1); /* initialize Paramter Status save structure */ if (pool_init_params(&SECONDARY(p)->params)) { return NULL; } p->num++; /* number of slots */ } return p; }
/* * create actual connections to backends */ static POOL_CONNECTION_POOL *new_connection(POOL_CONNECTION_POOL *p) { POOL_CONNECTION_POOL_SLOT *s; int active_backend_count = 0; int i; for (i=0;i<NUM_BACKENDS;i++) { pool_debug("new_connection: connecting %d backend", i); if (!VALID_BACKEND(i)) { pool_debug("new_connection: skipping slot %d because backend_status = %d", i, BACKEND_INFO(i).backend_status); continue; } s = malloc(sizeof(POOL_CONNECTION_POOL_SLOT)); if (s == NULL) { pool_error("new_connection: malloc() failed"); return NULL; } if (create_cp(s, i) == NULL) { /* connection failed. mark this backend down */ pool_error("new_connection: create_cp() failed"); /* If fail_over_on_backend_error is true, do failover. * Otherwise, just exit this session. */ if (pool_config->fail_over_on_backend_error) { notice_backend_error(i); } else { pool_log("new_connection: do not failover because fail_over_on_backend_error is off"); } child_exit(1); } p->info[i].create_time = time(NULL); p->slots[i] = s; if (pool_init_params(&s->con->params)) { return NULL; } BACKEND_INFO(i).backend_status = CON_UP; active_backend_count++; } if (active_backend_count > 0) { return p; } return NULL; }