static char *build_client_final_message(fe_scram_state *state);
static bool verify_server_signature(fe_scram_state *state);
static void calculate_client_proof(fe_scram_state *state,
- const char *client_final_message_without_proof,
- uint8 *result);
+ const char *client_final_message_without_proof,
+ uint8 *result);
static void read_client_first_message(scram_state *state, char *input);
static void read_client_final_message(scram_state *state, char *input);
static bool verify_client_proof(scram_state *state);
static bool verify_final_nonce(scram_state *state);
static bool parse_scram_verifier(const char *verifier, int *iterations,
- char **salt, uint8 *stored_key, uint8 *server_key);
+ char **salt, uint8 *stored_key, uint8 *server_key);
static void mock_scram_verifier(const char *username, int *iterations,
- char **salt, uint8 *stored_key, uint8 *server_key);
+ char **salt, uint8 *stored_key, uint8 *server_key);
static bool is_scram_printable(char *p);
static char *sanitize_char(char c);
static char *GetMockAuthenticationNonce(void);
char *server_signature_base64;
int siglen;
scram_HMAC_ctx ctx;
- char *res;
+ char *res;
/* calculate ServerSignature */
scram_HMAC_init(&ctx, state->ServerKey, SCRAM_KEY_LEN);
#define MAX_SASL_PAYLOAD_LEN 1024
-static void pool_send_backend_key_data(POOL_CONNECTION * frontend, int pid,
+static void pool_send_backend_key_data(POOL_CONNECTION *frontend, int pid,
char *key, int32 keylen, int protoMajor);
-static int do_clear_text_password(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth, int protoMajor);
-static void pool_send_auth_fail(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * cp);
-static int do_md5(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth, int protoMajor,
- char *storedPassword, PasswordType passwordType);
-static void send_md5auth_request(POOL_CONNECTION * frontend, int protoMajor, char *salt);
-static int read_password_packet(POOL_CONNECTION * frontend, int protoMajor, char *password, int *pwdSize);
-static int send_password_packet(POOL_CONNECTION * backend, int protoMajor, char *password);
-static int send_auth_ok(POOL_CONNECTION * frontend, int protoMajor);
-static void sendAuthRequest(POOL_CONNECTION * frontend, int protoMajor, int32 auth_req_type, char *extradata, int extralen);
-
-static int pg_SASL_continue(POOL_CONNECTION * backend, char *payload, int payloadlen, void *sasl_state, bool final);
-static void *pg_SASL_init(POOL_CONNECTION * backend, char *payload, int payloadlen, char *username, char *storedPassword);
-static bool do_SCRAM(POOL_CONNECTION * frontend, POOL_CONNECTION * backend, int protoMajor, int message_length,
- char *username, char *storedPassword, PasswordType passwordType);
-static void authenticate_frontend_md5(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth, int protoMajor);
-static void authenticate_frontend_cert(POOL_CONNECTION * frontend);
-static void authenticate_frontend_SCRAM(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth);
-static void authenticate_frontend_clear_text(POOL_CONNECTION * frontend);
-static bool get_auth_password(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth,
- char **password, PasswordType *passwordType);
-static void ProcessNegotiateProtocol(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * cp);
+static int do_clear_text_password(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth, int protoMajor);
+static void pool_send_auth_fail(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp);
+static int do_md5(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth, int protoMajor,
+ char *storedPassword, PasswordType passwordType);
+static void send_md5auth_request(POOL_CONNECTION *frontend, int protoMajor, char *salt);
+static int read_password_packet(POOL_CONNECTION *frontend, int protoMajor, char *password, int *pwdSize);
+static int send_password_packet(POOL_CONNECTION *backend, int protoMajor, char *password);
+static int send_auth_ok(POOL_CONNECTION *frontend, int protoMajor);
+static void sendAuthRequest(POOL_CONNECTION *frontend, int protoMajor, int32 auth_req_type, char *extradata, int extralen);
+
+static int pg_SASL_continue(POOL_CONNECTION *backend, char *payload, int payloadlen, void *sasl_state, bool final);
+static void *pg_SASL_init(POOL_CONNECTION *backend, char *payload, int payloadlen, char *username, char *storedPassword);
+static bool do_SCRAM(POOL_CONNECTION *frontend, POOL_CONNECTION *backend, int protoMajor, int message_length,
+ char *username, char *storedPassword, PasswordType passwordType);
+static void authenticate_frontend_md5(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth, int protoMajor);
+static void authenticate_frontend_cert(POOL_CONNECTION *frontend);
+static void authenticate_frontend_SCRAM(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth);
+static void authenticate_frontend_clear_text(POOL_CONNECTION *frontend);
+static bool get_auth_password(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth,
+ char **password, PasswordType *passwordType);
+static void ProcessNegotiateProtocol(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp);
/*
* Do authentication. Assuming the only caller is
* make_persistent_db_connection().
*/
void
-connection_do_auth(POOL_CONNECTION_POOL_SLOT * cp, char *password)
+connection_do_auth(POOL_CONNECTION_POOL_SLOT *cp, char *password)
{
char kind;
int length;
switch (kind)
{
- char *p;
- int32 keylen;
+ char *p;
+ int32 keylen;
case 'K': /* backend key data */
keydata_done = true;
{
ereport(ERROR,
(errmsg("failed to authenticate"),
- errdetail("invalid backend key data length. received %d bytes exceeding %d",
+ errdetail("invalid backend key data length. received %d bytes exceeding %d",
ntohl(length), MAX_CANCELKEY_LENGTH)));
}
* 0.
*/
int
-pool_do_auth(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * cp)
+pool_do_auth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp)
{
signed char kind;
int pid;
int i;
int message_length = 0;
StartupPacket *sp;
- int32 keylen; /* cancel key length */
- char cancel_key[MAX_CANCELKEY_LENGTH];
- char *p;
+ int32 keylen; /* cancel key length */
+ char cancel_key[MAX_CANCELKEY_LENGTH];
+ char *p;
protoMajor = MAIN_CONNECTION(cp)->sp->major;
&password, &passwordType) == false)
{
/*
- * We do not have any password, we can still get the password
- * from client using plain text authentication if it is
- * allowed by user
+ * We do not have any password, we can still get the password from
+ * client using plain text authentication if it is allowed by user
*/
if (frontend->pool_hba == NULL && pool_config->allow_clear_text_frontend_auth)
{
}
}
else
- keylen = 4;
+ keylen = 4;
elog(DEBUG1, "cancel key length: %d", keylen);
* throws ereport.
*/
int
-pool_do_reauth(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * cp)
+pool_do_reauth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp)
{
int protoMajor;
int msglen;
- POOL_CONNECTION_POOL_SLOT *sp;
+ POOL_CONNECTION_POOL_SLOT *sp;
protoMajor = MAJOR(cp);
* send authentication failure message text to frontend
*/
static void
-pool_send_auth_fail(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * cp)
+pool_send_auth_fail(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp)
{
int messagelen;
char *errmessage;
* Send backend key data to frontend.
*/
static void
-pool_send_backend_key_data(POOL_CONNECTION * frontend, int pid,
+pool_send_backend_key_data(POOL_CONNECTION *frontend, int pid,
char *key, int32 keylen, int protoMajor)
{
char kind;
}
static void
-authenticate_frontend_clear_text(POOL_CONNECTION * frontend)
+authenticate_frontend_clear_text(POOL_CONNECTION *frontend)
{
static int size;
char password[MAX_PASSWORD_SIZE];
* perform clear text password authentication
*/
static int
-do_clear_text_password(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth, int protoMajor)
+do_clear_text_password(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth, int protoMajor)
{
static int size;
char *pwd = NULL;
else if (!rtn || frontend->pwd_size == 0)
{
/*
- * We do not have any password, we can still get the password
- * from client using plain text authentication if it is
- * allowed by user
+ * We do not have any password, we can still get the password from
+ * client using plain text authentication if it is allowed by user
*/
if (frontend->pool_hba == NULL ||
frontend->pool_hba->auth_method == uaPassword ||
- pool_config->allow_clear_text_frontend_auth )
+ pool_config->allow_clear_text_frontend_auth)
{
ereport(DEBUG1,
- (errmsg("using clear text authentication with frontend"),
+ (errmsg("using clear text authentication with frontend"),
errdetail("backend is using password authentication")));
authenticate_frontend_clear_text(frontend);
{
ereport(FATAL,
(return_code(2),
- errmsg("clear text password authentication failed"),
- errdetail("unable to get the password for user: \"%s\"", frontend->username)));
+ errmsg("clear text password authentication failed"),
+ errdetail("unable to get the password for user: \"%s\"", frontend->username)));
}
}
}
* password in the pool_passwd file.
*/
static void
-authenticate_frontend_SCRAM(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth)
+authenticate_frontend_SCRAM(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth)
{
void *scram_opaq;
char *output = NULL;
PasswordType storedPasswordType = PASSWORD_TYPE_UNKNOWN;
char *storedPassword = NULL;
- if (get_auth_password(backend, frontend, reauth,&storedPassword, &storedPasswordType) == false)
+ if (get_auth_password(backend, frontend, reauth, &storedPassword, &storedPasswordType) == false)
{
ereport(FATAL,
(return_code(2),
* Authenticate frontend using pool_hba.conf
*/
void
-authenticate_frontend(POOL_CONNECTION * frontend)
+authenticate_frontend(POOL_CONNECTION *frontend)
{
switch (frontend->pool_hba->auth_method)
{
#ifdef USE_SSL
static void
-authenticate_frontend_cert(POOL_CONNECTION * frontend)
+authenticate_frontend_cert(POOL_CONNECTION *frontend)
{
if (frontend->client_cert_loaded == true && frontend->cert_cn)
{
}
#else
static void
-authenticate_frontend_cert(POOL_CONNECTION * frontend)
+authenticate_frontend_cert(POOL_CONNECTION *frontend)
{
ereport(ERROR,
(errmsg("CERT authentication failed"),
#endif
static void
-authenticate_frontend_md5(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth, int protoMajor)
+authenticate_frontend_md5(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth, int protoMajor)
{
char salt[4];
static int size;
PasswordType storedPasswordType = PASSWORD_TYPE_UNKNOWN;
char *storedPassword = NULL;
- if (get_auth_password(backend, frontend, reauth,&storedPassword, &storedPasswordType) == false)
+ if (get_auth_password(backend, frontend, reauth, &storedPassword, &storedPasswordType) == false)
{
ereport(FATAL,
(return_code(2),
* it.
*/
static bool
-get_auth_password(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth,
+get_auth_password(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth,
char **password, PasswordType *passwordType)
{
/* First preference is to use the pool_passwd file */
* perform MD5 authentication
*/
static int
-do_md5(POOL_CONNECTION * backend, POOL_CONNECTION * frontend, int reauth, int protoMajor,
+do_md5(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int reauth, int protoMajor,
char *storedPassword, PasswordType passwordType)
{
char salt[4];
* Send an authentication request packet to the frontend.
*/
static void
-sendAuthRequest(POOL_CONNECTION * frontend, int protoMajor, int32 auth_req_type, char *extradata, int extralen)
+sendAuthRequest(POOL_CONNECTION *frontend, int protoMajor, int32 auth_req_type, char *extradata, int extralen)
{
int kind = htonl(auth_req_type);
* Send md5 authentication request packet to frontend
*/
static void
-send_md5auth_request(POOL_CONNECTION * frontend, int protoMajor, char *salt)
+send_md5auth_request(POOL_CONNECTION *frontend, int protoMajor, char *salt)
{
sendAuthRequest(frontend, protoMajor, AUTH_REQ_MD5, salt, 4);
}
* Read password packet from frontend
*/
static int
-read_password_packet(POOL_CONNECTION * frontend, int protoMajor, char *password, int *pwdSize)
+read_password_packet(POOL_CONNECTION *frontend, int protoMajor, char *password, int *pwdSize)
{
int size;
* "password" must be null-terminated.
*/
static int
-send_password_packet(POOL_CONNECTION * backend, int protoMajor, char *password)
+send_password_packet(POOL_CONNECTION *backend, int protoMajor, char *password)
{
int size;
int len;
* Send auth ok to frontend
*/
static int
-send_auth_ok(POOL_CONNECTION * frontend, int protoMajor)
+send_auth_ok(POOL_CONNECTION *frontend, int protoMajor)
{
int msglen;
}
static bool
-do_SCRAM(POOL_CONNECTION * frontend, POOL_CONNECTION * backend, int protoMajor, int message_length,
+do_SCRAM(POOL_CONNECTION *frontend, POOL_CONNECTION *backend, int protoMajor, int message_length,
char *username, char *storedPassword, PasswordType passwordType)
{
/* read the packet first */
}
static void *
-pg_SASL_init(POOL_CONNECTION * backend, char *payload, int payloadlen, char *username, char *storedPassword)
+pg_SASL_init(POOL_CONNECTION *backend, char *payload, int payloadlen, char *username, char *storedPassword)
{
char *initialresponse = NULL;
int initialresponselen;
* the protocol.
*/
static int
-pg_SASL_continue(POOL_CONNECTION * backend, char *payload, int payloadlen, void *sasl_state, bool final)
+pg_SASL_continue(POOL_CONNECTION *backend, char *payload, int payloadlen, void *sasl_state, bool final)
{
char *output;
int outputlen;
static void
ProcessNegotiateProtocol(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp)
{
- int32 len;
- int32 savelen;
- int32 protoMajor;
- int32 protoMinor;
- int32 protov;
- bool forwardMsg = false;
- int i;
+ int32 len;
+ int32 savelen;
+ int32 protoMajor;
+ int32 protoMinor;
+ int32 protov;
+ bool forwardMsg = false;
+ int i;
elog(DEBUG1, "Forwarding NegotiateProtocol message to frontend");
pool_write(frontend, "v", 1); /* forward message kind */
- savelen = len = pool_read_int(cp); /* message length including self */
+ savelen = len = pool_read_int(cp); /* message length including self */
pool_write(frontend, &len, 4); /* forward message length */
- len = ntohl(len) - 4; /* length of rest of the message */
- protov = pool_read_int(cp); /* read protocol version */
- protoMajor = PG_PROTOCOL_MAJOR(ntohl(protov)); /* protocol major version */
+ len = ntohl(len) - 4; /* length of rest of the message */
+ protov = pool_read_int(cp); /* read protocol version */
+ protoMajor = PG_PROTOCOL_MAJOR(ntohl(protov)); /* protocol major version */
protoMinor = PG_PROTOCOL_MINOR(ntohl(protov)); /* protocol minor version */
pool_write(frontend, &protov, 4); /* forward protocol version */
elog(DEBUG1, "protocol verion offered: major: %d minor: %d", protoMajor, protoMinor);
{
if (VALID_BACKEND(i))
{
- POOL_CONNECTION_POOL_SLOT *sp;
- char *p;
- char *np;
- Size nplen;
+ POOL_CONNECTION_POOL_SLOT *sp;
+ char *p;
+ char *np;
+ Size nplen;
p = pool_read2(CONNECTION(cp, i), len);
if (!forwardMsg)
{
- pool_write_and_flush(frontend, p, len); /* forward rest of message */
+ pool_write_and_flush(frontend, p, len); /* forward rest of
+ * message */
forwardMsg = true;
}
/* save negatiate protocol version */
sp->negotiated_minor = protoMinor;
/* save negatiate protocol message */
- nplen = 1 + /* message kind */
+ nplen = 1 + /* message kind */
sizeof(savelen) + /* message length */
sizeof(protov) + /* protocol version */
- len; /* rest of message */
+ len; /* rest of message */
/* allocate message area */
sp->negotiateProtocolMsg = MemoryContextAlloc(TopMemoryContext, nplen);
np = sp->negotiateProtocolMsg;
static HbaToken *make_hba_token(const char *token, bool quoted);
static bool parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline,
- int elevel, char **err_msg);
+ int elevel, char **err_msg);
static MemoryContext tokenize_file(const char *filename, FILE *file,
- List **tok_lines, int elevel);
-static void sendAuthRequest(POOL_CONNECTION * frontend, AuthRequest areq);
-static void auth_failed(POOL_CONNECTION * frontend);
-static bool hba_getauthmethod(POOL_CONNECTION * frontend);
-static bool check_hba(POOL_CONNECTION * frontend);
+ List **tok_lines, int elevel);
+static void sendAuthRequest(POOL_CONNECTION *frontend, AuthRequest areq);
+static void auth_failed(POOL_CONNECTION *frontend);
+static bool hba_getauthmethod(POOL_CONNECTION *frontend);
+static bool check_hba(POOL_CONNECTION *frontend);
static bool check_user(char *user, List *tokens);
static bool check_db(const char *dbname, const char *user, List *tokens);
static List *tokenize_inc_file(List *tokens,
- const char *outer_filename,
- const char *inc_filename,
- int elevel,
- char **err_msg);
+ const char *outer_filename,
+ const char *inc_filename,
+ int elevel,
+ char **err_msg);
static bool
- check_hostname(POOL_CONNECTION * frontend, const char *hostname);
+ check_hostname(POOL_CONNECTION *frontend, const char *hostname);
static bool
check_ip(SockAddr *raddr, struct sockaddr *addr, struct sockaddr *mask);
static bool
check_same_host_or_net(SockAddr *raddr, IPCompareMethod method);
static void check_network_callback(struct sockaddr *addr, struct sockaddr *netmask,
- void *cb_data);
+ void *cb_data);
static HbaLine *parse_hba_line(TokenizedLine *tok_line, int elevel);
static bool pg_isblank(const char c);
static bool next_token(char **lineptr, char *buf, int bufsz,
- bool *initial_quote, bool *terminating_comma,
- int elevel, char **err_msg);
+ bool *initial_quote, bool *terminating_comma,
+ int elevel, char **err_msg);
static List *next_field_expand(const char *filename, char **lineptr,
- int elevel, char **err_msg);
+ int elevel, char **err_msg);
#ifdef NOT_USED
static POOL_STATUS CheckUserExist(char *username);
#endif
#define PGPOOL_PAM_SERVICE "pgpool" /* Service name passed to PAM */
-static POOL_STATUS CheckPAMAuth(POOL_CONNECTION * frontend, char *user, char *password);
+static POOL_STATUS CheckPAMAuth(POOL_CONNECTION *frontend, char *user, char *password);
static int pam_passwd_conv_proc(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr);
static struct pam_conv pam_passwd_conv = {
};
static char *pam_passwd = NULL; /* Workaround for Solaris 2.6 brokenness */
-static POOL_CONNECTION * pam_frontend_kludge; /* Workaround for passing
+static POOL_CONNECTION *pam_frontend_kludge; /* Workaround for passing
* POOL_CONNECTION *frontend
* into pam_passwd_conv_proc */
#endif /* USE_PAM */
* so declare a prototype here in "#if defined(USE_PAM or USE_LDAP)" to avoid
* compilation warning.
*/
-static char *recv_password_packet(POOL_CONNECTION * frontend);
+static char *recv_password_packet(POOL_CONNECTION *frontend);
#endif /* USE_PAM or USE_LDAP */
/*
}
#ifdef USE_LDAP
+
/*
* Check if the selected authentication method has any mandatory arguments
* that are not set.
* do frontend <-> pgpool authentication based on pool_hba.conf
*/
void
-ClientAuthentication(POOL_CONNECTION * frontend)
+ClientAuthentication(POOL_CONNECTION *frontend)
{
POOL_STATUS status = POOL_END;
MemoryContext oldContext;
/*
* Get the password for the user if it is stored in the pool_password
- * file
- * authentication process is called in the temporary memory
- * context, but password mappings has to live till the life time
- * of frontend connection, so call the pool_get_user_credentials in
+ * file authentication process is called in the temporary memory
+ * context, but password mappings has to live till the life time of
+ * frontend connection, so call the pool_get_user_credentials in
* ProcessLoopContext memory context
*/
oldContext = MemoryContextSwitchTo(ProcessLoopContext);
#ifdef USE_SSL
ereport(FATAL,
- (return_code(2),
+ (return_code(2),
errmsg("client authentication failed"),
errdetail("no pool_hba.conf entry for host \"%s\", user \"%s\", database \"%s\", %s",
hostinfo, frontend->username, frontend->database,
static void
-sendAuthRequest(POOL_CONNECTION * frontend, AuthRequest areq)
+sendAuthRequest(POOL_CONNECTION *frontend, AuthRequest areq)
{
int wsize; /* number of bytes to write */
int areq_nbo; /* areq in network byte order */
* Returns NULL if couldn't get password, else palloc'd string.
*/
static char *
-recv_password_packet(POOL_CONNECTION * frontend)
+recv_password_packet(POOL_CONNECTION *frontend)
{
int rsize;
char *passwd;
* Tell the user the authentication failed.
*/
static void
-auth_failed(POOL_CONNECTION * frontend)
+auth_failed(POOL_CONNECTION *frontend)
{
int messagelen;
char *errmessage;
* we return true and method = uaReject.
*/
static bool
-hba_getauthmethod(POOL_CONNECTION * frontend)
+hba_getauthmethod(POOL_CONNECTION *frontend)
{
if (check_hba(frontend))
return true;
* request.
*/
static bool
-check_hba(POOL_CONNECTION * frontend)
+check_hba(POOL_CONNECTION *frontend)
{
ListCell *line;
HbaLine *hba;
* Check to see if a connecting IP matches a given host name.
*/
static bool
-check_hostname(POOL_CONNECTION * frontend, const char *hostname)
+check_hostname(POOL_CONNECTION *frontend, const char *hostname)
{
struct addrinfo *gai_result,
*gai;
/*
* Check authentication against PAM.
*/
-static POOL_STATUS CheckPAMAuth(POOL_CONNECTION * frontend, char *user, char *password)
+static POOL_STATUS
+CheckPAMAuth(POOL_CONNECTION *frontend, char *user, char *password)
{
int retval;
pam_handle_t *pamh = NULL;
* later used inside the PAM conversation to pass the password to the
* authentication module.
*/
- pam_passwd_conv.appdata_ptr = (char *) password; /* from password above,
- * not allocated */
+ pam_passwd_conv.appdata_ptr = (char *) password; /* from password above,
+ * not allocated */
/* Optionally, one can set the service name in pool_hba.conf */
if (frontend->pool_hba->pamservice && frontend->pool_hba->pamservice[0] != '\0')
/*
* Check authentication against LDAP.
*/
-static POOL_STATUS CheckLDAPAuth(POOL_CONNECTION * frontend)
+static POOL_STATUS
+CheckLDAPAuth(POOL_CONNECTION *frontend)
{
char *passwd;
LDAP *ldap;
passwd = recv_password_packet(frontend);
if (passwd == NULL)
- return -2; /* client wouldn't send password */
+ return -2; /* client wouldn't send password */
if (InitializeLDAPConnection(frontend, &ldap) == -1)
{
#endif /* USE_LDAP */
#ifdef NOT_USED
-static POOL_STATUS CheckUserExist(char *username)
+static POOL_STATUS
+CheckUserExist(char *username)
{
char *passwd;
if (pool_passwd_filename == NULL)
{
- saved_passwd_filename[0] = '\0'; /* indicate pool_passwd is disabled */
+ saved_passwd_filename[0] = '\0'; /* indicate pool_passwd is
+ * disabled */
return;
}
{
#define LINE_LEN \
MAX_USER_NAME_LEN + 1 + MAX_POOL_PASSWD_LEN + 2
- char linebuf[LINE_LEN];
- char *writebuf = NULL;
- int len;
- bool updated = false;
+ char linebuf[LINE_LEN];
+ char *writebuf = NULL;
+ int len;
+ bool updated = false;
if (!passwd_fd)
ereport(ERROR,
while (!feof(passwd_fd) && !ferror(passwd_fd))
{
- char *t = linebuf;
- int len;
+ char *t = linebuf;
+ int len;
if (fgets(linebuf, sizeof(linebuf), passwd_fd) == NULL)
break;
strcat(writebuf, linebuf);
}
- if(!writebuf)
+ if (!writebuf)
return 0;
fclose(passwd_fd);
{
if (strlen(saved_passwd_filename))
ereport(ERROR,
- (errmsg("unable to get password, password file descriptor is NULL")));
+ (errmsg("unable to get password, password file descriptor is NULL")));
else
return NULL;
}
{
if (strlen(saved_passwd_filename))
ereport(WARNING,
- (errmsg("unable to get password, password file descriptor is NULL")));
+ (errmsg("unable to get password, password file descriptor is NULL")));
return NULL;
}
}
void
-delete_passwordMapping(PasswordMapping * pwdMapping)
+delete_passwordMapping(PasswordMapping *pwdMapping)
{
if (!pwdMapping)
return;
PasswordMapping *password_mapping = NULL;
/*
- * if the password specified in config is empty string or NULL look for the
- * password in pool_passwd file
+ * if the password specified in config is empty string or NULL look for
+ * the password in pool_passwd file
*/
if (password_in_config == NULL || strlen(password_in_config) == 0)
{
/* convert the TEXT prefixed password to plain text password */
passwordType = PASSWORD_TYPE_PLAINTEXT;
if (password)
- password = (char*)(password + strlen(PASSWORD_TEXT_PREFIX));
+ password = (char *) (password + strlen(PASSWORD_TEXT_PREFIX));
}
if (password && strlen(password) && (passwordType != PASSWORD_TYPE_PLAINTEXT &&
return NULL;
/*
- * To prevent file-swapping due to file race conditions,
- * we open the key file before checking it by stat().
+ * To prevent file-swapping due to file race conditions, we open the key
+ * file before checking it by stat().
*/
/* If password file cannot be opened, ignore it. */
- if ( (fp = fopen(key_file_path, "r")) == NULL)
+ if ((fp = fopen(key_file_path, "r")) == NULL)
return NULL;
if (fstat(fileno(fp), &stat_buf) != 0)
PasswordType passwordType = PASSWORD_TYPE_UNKNOWN;
/*
- * if the password specified in config is empty string or NULL look for the
- * password in pool_passwd file
+ * if the password specified in config is empty string or NULL look for
+ * the password in pool_passwd file
*/
if (password_in_config == NULL || strlen(password_in_config) == 0)
{
PasswordMapping *password_mapping = NULL;
+
password_mapping = pool_get_user_credentials(username);
if (password_mapping == NULL)
{
passwordType = get_password_type(password_in_config);
}
- /* if the password type is MD5 hash return -1*/
+ /* if the password type is MD5 hash return -1 */
if (passwordType == PASSWORD_TYPE_MD5)
{
return -1;
static void sort_config_vars(void);
static bool setConfigOptionArrayVarWithConfigDefault(struct config_generic *record, const char *name,
- const char *value, ConfigContext context, int elevel);
+ const char *value, ConfigContext context, int elevel);
static bool setConfigOption(const char *name, const char *value,
- ConfigContext context, GucSource source, int elevel);
+ ConfigContext context, GucSource source, int elevel);
static bool setConfigOptionVar(struct config_generic *record, const char *name, int index_val,
- const char *value, ConfigContext context, GucSource source, int elevel);
+ const char *value, ConfigContext context, GucSource source, int elevel);
static bool get_index_in_var_name(struct config_generic *record,
- const char *name, int *index, int elevel);
+ const char *name, int *index, int elevel);
static bool MakeUserRedirectListRegex(char *newval, int elevel);
static bool MakeDBRedirectListRegex(char *newval, int elevel);
static bool MakeAppRedirectListRegex(char *newval, int elevel);
static bool MakeDMLAdaptiveObjectRelationList(char *newval, int elevel);
-static char* getParsedToken(char *token, DBObjectTypes *object_type);
+static char *getParsedToken(char *token, DBObjectTypes *object_type);
static bool check_redirect_node_spec(char *node_spec);
static char **get_list_from_string(const char *str, const char *delimi, int *n);
#ifndef POOL_PRIVATE
static void convert_int_from_base_unit(int64 base_value, int base_unit,
- int64 *value, const char **unit);
+ int64 *value, const char **unit);
/* These functions are used to provide Hints for enum type config parameters and
static char *ShowOption(struct config_generic *record, int index, int elevel);
static char *config_enum_get_options(struct config_enum *record, const char *prefix,
- const char *suffix, const char *separator);
-static void send_row_description_for_detail_view(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend);
-static int send_grouped_type_variable_to_frontend(struct config_grouped_array_var *grouped_record,
- POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend);
-static int send_array_type_variable_to_frontend(struct config_generic *record,
- POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend);
+ const char *suffix, const char *separator);
+static void send_row_description_for_detail_view(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
+static int send_grouped_type_variable_to_frontend(struct config_grouped_array_var *grouped_record,
+ POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
+static int send_array_type_variable_to_frontend(struct config_generic *record,
+ POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
#endif
};
static const struct config_enum_entry check_temp_table_options[] = {
- {"catalog", CHECK_TEMP_CATALOG, false}, /* search system catalogs */
- {"trace", CHECK_TEMP_TRACE, false}, /* tracing temp tables */
- {"none", CHECK_TEMP_NONE, false}, /* do not check temp tables */
- {"on", CHECK_TEMP_ON, false}, /* same as CHECK_TEMP_CATALOG. Just for backward compatibility. */
- {"off", CHECK_TEMP_OFF, false}, /* same as CHECK_TEMP_NONE. Just for backward compatibility. */
+ {"catalog", CHECK_TEMP_CATALOG, false}, /* search system catalogs */
+ {"trace", CHECK_TEMP_TRACE, false}, /* tracing temp tables */
+ {"none", CHECK_TEMP_NONE, false}, /* do not check temp tables */
+ {"on", CHECK_TEMP_ON, false}, /* same as CHECK_TEMP_CATALOG. Just for
+ * backward compatibility. */
+ {"off", CHECK_TEMP_OFF, false}, /* same as CHECK_TEMP_NONE. Just for
+ * backward compatibility. */
{NULL, 0, false}
};
static const struct config_enum_entry log_backend_messages_options[] = {
- {"none", BGMSG_NONE, false}, /* turn off logging */
- {"terse", BGMSG_TERSE, false}, /* terse logging (repeated messages are collapsed into count */
+ {"none", BGMSG_NONE, false}, /* turn off logging */
+ {"terse", BGMSG_TERSE, false}, /* terse logging (repeated messages are
+ * collapsed into count */
{"verbose", BGMSG_VERBOSE, false}, /* always log each message */
{NULL, 0, false}
};
{
{"health_check_test", CFGCXT_INIT, HEALTH_CHECK_CONFIG,
- "If on, enable health check testing.",
- CONFIG_VAR_TYPE_BOOL, false, 0
+ "If on, enable health check testing.",
+ CONFIG_VAR_TYPE_BOOL, false, 0
},
&g_pool_config.health_check_test,
false,
CONFIG_VAR_TYPE_STRING_ARRAY, true, VAR_PART_OF_GROUP, MAX_NUM_BACKENDS
},
NULL,
- "", /* for ALWAYS_PRIMARY */
+ "", /* for ALWAYS_PRIMARY */
EMPTY_CONFIG_STRING,
BackendFlagsAssignFunc, NULL, BackendFlagsShowFunc, BackendSlotEmptyCheckFunc
},
CONFIG_VAR_TYPE_INT, false, GUC_UNIT_MIN
},
&g_pool_config.log_rotation_age,
- 1440,/*1 day*/
+ 1440, /* 1 day */
0, INT_MAX,
NULL, NULL, NULL
},
},
&g_pool_config.log_rotation_size,
10 * 1024,
- 0, INT_MAX/1024,
+ 0, INT_MAX / 1024,
NULL, NULL, NULL
},
{
for (token = strtok(temp_string, delimi); token != NULL; token = strtok(NULL, delimi))
{
- int i;
+ int i;
/* skip leading whitespace */
while (isspace(*token))
/* skip trailing whitespace */
i = strlen(token) - 1;
- while (i >= 0 && isspace(token[i])) {
+ while (i >= 0 && isspace(token[i]))
+ {
token[i] = '\0';
i--;
}
}
else if (*str_temp == *delimi)
{
- char *output = (char *) palloc(j + 1);
+ char *output = (char *) palloc(j + 1);
+
StrNCpy(output, buf, j + 1);
/* replace escape character of "'" */
if (value != NULL)
{
- int64 newval64;
+ int64 newval64;
const char *hintmsg;
if (!parse_int(value, &newval64,
hintmsg ? errhint("%s", _(hintmsg)) : 0));
return false;
}
- newval = (int)newval64;
+ newval = (int) newval64;
}
else if (source == PGC_S_DEFAULT)
{
if (value != NULL)
{
- int64 newval64;
+ int64 newval64;
const char *hintmsg;
if (!parse_int(value, &newval64,
hintmsg ? errhint("%s", _(hintmsg)) : 0));
return false;
}
- newval = (int)newval64;
+ newval = (int) newval64;
}
else if (source == PGC_S_DEFAULT)
{
if (*buffer == '\0')
snprintf(buffer, sizeof(buffer), "ALWAYS_PRIMARY");
else
- snprintf(buffer+strlen(buffer), sizeof(buffer), "|ALWAYS_PRIMARY");
+ snprintf(buffer + strlen(buffer), sizeof(buffer), "|ALWAYS_PRIMARY");
}
return buffer;
}
static bool
WdIFSlotEmptyCheckFunc(int index)
{
- return (g_pool_config.hb_ifs[index].dest_port == 0);
+ return (g_pool_config.hb_ifs[index].dest_port == 0);
}
static const char *
g_pool_config.failover_on_backend_error = newval;
return true;
}
+
/*
* Throws warning for if someone uses the removed delegate_IP
* configuration parameter and set the value to delegate_ip
g_pool_config.delegate_ip = newval;
return true;
}
+
/*
* Check DB node spec. node spec should be either "primary", "standby" or
* numeric DB node id.
static bool
config_post_processor(ConfigContext context, int elevel)
{
- double total_weight = 0.0;
+ double total_weight = 0.0;
sig_atomic_t local_num_backends = 0;
- int i;
+ int i;
/* read from pgpool_node_id */
SetPgpoolNodeId(elevel);
/*
* Quarantine state in native replication mode is dangerous and it can
- * potentially cause data inconsistency.
- * So as per the discussions, we agreed on disallowing setting
- * failover_when_quorum_exists in native replication mode
+ * potentially cause data inconsistency. So as per the discussions, we
+ * agreed on disallowing setting failover_when_quorum_exists in native
+ * replication mode
*/
if (pool_config->failover_when_quorum_exists && pool_config->replication_mode)
}
/*
- * Verify the minimum and maximum number of spare children configuration when
- * dynamic process management is enabled
+ * Verify the minimum and maximum number of spare children configuration
+ * when dynamic process management is enabled
*/
if (g_pool_config.process_management == PM_DYNAMIC)
{
ereport(elevel,
(errmsg("invalid configuration, max_spare_children:%d must be greater than min_spare_children:%d",
- pool_config->max_spare_children,pool_config->min_spare_children)));
+ pool_config->max_spare_children, pool_config->min_spare_children)));
return false;
}
if (pool_config->num_init_children < pool_config->max_spare_children)
{
ereport(elevel,
(errmsg("invalid configuration, max_spare_children:%d can't be greater than num_init_children:%d",
- pool_config->max_spare_children,pool_config->num_init_children)));
+ pool_config->max_spare_children, pool_config->num_init_children)));
return false;
}
}
static bool
MakeDMLAdaptiveObjectRelationList(char *newval, int elevel)
{
- int i;
- int elements_count = 0;
- char **rawList = get_list_from_string(newval, ",", &elements_count);
+ int i;
+ int elements_count = 0;
+ char **rawList = get_list_from_string(newval, ",", &elements_count);
if (rawList == NULL || elements_count == 0)
{
for (i = 0; i < elements_count; i++)
{
- char *kvstr = rawList[i];
- char *left_token = strtok(kvstr, ":");
- char *right_token = strtok(NULL, ":");
+ char *kvstr = rawList[i];
+ char *left_token = strtok(kvstr, ":");
+ char *right_token = strtok(NULL, ":");
DBObjectTypes object_type;
ereport(DEBUG5,
(errmsg("dml_adaptive_init"),
- errdetail("%s -- left_token[%s] right_token[%s]", kvstr, left_token, right_token)));
+ errdetail("%s -- left_token[%s] right_token[%s]", kvstr, left_token, right_token)));
pool_config->parsed_dml_adaptive_object_relationship_list[i].left_token.name =
- getParsedToken(left_token, &object_type);
+ getParsedToken(left_token, &object_type);
pool_config->parsed_dml_adaptive_object_relationship_list[i].left_token.object_type = object_type;
pool_config->parsed_dml_adaptive_object_relationship_list[i].right_token.name =
- getParsedToken(right_token,&object_type);
+ getParsedToken(right_token, &object_type);
pool_config->parsed_dml_adaptive_object_relationship_list[i].right_token.object_type = object_type;
pfree(kvstr);
}
* We also remove the trailing spaces from the function type token
* and return the palloc'd copy of token in new_token
*/
-static char*
+static char *
getParsedToken(char *token, DBObjectTypes *object_type)
{
- int len;
+ int len;
+
*object_type = OBJECT_TYPE_UNKNOWN;
if (!token)
len = strlen(token);
if (len > strlen("*()"))
{
- int namelen = len - 2;
+ int namelen = len - 2;
+
/* check if token ends with () */
- if (strcmp(token + namelen,"()") == 0)
+ if (strcmp(token + namelen, "()") == 0)
{
/*
- * Remove the Parentheses from end of
- * token name
+ * Remove the Parentheses from end of token name
*/
- char *new_token;
- int new_len = strlen(token) - 2;
+ char *new_token;
+ int new_len = strlen(token) - 2;
+
new_token = palloc(new_len + 1);
- strncpy(new_token,token,new_len);
+ strncpy(new_token, token, new_len);
new_token[new_len] = '\0';
*object_type = OBJECT_TYPE_FUNCTION;
return new_token;
SetPgpoolNodeId(int elevel)
{
char pgpool_node_id_file[POOLMAXPATHLEN + 1];
- FILE *fd;
- int length;
- int i;
+ FILE *fd;
+ int length;
+ int i;
if (g_pool_config.use_watchdog)
{
snprintf(pgpool_node_id_file, sizeof(pgpool_node_id_file), "%s/%s", config_file_dir, NODE_ID_FILE_NAME);
#define MAXLINE 10
- char readbuf[MAXLINE];
+ char readbuf[MAXLINE];
fd = fopen(pgpool_node_id_file, "r");
if (!fd)
static bool
SetHBDestIfFunc(int elevel)
{
- int idx = 0;
- char **addrs;
- char **if_names;
- int i, j,
- n_addr,
- n_if_name;
+ int idx = 0;
+ char **addrs;
+ char **if_names;
+ int i,
+ j,
+ n_addr,
+ n_if_name;
g_pool_config.num_hb_dest_if = 0;
/*
* g_pool_config.hb_ifs is the information for sending/receiving heartbeat
- * for all nodes specified in pgpool.conf.
- * If it is local pgpool node information, set dest_port to g_pool_config.wd_heartbeat_port
- * and ignore addr and if_name.
- * g_pool_config.hb_dest_if is the heartbeat destination information.
+ * for all nodes specified in pgpool.conf. If it is local pgpool node
+ * information, set dest_port to g_pool_config.wd_heartbeat_port and
+ * ignore addr and if_name. g_pool_config.hb_dest_if is the heartbeat
+ * destination information.
*/
for (i = 0; i < WD_MAX_IF_NUM; i++)
{
continue;
}
- WdHbIf *hbNodeInfo = &g_pool_config.hb_ifs[i];
+ WdHbIf *hbNodeInfo = &g_pool_config.hb_ifs[i];
addrs = get_list_from_string(hbNodeInfo->addr, ";", &n_addr);
if_names = get_list_from_string(hbNodeInfo->if_name, ";", &n_if_name);
{
strlcpy(g_pool_config.hb_dest_if[idx].addr, addrs[j], WD_MAX_HOST_NAMELEN - 1);
g_pool_config.hb_dest_if[idx].dest_port = hbNodeInfo->dest_port;
- if (n_if_name > j )
+ if (n_if_name > j)
{
strlcpy(g_pool_config.hb_dest_if[idx].if_name, if_names[j], WD_MAX_IF_NAME_LEN - 1);
pfree(if_names[j]);
*result = (int64) val;
return true;
}
+
/*
* Convert a value from one of the human-friendly units ("kB", "min" etc.)
* to the given base unit. 'value' and 'unit' are the input value and unit
}
bool
-set_config_option_for_session(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend, const char *name, const char *value)
+set_config_option_for_session(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, const char *name, const char *value)
{
bool ret;
MemoryContext oldCxt = MemoryContextSwitchTo(TopMemoryContext);
}
bool
-reset_all_variables(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
+reset_all_variables(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
{
int i;
int elevel = (frontend == NULL) ? FATAL : FRONTEND_ONLY_ERROR;
* Handle "pgpool show all" command.
*/
bool
-report_all_variables(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
+report_all_variables(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
{
int i;
int num_rows = 0;
* Handle "pgpool show" command.
*/
bool
-report_config_variable(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend, const char *var_name)
+report_config_variable(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, const char *var_name)
{
int index = 0;
char *value;
}
static int
-send_array_type_variable_to_frontend(struct config_generic *record, POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
+send_array_type_variable_to_frontend(struct config_generic *record, POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
{
if (record->dynamic_array_var)
{
}
static int
-send_grouped_type_variable_to_frontend(struct config_grouped_array_var *grouped_record, POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
+send_grouped_type_variable_to_frontend(struct config_grouped_array_var *grouped_record, POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
{
int k,
index;
}
static void
-send_row_description_for_detail_view(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
+send_row_description_for_detail_view(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
{
static char *field_names[] = {"item", "value", "description"};
#include "pool_config.h" /* remove me afterwards */
static POOL_PROCESS_CONTEXT process_context_d;
-static POOL_PROCESS_CONTEXT * process_context;
+static POOL_PROCESS_CONTEXT *process_context;
/*
* Initialize per process context
size_t
pool_coninfo_size(void)
{
- size_t size;
+ size_t size;
size = pool_config->num_init_children *
pool_config->max_pool *
* This flag is used to handle pg_terminate_backend()
*/
void
-pool_set_connection_will_be_terminated(ConnectionInfo * connInfo)
+pool_set_connection_will_be_terminated(ConnectionInfo *connInfo)
{
connInfo->swallow_termination = 1;
}
void
-pool_unset_connection_will_be_terminated(ConnectionInfo * connInfo)
+pool_unset_connection_will_be_terminated(ConnectionInfo *connInfo)
{
connInfo->swallow_termination = 0;
}
POOL_STANDBY,
POOL_EITHER,
POOL_BOTH
-} POOL_DEST;
+} POOL_DEST;
#define CHECK_QUERY_CONTEXT_IS_VALID \
do { \
} while (0)
static POOL_DEST send_to_where(Node *node);
-static void where_to_send_deallocate(POOL_QUERY_CONTEXT * query_context, Node *node);
-static void where_to_send_main_replica(POOL_QUERY_CONTEXT * query_context, char *query, Node *node);
-static void where_to_send_native_replication(POOL_QUERY_CONTEXT * query_context, char *query, Node *node);
+static void where_to_send_deallocate(POOL_QUERY_CONTEXT *query_context, Node *node);
+static void where_to_send_main_replica(POOL_QUERY_CONTEXT *query_context, char *query, Node *node);
+static void where_to_send_native_replication(POOL_QUERY_CONTEXT *query_context, char *query, Node *node);
static char *remove_read_write(int len, const char *contents, int *rewritten_len);
static void set_virtual_main_node(POOL_QUERY_CONTEXT *query_context);
static bool is_select_object_in_temp_write_list(Node *node, void *context);
static bool add_object_into_temp_write_list(Node *node, void *context);
static void dml_adaptive(Node *node, char *query);
-static char* get_associated_object_from_dml_adaptive_relations
- (char *left_token, DBObjectTypes object_type);
+static char *get_associated_object_from_dml_adaptive_relations
+ (char *left_token, DBObjectTypes object_type);
/*
* Create and initialize per query session context
* Destroy query context
*/
void
-pool_query_context_destroy(POOL_QUERY_CONTEXT * query_context)
+pool_query_context_destroy(POOL_QUERY_CONTEXT *query_context)
{
POOL_SESSION_CONTEXT *session_context;
* Perform shallow copy of given query context. Used in parse_before_bind.
*/
POOL_QUERY_CONTEXT *
-pool_query_context_shallow_copy(POOL_QUERY_CONTEXT * query_context)
+pool_query_context_shallow_copy(POOL_QUERY_CONTEXT *query_context)
{
POOL_QUERY_CONTEXT *qc;
MemoryContext memory_context;
* Start query
*/
void
-pool_start_query(POOL_QUERY_CONTEXT * query_context, char *query, int len, Node *node)
+pool_start_query(POOL_QUERY_CONTEXT *query_context, char *query, int len, Node *node)
{
POOL_SESSION_CONTEXT *session_context;
* Specify DB node to send query
*/
void
-pool_set_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id)
+pool_set_node_to_be_sent(POOL_QUERY_CONTEXT *query_context, int node_id)
{
CHECK_QUERY_CONTEXT_IS_VALID;
* Unspecified DB node to send query
*/
void
-pool_unset_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id)
+pool_unset_node_to_be_sent(POOL_QUERY_CONTEXT *query_context, int node_id)
{
CHECK_QUERY_CONTEXT_IS_VALID;
* Clear DB node map
*/
void
-pool_clear_node_to_be_sent(POOL_QUERY_CONTEXT * query_context)
+pool_clear_node_to_be_sent(POOL_QUERY_CONTEXT *query_context)
{
CHECK_QUERY_CONTEXT_IS_VALID;
* Set all DB node map entry
*/
void
-pool_setall_node_to_be_sent(POOL_QUERY_CONTEXT * query_context)
+pool_setall_node_to_be_sent(POOL_QUERY_CONTEXT *query_context)
{
int i;
POOL_SESSION_CONTEXT *sc;
if (SL_MODE)
{
/*
- * If load balance mode is disabled, only send to the primary node.
- * If primary node does not exist, send to the main node.
+ * If load balance mode is disabled, only send to the primary
+ * node. If primary node does not exist, send to the main
+ * node.
*/
if (!pool_config->load_balance_mode)
{
continue;
}
else
+
/*
* If the node is not primary node nor load balance node,
* there's no point to send query except statement level
*/
if (!pool_config->statement_level_load_balance &&
i != PRIMARY_NODE_ID && i != sc->load_balance_node_id)
- continue;
+ continue;
}
query_context->where_to_send[i] = true;
}
* Return true if multiple nodes are targets
*/
bool
-pool_multi_node_to_be_sent(POOL_QUERY_CONTEXT * query_context)
+pool_multi_node_to_be_sent(POOL_QUERY_CONTEXT *query_context)
{
int i;
int cnt = 0;
* Return if the DB node is needed to send query
*/
bool
-pool_is_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id)
+pool_is_node_to_be_sent(POOL_QUERY_CONTEXT *query_context, int node_id)
{
CHECK_QUERY_CONTEXT_IS_VALID;
int
pool_virtual_main_db_node_id(void)
{
- volatile POOL_REQUEST_INFO *my_req;
+ volatile POOL_REQUEST_INFO *my_req;
POOL_SESSION_CONTEXT *sc;
/*
- * Check whether failover is in progress and we are child process.
- * If so, we will wait for failover to finish.
+ * Check whether failover is in progress and we are child process. If so,
+ * we will wait for failover to finish.
*/
my_req = Req_info;
if (processType == PT_CHILD && my_req->switching)
POOL_SETMASK(&BlockSig);
ereport(WARNING,
(errmsg("failover/failback is in progress"),
- errdetail("executing failover or failback on backend"),
+ errdetail("executing failover or failback on backend"),
errhint("In a moment you should be able to reconnect to the database")));
POOL_SETMASK(&UnBlockSig);
#endif
+
/*
* Wait for failover to finish
*/
if (wait_for_failover_to_finish() == -2)
+
/*
- * Waiting for failover/failback to finish was timed out.
- * Time to exit this process (and session disconnection).
+ * Waiting for failover/failback to finish was timed out. Time to
+ * exit this process (and session disconnection).
*/
child_exit(POOL_EXIT_AND_RESTART);
}
{
/*
* We used to return REAL_MAIN_NODE_ID here. Problem with it is, it
- * is possible that REAL_MAIN_NODE_ID could be changed
- * anytime. Suppose REAL_MAIN_NODE_ID == my_main_node_id == 1. Then
- * due to failback, REAL_MAIN_NODE_ID is changed to 0. Then
+ * is possible that REAL_MAIN_NODE_ID could be changed anytime.
+ * Suppose REAL_MAIN_NODE_ID == my_main_node_id == 1. Then due to
+ * failback, REAL_MAIN_NODE_ID is changed to 0. Then
* MAIN_CONNECTION(cp) will return NULL and any reference to it will
* cause segmentation fault. To prevent the issue we should return
* my_main_node_id instead.
}
/*
- * No query context exists. If in streaming replication mode, returns primary node
- * if exists. Otherwise returns my_main_node_id, which represents the
- * last REAL_MAIN_NODE_ID.
+ * No query context exists. If in streaming replication mode, returns
+ * primary node if exists. Otherwise returns my_main_node_id, which
+ * represents the last REAL_MAIN_NODE_ID.
*/
if (MAIN_REPLICA)
{
* Set the destination for the current query to the specific backend node.
*/
void
-pool_force_query_node_to_backend(POOL_QUERY_CONTEXT * query_context, int backend_id)
+pool_force_query_node_to_backend(POOL_QUERY_CONTEXT *query_context, int backend_id)
{
CHECK_QUERY_CONTEXT_IS_VALID;
* Decide where to send queries(thus expecting response)
*/
void
-pool_where_to_send(POOL_QUERY_CONTEXT * query_context, char *query, Node *node)
+pool_where_to_send(POOL_QUERY_CONTEXT *query_context, char *query, Node *node)
{
CHECK_QUERY_CONTEXT_IS_VALID;
if (query_context->is_multi_statement)
{
/*
- * If we are in streaming replication mode and we have multi statement query,
- * we should send it to primary server only. Otherwise it is possible
- * to send a write query to standby servers because we only use the
- * first element of the multi statement query and don't care about the
- * rest. Typical situation where we are bugged by this is,
- * "BEGIN;DELETE FROM table;END". Note that from pgpool-II 3.1.0
- * transactional statements such as "BEGIN" is unconditionally sent to
- * all nodes(see send_to_where() for more details). Someday we might
+ * If we are in streaming replication mode and we have multi
+ * statement query, we should send it to primary server only.
+ * Otherwise it is possible to send a write query to standby
+ * servers because we only use the first element of the multi
+ * statement query and don't care about the rest. Typical
+ * situation where we are bugged by this is, "BEGIN;DELETE FROM
+ * table;END". Note that from pgpool-II 3.1.0 transactional
+ * statements such as "BEGIN" is unconditionally sent to all
+ * nodes(see send_to_where() for more details). Someday we might
* be able to understand all part of multi statement queries, but
* until that day we need this band aid.
*/
* >0: send to this node_id
*/
POOL_STATUS
-pool_send_and_wait(POOL_QUERY_CONTEXT * query_context,
+pool_send_and_wait(POOL_QUERY_CONTEXT *query_context,
int send_type, int node_id)
{
POOL_SESSION_CONTEXT *session_context;
string = NULL;
/*
- * If the query is BEGIN READ WRITE or BEGIN ... SERIALIZABLE in
- * streaming replication mode, we send BEGIN to standbys instead.
- * The original_query which is BEGIN READ WRITE is sent to primary.
- * The rewritten_query BEGIN is sent to standbys.
+ * If the query is BEGIN READ WRITE or BEGIN ... SERIALIZABLE in streaming
+ * replication mode, we send BEGIN to standbys instead. The original_query
+ * which is BEGIN READ WRITE is sent to primary. The rewritten_query BEGIN
+ * is sent to standbys.
*/
if (pool_need_to_treat_as_if_default_transaction(query_context))
{
continue;
/*
- * If we are in streaming replication mode or logical replication mode,
- * we do not send COMMIT/ABORT to standbys if it's in I (idle) state.
+ * If we are in streaming replication mode or logical replication
+ * mode, we do not send COMMIT/ABORT to standbys if it's in I (idle)
+ * state.
*/
if (is_commit && MAIN_REPLICA && !IS_MAIN_NODE_ID(i) && TSTATE(backend, i) == 'I')
{
* >0: send to this node_id
*/
POOL_STATUS
-pool_extended_send_and_wait(POOL_QUERY_CONTEXT * query_context,
+pool_extended_send_and_wait(POOL_QUERY_CONTEXT *query_context,
char *kind, int len, char *contents,
int send_type, int node_id, bool nowait)
{
rewritten_begin = NULL;
/*
- * If the query is BEGIN READ WRITE or BEGIN ... SERIALIZABLE in
- * streaming replication mode, we send BEGIN to standbys instead.
- * The original_query which is BEGIN READ WRITE is sent to primary.
- * The rewritten_query BEGIN is sent to standbys.
+ * If the query is BEGIN READ WRITE or BEGIN ... SERIALIZABLE in streaming
+ * replication mode, we send BEGIN to standbys instead. The original_query
+ * which is BEGIN READ WRITE is sent to primary. The rewritten_query BEGIN
+ * is sent to standbys.
*/
if (pool_need_to_treat_as_if_default_transaction(query_context))
{
* From syntactically analysis decide the statement to be sent to the
* primary, the standby or either or both in native replication+HR/SR mode.
*/
-static POOL_DEST send_to_where(Node *node)
+static POOL_DEST
+send_to_where(Node *node)
{
/* From storage/lock.h */
if (is_start_transaction_query(node))
{
/*
- * But actually, we send BEGIN to standby if it's BEGIN READ
- * WRITE or START TRANSACTION READ WRITE
+ * But actually, we send BEGIN to standby if it's BEGIN READ WRITE
+ * or START TRANSACTION READ WRITE
*/
if (is_read_write((TransactionStmt *) node))
return POOL_BOTH;
/*
- * Other TRANSACTION start commands are sent to both primary
- * and standby
+ * Other TRANSACTION start commands are sent to both primary and
+ * standby
*/
else
return POOL_BOTH;
}
return POOL_BOTH;
}
+
/*
* 2PC commands
*/
/*
* SET TRANSACTION ISOLATION LEVEL SERIALIZABLE or SET SESSION
- * CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE or
- * SET transaction_isolation TO 'serializable' SET
+ * CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE or SET
+ * transaction_isolation TO 'serializable' SET
* default_transaction_isolation TO 'serializable'
*/
else if (is_set_transaction_serializable(node))
}
/*
- * Check "SET TRANSACTION READ WRITE" "SET SESSION CHARACTERISTICS
- * AS TRANSACTION READ WRITE"
+ * Check "SET TRANSACTION READ WRITE" "SET SESSION CHARACTERISTICS AS
+ * TRANSACTION READ WRITE"
*/
else if (((VariableSetStmt *) node)->kind == VAR_SET_MULTI &&
(!strcmp(((VariableSetStmt *) node)->name, "TRANSACTION") ||
*/
static
void
-where_to_send_deallocate(POOL_QUERY_CONTEXT * query_context, Node *node)
+where_to_send_deallocate(POOL_QUERY_CONTEXT *query_context, Node *node)
{
DeallocateStmt *d = NULL;
ExecuteStmt *e = NULL;
- char *name;
+ char *name;
POOL_SENT_MESSAGE *msg;
if (IsA(node, DeallocateStmt))
else
{
/*
- * prepared statement was not found.
- * There are two cases when this could happen.
- * (1) mistakes by client. In this case backend will return ERROR
- * anyway.
- * (2) previous query was issued as multi-statement query. e.g.
- * SELECT 1\;PREPARE foo AS SELECT 1;
+ * prepared statement was not found. There are two cases when this
+ * could happen. (1) mistakes by client. In this case backend will
+ * return ERROR anyway. (2) previous query was issued as
+ * multi-statement query. e.g. SELECT 1\;PREPARE foo AS SELECT 1;
* In this case pgpool does not know anything about the prepared
* statement "foo".
*/
* The rewritten_query BEGIN is sent to standbys.
*/
bool
-pool_need_to_treat_as_if_default_transaction(POOL_QUERY_CONTEXT * query_context)
+pool_need_to_treat_as_if_default_transaction(POOL_QUERY_CONTEXT *query_context)
{
return (MAIN_REPLICA &&
is_start_transaction_query(query_context->parse_tree) &&
* Set query state, if a current state is before it than the specified state.
*/
void
-pool_set_query_state(POOL_QUERY_CONTEXT * query_context, POOL_QUERY_STATE state)
+pool_set_query_state(POOL_QUERY_CONTEXT *query_context, POOL_QUERY_STATE state)
{
int i;
static void
set_virtual_main_node(POOL_QUERY_CONTEXT *query_context)
{
- int i;
+ int i;
for (i = 0; i < NUM_BACKENDS; i++)
{
set_load_balance_info(POOL_QUERY_CONTEXT *query_context)
{
POOL_SESSION_CONTEXT *session_context;
+
session_context = pool_get_session_context(false);
if (pool_config->statement_level_load_balance)
if (name == NULL || list == NIL)
return false;
- ListCell *cell;
- foreach (cell, list)
+ ListCell *cell;
+
+ foreach(cell, list)
{
- char *cell_name = (char *)lfirst(cell);
+ char *cell_name = (char *) lfirst(cell);
+
if (strcasecmp(name, cell_name) == 0)
{
ereport(DEBUG1,
if (pool_config->disable_load_balance_on_write == DLBOW_DML_ADAPTIVE && session_context->is_in_transaction)
{
ereport(DEBUG1,
- (errmsg("is_select_object_in_temp_write_list: \"%s\", found relation \"%s\"", (char*)context, rgv->relname)));
+ (errmsg("is_select_object_in_temp_write_list: \"%s\", found relation \"%s\"", (char *) context, rgv->relname)));
return is_in_list(rgv->relname, session_context->transaction_temp_write_list);
}
return raw_expression_tree_walker(node, is_select_object_in_temp_write_list, context);
}
-static char*
-get_associated_object_from_dml_adaptive_relations
- (char *left_token, DBObjectTypes object_type)
+static char *get_associated_object_from_dml_adaptive_relations
+ (char *left_token, DBObjectTypes object_type)
{
- int i;
- char *right_token = NULL;
+ int i;
+ char *right_token = NULL;
+
if (!pool_config->parsed_dml_adaptive_object_relationship_list)
return NULL;
- for (i=0 ;; i++)
+ for (i = 0;; i++)
{
if (pool_config->parsed_dml_adaptive_object_relationship_list[i].left_token.name == NULL)
break;
if (session_context->is_in_transaction)
{
- char *right_token =
- get_associated_object_from_dml_adaptive_relations
- (name, is_func_name? OBJECT_TYPE_FUNCTION : OBJECT_TYPE_RELATION);
+ char *right_token =
+ get_associated_object_from_dml_adaptive_relations
+ (name, is_func_name ? OBJECT_TYPE_FUNCTION : OBJECT_TYPE_RELATION);
if (right_token)
{
MemoryContext old_context = MemoryContextSwitchTo(session_context->memory_context);
+
session_context->transaction_temp_write_list =
lappend(session_context->transaction_temp_write_list, pstrdup(right_token));
MemoryContextSwitchTo(old_context);
RangeVar *rgv = (RangeVar *) node;
ereport(DEBUG5,
- (errmsg("add_object_into_temp_write_list: \"%s\", found relation \"%s\"", (char*)context, rgv->relname)));
+ (errmsg("add_object_into_temp_write_list: \"%s\", found relation \"%s\"", (char *) context, rgv->relname)));
POOL_SESSION_CONTEXT *session_context = pool_get_session_context(false);
MemoryContext old_context = MemoryContextSwitchTo(session_context->memory_context);
session_context->transaction_temp_write_list = NIL;
}
- else if(is_commit_or_rollback_query(node))
+ else if (is_commit_or_rollback_query(node))
{
session_context->is_in_transaction = false;
return;
}
- /* If non-selectStmt, find the relname and add it to the transaction temp write list. */
+ /*
+ * If non-selectStmt, find the relname and add it to the transaction
+ * temp write list.
+ */
if (!is_select_query(node, query))
add_object_into_temp_write_list(node, query);
* replication mode and slony mode. Called by pool_where_to_send.
*/
static void
-where_to_send_main_replica(POOL_QUERY_CONTEXT * query_context, char *query, Node *node)
+where_to_send_main_replica(POOL_QUERY_CONTEXT *query_context, char *query, Node *node)
{
POOL_DEST dest;
POOL_SESSION_CONTEXT *session_context;
if (is_tx_started_by_multi_statement_query())
{
/*
- * If we are in an explicit transaction and the transaction
- * was started by a multi statement query, we should send
- * query to primary node only (which was supposed to be sent
- * to all nodes) until the transaction gets committed or
- * aborted.
+ * If we are in an explicit transaction and the transaction was
+ * started by a multi statement query, we should send query to
+ * primary node only (which was supposed to be sent to all nodes)
+ * until the transaction gets committed or aborted.
*/
pool_set_node_to_be_sent(query_context, PRIMARY_NODE_ID);
}
{
/*
* If (we are outside of an explicit transaction) OR (the
- * transaction has not issued a write query yet, AND
- * transaction isolation level is not SERIALIZABLE) we might
- * be able to load balance.
+ * transaction has not issued a write query yet, AND transaction
+ * isolation level is not SERIALIZABLE) we might be able to load
+ * balance.
*/
ereport(DEBUG1,
*/
/*
- * If system catalog is used in the SELECT, we prefer to
- * send to the primary. Example: SELECT * FROM pg_class
- * WHERE relname = 't1'; Because 't1' is a constant, it's
- * hard to recognize as table name. Most use case such
- * query is against system catalog, and the table name can
- * be a temporary table, it's best to query against
- * primary system catalog. Please note that this test must
- * be done *before* test using pool_has_temp_table.
+ * If system catalog is used in the SELECT, we prefer to send
+ * to the primary. Example: SELECT * FROM pg_class WHERE
+ * relname = 't1'; Because 't1' is a constant, it's hard to
+ * recognize as table name. Most use case such query is
+ * against system catalog, and the table name can be a
+ * temporary table, it's best to query against primary system
+ * catalog. Please note that this test must be done *before*
+ * test using pool_has_temp_table.
*/
if (pool_has_system_catalog(node))
{
}
/*
- * If temporary table is used in the SELECT, we prefer to
- * send to the primary.
+ * If temporary table is used in the SELECT, we prefer to send
+ * to the primary.
*/
else if (pool_config->check_temp_table && pool_has_temp_table(node))
{
}
/*
- * If unlogged table is used in the SELECT, we prefer to
- * send to the primary.
+ * If unlogged table is used in the SELECT, we prefer to send
+ * to the primary.
*/
else if (pool_config->check_unlogged_table && pool_has_unlogged_table(node))
{
pool_set_node_to_be_sent(query_context, PRIMARY_NODE_ID);
}
+
/*
- * When query match the query patterns in primary_routing_query_pattern_list, we
- * send only to main node.
+ * When query match the query patterns in
+ * primary_routing_query_pattern_list, we send only to main
+ * node.
*/
else if (pattern_compare(query, WRITELIST, "primary_routing_query_pattern_list") == 1)
{
pool_set_node_to_be_sent(query_context, PRIMARY_NODE_ID);
}
+
/*
- * If a writing function call is used, we prefer to send
- * to the primary.
+ * If a writing function call is used, we prefer to send to
+ * the primary.
*/
else if (pool_has_function_call(node))
{
/*
* As streaming replication delay is too much, if
- * prefer_lower_delay_standby is true then elect new
- * load balance node which is lowest delayed,
- * false then send to the primary.
+ * prefer_lower_delay_standby is true then elect new load
+ * balance node which is lowest delayed, false then send
+ * to the primary.
*/
if (STREAM && check_replication_delay(session_context->load_balance_node_id))
{
if (pool_config->prefer_lower_delay_standby)
{
- int new_load_balancing_node = select_load_balancing_node();
+ int new_load_balancing_node = select_load_balancing_node();
session_context->load_balance_node_id = new_load_balancing_node;
session_context->query_context->load_balance_node_id = session_context->load_balance_node_id;
* Called by pool_where_to_send.
*/
static void
-where_to_send_native_replication(POOL_QUERY_CONTEXT * query_context, char *query, Node *node)
+where_to_send_native_replication(POOL_QUERY_CONTEXT *query_context, char *query, Node *node)
{
POOL_SESSION_CONTEXT *session_context;
POOL_CONNECTION_POOL *backend;
* from syntactical point of view).
*/
elog(DEBUG1, "Maybe: load balance mode: %d is_select_query: %d",
- pool_config->load_balance_mode, is_select_query(node, query));
+ pool_config->load_balance_mode, is_select_query(node, query));
if (pool_config->load_balance_mode &&
is_select_query(node, query) &&
else if (TSTATE(backend, MAIN_NODE_ID) == 'I')
{
/*
- * We are out side transaction. If default transaction is read only,
- * we can load balance.
+ * We are out side transaction. If default transaction is read
+ * only, we can load balance.
*/
- static char *si_query = "SELECT current_setting('transaction_read_only')";
+ static char *si_query = "SELECT current_setting('transaction_read_only')";
POOL_SELECT_RESULT *res;
- bool load_balance = false;
+ bool load_balance = false;
do_query(CONNECTION(backend, MAIN_NODE_ID), si_query, &res, MAJOR(backend));
if (res)
}
}
}
-
+
/*
* If a writing function call is used or replicate_select is true, we
* have to send to all nodes since the function may modify database.
}
/*
- * If (we are outside of an explicit transaction) OR (the
- * transaction has not issued a write query yet, AND transaction
- * isolation level is not SERIALIZABLE) we might be able to load
- * balance.
+ * If (we are outside of an explicit transaction) OR (the transaction
+ * has not issued a write query yet, AND transaction isolation level
+ * is not SERIALIZABLE) we might be able to load balance.
*/
else if (TSTATE(backend, MAIN_NODE_ID) == 'I' ||
(!pool_is_writing_transaction() &&
int
wait_for_failover_to_finish(void)
{
-#define MAX_FAILOVER_WAIT 30 /* waiting for failover finish timeout in seconds */
+#define MAX_FAILOVER_WAIT 30 /* waiting for failover finish timeout in
+ * seconds */
- volatile POOL_REQUEST_INFO *my_req;
- int ret = 0;
- int i;
+ volatile POOL_REQUEST_INFO *my_req;
+ int ret = 0;
+ int i;
/*
* Wait for failover to finish
*/
- for (i = 0;i < MAX_FAILOVER_WAIT; i++)
+ for (i = 0; i < MAX_FAILOVER_WAIT; i++)
{
my_req = Req_info;
if (my_req->switching == 0)
return ret;
- ret = -1; /* failover/failback finished */
+ ret = -1; /* failover/failback finished */
sleep(1);
}
- return -2; /* timed out */
+ return -2; /* timed out */
}
#include "context/pool_session_context.h"
static POOL_SESSION_CONTEXT session_context_d;
-static POOL_SESSION_CONTEXT * session_context = NULL;
+static POOL_SESSION_CONTEXT *session_context = NULL;
static void GetTranIsolationErrorCb(void *arg);
static void init_sent_message_list(void);
-static POOL_PENDING_MESSAGE * copy_pending_message(POOL_PENDING_MESSAGE * message);
-static void dump_sent_message(char *caller, POOL_SENT_MESSAGE * m);
+static POOL_PENDING_MESSAGE *copy_pending_message(POOL_PENDING_MESSAGE *message);
+static void dump_sent_message(char *caller, POOL_SENT_MESSAGE *m);
static void dml_adaptive_init(void);
static void dml_adaptive_destroy(void);
* Initialize per session context
*/
void
-pool_init_session_context(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
+pool_init_session_context(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
{
session_context = &session_context_d;
ProcessInfo *process_info;
/* Initialize temp tables */
pool_temp_tables_init();
-
+
/* Snapshot isolation state */
session_context->si_state = SI_NO_SNAPSHOT;
* Destroy sent message
*/
void
-pool_sent_message_destroy(POOL_SENT_MESSAGE * message)
+pool_sent_message_destroy(POOL_SENT_MESSAGE *message)
{
bool in_progress;
POOL_QUERY_CONTEXT *qc = NULL;
}
static void
-dump_sent_message(char *caller, POOL_SENT_MESSAGE * m)
+dump_sent_message(char *caller, POOL_SENT_MESSAGE *m)
{
ereport(DEBUG5,
(errmsg("called by %s: sent message: address: %p kind: %c name: =%s= state:%d",
POOL_SENT_MESSAGE *
pool_create_sent_message(char kind, int len, char *contents,
int num_tsparams, const char *name,
- POOL_QUERY_CONTEXT * query_context)
+ POOL_QUERY_CONTEXT *query_context)
{
POOL_SENT_MESSAGE *msg;
* Add a sent message to sent message list
*/
void
-pool_add_sent_message(POOL_SENT_MESSAGE * message)
+pool_add_sent_message(POOL_SENT_MESSAGE *message)
{
POOL_SENT_MESSAGE *old_msg;
POOL_SENT_MESSAGE_LIST *msglist;
* Find a sent message by query context.
*/
POOL_SENT_MESSAGE *
-pool_get_sent_message_by_query_context(POOL_QUERY_CONTEXT * query_context)
+pool_get_sent_message_by_query_context(POOL_QUERY_CONTEXT *query_context)
{
int i;
POOL_SENT_MESSAGE_LIST *msglist;
* Set message state to POOL_SENT_MESSAGE_STATE to POOL_SENT_MESSAGE_CLOSED.
*/
void
-pool_set_sent_message_state(POOL_SENT_MESSAGE * message)
+pool_set_sent_message_state(POOL_SENT_MESSAGE *message)
{
ereport(DEBUG5,
(errmsg("pool_set_sent_message_state: name:%s kind:%c previous state: %d",
pool_set_writing_transaction(void)
{
/*
- * If disable_transaction_on_write is 'off' or 'dml_adaptive', then never turn on writing
- * transaction flag.
+ * If disable_transaction_on_write is 'off' or 'dml_adaptive', then never
+ * turn on writing transaction flag.
*/
if (pool_config->disable_load_balance_on_write != DLBOW_OFF && pool_config->disable_load_balance_on_write != DLBOW_DML_ADAPTIVE)
{
* is used. Returns true if it is not used.
*/
bool
-can_query_context_destroy(POOL_QUERY_CONTEXT * qc)
+can_query_context_destroy(POOL_QUERY_CONTEXT *qc)
{
int i;
int count = 0;
* message was sent.
*/
void
-pool_pending_message_dest_set(POOL_PENDING_MESSAGE * message, POOL_QUERY_CONTEXT * query_context)
+pool_pending_message_dest_set(POOL_PENDING_MESSAGE *message, POOL_QUERY_CONTEXT *query_context)
{
memcpy(message->node_ids, query_context->where_to_send, sizeof(message->node_ids));
* which indicates which backend nodes the message was sent.
*/
void
-pool_pending_message_query_context_dest_set(POOL_PENDING_MESSAGE * message, POOL_QUERY_CONTEXT * query_context)
+pool_pending_message_query_context_dest_set(POOL_PENDING_MESSAGE *message, POOL_QUERY_CONTEXT *query_context)
{
int i;
* Set query field of message.
*/
void
-pool_pending_message_query_set(POOL_PENDING_MESSAGE * message, POOL_QUERY_CONTEXT * query_context)
+pool_pending_message_query_set(POOL_PENDING_MESSAGE *message, POOL_QUERY_CONTEXT *query_context)
{
StrNCpy(message->query, query_context->original_query, sizeof(message->query));
}
* Add one message to the tail of the list.
*/
void
-pool_pending_message_add(POOL_PENDING_MESSAGE * message)
+pool_pending_message_add(POOL_PENDING_MESSAGE *message)
{
MemoryContext old_context;
* close message.
*/
char
-pool_get_close_message_spec(POOL_PENDING_MESSAGE * msg)
+pool_get_close_message_spec(POOL_PENDING_MESSAGE *msg)
{
return *msg->contents;
}
* The returned pointer is within "msg".
*/
char *
-pool_get_close_message_name(POOL_PENDING_MESSAGE * msg)
+pool_get_close_message_name(POOL_PENDING_MESSAGE *msg)
{
return (msg->contents) + 1;
}
* Perform deep copy of POOL_PENDING_MESSAGE object in the current memory
* context except the query context.
*/
-static POOL_PENDING_MESSAGE * copy_pending_message(POOL_PENDING_MESSAGE * message)
+static POOL_PENDING_MESSAGE *
+copy_pending_message(POOL_PENDING_MESSAGE *message)
{
POOL_PENDING_MESSAGE *msg;
* context except the query context.
*/
void
-pool_pending_message_free_pending_message(POOL_PENDING_MESSAGE * message)
+pool_pending_message_free_pending_message(POOL_PENDING_MESSAGE *message)
{
if (message == NULL)
return;
* Set previous message.
*/
void
-pool_pending_message_set_previous_message(POOL_PENDING_MESSAGE * message)
+pool_pending_message_set_previous_message(POOL_PENDING_MESSAGE *message)
{
if (!session_context)
{
* pool_pending_message_free_pending_message.
*/
POOL_PENDING_MESSAGE *
-pool_pending_message_find_lastest_by_query_context(POOL_QUERY_CONTEXT * qc)
+pool_pending_message_find_lastest_by_query_context(POOL_QUERY_CONTEXT *qc)
{
List *msgs;
POOL_PENDING_MESSAGE *msg;
* the pending message is one of primary or standby node.
*/
int
-pool_pending_message_get_target_backend_id(POOL_PENDING_MESSAGE * msg)
+pool_pending_message_get_target_backend_id(POOL_PENDING_MESSAGE *msg)
{
int backend_id = -1;
int i;
{
ListCell *cell;
ListCell *next;
- int cnt = 0;
- int i;
+ int cnt = 0;
+ int i;
if (!session_context)
{
foreach(msg_item, session_context->pending_messages)
{
POOL_PENDING_MESSAGE *msg = (POOL_PENDING_MESSAGE *) lfirst(msg_item);
+
msg->flush_pending = true;
ereport(DEBUG5,
(errmsg("pool_pending_message_set_flush_request: msg: %s",
* If the table already exists, just replace state.
*/
void
-pool_temp_tables_add(char * tablename, POOL_TEMP_TABLE_STATE state)
+pool_temp_tables_add(char *tablename, POOL_TEMP_TABLE_STATE state)
{
MemoryContext old_context;
- POOL_TEMP_TABLE * table;
+ POOL_TEMP_TABLE *table;
if (!session_context)
ereport(ERROR,
*/
POOL_TEMP_TABLE *
-pool_temp_tables_find(char * tablename)
+pool_temp_tables_find(char *tablename)
{
ListCell *cell;
foreach(cell, session_context->temp_tables)
{
- POOL_TEMP_TABLE * table = (POOL_TEMP_TABLE *)lfirst(cell);
+ POOL_TEMP_TABLE *table = (POOL_TEMP_TABLE *) lfirst(cell);
+
if (strcmp(tablename, table->tablename) == 0)
return table;
}
* the table state.
*/
void
-pool_temp_tables_delete(char * tablename, POOL_TEMP_TABLE_STATE state)
+pool_temp_tables_delete(char *tablename, POOL_TEMP_TABLE_STATE state)
{
- POOL_TEMP_TABLE * table;
+ POOL_TEMP_TABLE *table;
MemoryContext old_context;
if (!session_context)
Retry:
foreach(cell, session_context->temp_tables)
{
- POOL_TEMP_TABLE * table = (POOL_TEMP_TABLE *)lfirst(cell);
+ POOL_TEMP_TABLE *table = (POOL_TEMP_TABLE *) lfirst(cell);
if (table->state == TEMP_TABLE_CREATING)
{
Retry:
foreach(cell, session_context->temp_tables)
{
- POOL_TEMP_TABLE * table = (POOL_TEMP_TABLE *)lfirst(cell);
+ POOL_TEMP_TABLE *table = (POOL_TEMP_TABLE *) lfirst(cell);
if (table->state == TEMP_TABLE_CREATING || table->state == TEMP_TABLE_DROPPING)
{
foreach(cell, session_context->temp_tables)
{
- POOL_TEMP_TABLE * table = (POOL_TEMP_TABLE *)lfirst(cell);
+ POOL_TEMP_TABLE *table = (POOL_TEMP_TABLE *) lfirst(cell);
+
ereport(DEBUG1,
(errmsg("pool_temp_tables_dump: table %s state: %d",
table->tablename, table->state)));
#ifndef pool_auth_h
#define pool_auth_h
-extern void connection_do_auth(POOL_CONNECTION_POOL_SLOT * cp, char *password);
-extern int pool_do_auth(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend);
-extern int pool_do_reauth(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * cp);
-extern void authenticate_frontend(POOL_CONNECTION * frontend);
+extern void connection_do_auth(POOL_CONNECTION_POOL_SLOT *cp, char *password);
+extern int pool_do_auth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
+extern int pool_do_reauth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp);
+extern void authenticate_frontend(POOL_CONNECTION *frontend);
extern void pool_random_salt(char *md5Salt);
extern void pool_random(void *buf, size_t len);
-#endif /* pool_auth_h */
+#endif /* pool_auth_h */
char *ldapprefix;
char *ldapsuffix;
/* Additional LDAPl option with pgpool */
- bool backend_use_passwd; /* If true, pgpool use same password to auth backend */
+ bool backend_use_passwd; /* If true, pgpool use same password to
+ * auth backend */
};
extern bool load_hba(char *hbapath);
-extern void ClientAuthentication(POOL_CONNECTION * frontend);
+extern void ClientAuthentication(POOL_CONNECTION *frontend);
#endif /* POOL_HBA_H */
#define POOL_PASSWD_FILENAME "pool_passwd"
#define POOL_PASSWD_LEN 35
-#define MAX_POOL_PASSWD_LEN 132 /* In case of TEXT prefix(4byte) and plain text password(128byte)*/
+#define MAX_POOL_PASSWD_LEN 132 /* In case of TEXT prefix(4byte) and plain
+ * text password(128byte) */
#define MAX_USER_NAME_LEN 128
#define MAX_PGPASS_LEN 128
* pgpool-II child main process */
POOL_PASSWD_RW, /* open pool_passwd in read/write mode. used
* by pg_md5 command */
-} POOL_PASSWD_MODE;
+} POOL_PASSWD_MODE;
typedef enum PasswordType
{
char *userName;
char *password;
PasswordType passwordType;
-} UserPassword;
+} UserPassword;
typedef struct PasswordMapping
{
UserPassword pgpoolUser;
UserPassword backendUser;
bool mappedUser;
-} PasswordMapping;
+} PasswordMapping;
-extern PasswordMapping * pool_get_user_credentials(char *username);
+extern PasswordMapping *pool_get_user_credentials(char *username);
extern PasswordType get_password_type(const char *shadow_pass);
extern void pool_init_pool_passwd(char *pool_passwd_filename, POOL_PASSWD_MODE mode);
extern int pool_create_passwdent(char *username, char *passwd);
extern char *get_decrypted_password(const char *shadow_pass);
extern char *read_pool_key(char *key_file_path);
extern char *get_pgpool_config_user_password(char *username, char *password_in_config);
-extern void delete_passwordMapping(PasswordMapping * pwdMapping);
-extern int check_password_type_is_not_md5(char *username, char *password_in_config);
+extern void delete_passwordMapping(PasswordMapping *pwdMapping);
+extern int check_password_type_is_not_md5(char *username, char *password_in_config);
#endif /* POOL_PASSWD_H */
extern void scram_HMAC_final(uint8 *result, scram_HMAC_ctx *ctx);
extern void scram_SaltedPassword(const char *password, const char *salt,
- int saltlen, int iterations, uint8 *result);
+ int saltlen, int iterations, uint8 *result);
extern void scram_H(const uint8 *str, int len, uint8 *result);
extern void scram_ClientKey(const uint8 *salted_password, uint8 *result);
extern void scram_ServerKey(const uint8 *salted_password, uint8 *result);
extern char *scram_build_verifier(const char *salt, int saltlen, int iterations,
- const char *password);
+ const char *password);
#endif /* SCRAM_COMMON_H */
/* Routines dedicated to authentication */
extern void *pg_be_scram_init(const char *username, const char *shadow_pass);
-extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen,
- char **output, int *outputlen, char **logdetail);
+extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen,
+ char **output, int *outputlen, char **logdetail);
/* Routines to handle and check SCRAM-SHA-256 verifier */
extern char *pg_be_scram_build_verifier(const char *password);
extern bool scram_verify_plain_password(const char *username,
- const char *password, const char *verifier);
+ const char *password, const char *verifier);
extern void *pg_fe_scram_init(const char *username, const char *password);
extern void pg_fe_scram_exchange(void *opaq, char *input, int inputlen,
- char **output, int *outputlen,
- bool *done, bool *success);
+ char **output, int *outputlen,
+ bool *done, bool *success);
extern void pg_fe_scram_free(void *opaq);
extern char *pg_fe_scram_build_verifier(const char *password);
#ifndef POOL_PROCESS_CONTEXT_H
#define POOL_PROCESS_CONTEXT_H
-//#include "pool.h"
+/* #include "pool.h" */
#include "pcp/libpcp_ext.h"
#include "utils/pool_signal.h"
unsigned int last_alarm_second;
unsigned int undo_alarm_second;
-} POOL_PROCESS_CONTEXT;
+} POOL_PROCESS_CONTEXT;
extern void pool_init_process_context(void);
-extern POOL_PROCESS_CONTEXT * pool_get_process_context(void);
-extern ProcessInfo * pool_get_my_process_info(void);
+extern POOL_PROCESS_CONTEXT *pool_get_process_context(void);
+extern ProcessInfo *pool_get_my_process_info(void);
extern void pool_increment_local_session_id(void);
-extern size_t pool_coninfo_size(void);
+extern size_t pool_coninfo_size(void);
extern int pool_coninfo_num(void);
-extern ConnectionInfo * pool_coninfo(int child, int connection_pool, int backend);
-extern ConnectionInfo * pool_coninfo_pid(int pid, int connection_pool, int backend);
+extern ConnectionInfo *pool_coninfo(int child, int connection_pool, int backend);
+extern ConnectionInfo *pool_coninfo_pid(int pid, int connection_pool, int backend);
extern void pool_coninfo_set_frontend_connected(int proc_id, int pool_index);
extern void pool_coninfo_unset_frontend_connected(int proc_id, int pool_index);
-extern ConnectionInfo * pool_coninfo_backend_pid(int backend_pid, int *backend_node_id);
-extern void pool_set_connection_will_be_terminated(ConnectionInfo * connInfo);
-extern void pool_unset_connection_will_be_terminated(ConnectionInfo * connInfo);
+extern ConnectionInfo *pool_coninfo_backend_pid(int backend_pid, int *backend_node_id);
+extern void pool_set_connection_will_be_terminated(ConnectionInfo *connInfo);
+extern void pool_unset_connection_will_be_terminated(ConnectionInfo *connInfo);
extern void pool_alarm(pool_sighandler_t handler, unsigned int second);
extern void pool_undo_alarm(void);
POOL_PARSE_COMPLETE,
POOL_BIND_COMPLETE,
POOL_EXECUTE_COMPLETE
-} POOL_QUERY_STATE;
+} POOL_QUERY_STATE;
/*
* Query context:
Node *rewritten_parse_tree; /* rewritten raw parser output if any */
bool where_to_send[MAX_NUM_BACKENDS]; /* DB node map to send
* query */
- int load_balance_node_id; /* load balance node id per statement */
- int virtual_main_node_id; /* the 1st DB node to send query */
+ int load_balance_node_id; /* load balance node id per statement */
+ int virtual_main_node_id; /* the 1st DB node to send query */
POOL_QUERY_STATE query_state[MAX_NUM_BACKENDS]; /* for extended query
* protocol */
bool is_cache_safe; /* true if SELECT is safe to cache */
* extended query, do not commit cache if
* this flag is true. */
- bool atEnd; /* if true all rows have been already
- * fetched from the portal */
+ bool atEnd; /* if true all rows have been already fetched
+ * from the portal */
- bool partial_fetch; /* if true some rows have been fetched by
- * an execute with non 0 row option */
+ bool partial_fetch; /* if true some rows have been fetched by an
+ * execute with non 0 row option */
MemoryContext memory_context; /* memory context for query context */
-} POOL_QUERY_CONTEXT;
+} POOL_QUERY_CONTEXT;
-extern POOL_QUERY_CONTEXT * pool_init_query_context(void);
-extern void pool_query_context_destroy(POOL_QUERY_CONTEXT * query_context);
-extern POOL_QUERY_CONTEXT * pool_query_context_shallow_copy(POOL_QUERY_CONTEXT * query_context);
-extern void pool_start_query(POOL_QUERY_CONTEXT * query_context, char *query, int len, Node *node);
-extern void pool_set_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id);
-extern bool pool_is_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id);
-extern void pool_set_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id);
-extern void pool_unset_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id);
-extern void pool_clear_node_to_be_sent(POOL_QUERY_CONTEXT * query_context);
-extern void pool_setall_node_to_be_sent(POOL_QUERY_CONTEXT * query_context);
-extern bool pool_multi_node_to_be_sent(POOL_QUERY_CONTEXT * query_context);
-extern void pool_where_to_send(POOL_QUERY_CONTEXT * query_context, char *query, Node *node);
-extern POOL_STATUS pool_send_and_wait(POOL_QUERY_CONTEXT * query_context, int send_type, int node_id);
-extern POOL_STATUS pool_extended_send_and_wait(POOL_QUERY_CONTEXT * query_context, char *kind, int len, char *contents, int send_type, int node_id, bool nowait);
+extern POOL_QUERY_CONTEXT *pool_init_query_context(void);
+extern void pool_query_context_destroy(POOL_QUERY_CONTEXT *query_context);
+extern POOL_QUERY_CONTEXT *pool_query_context_shallow_copy(POOL_QUERY_CONTEXT *query_context);
+extern void pool_start_query(POOL_QUERY_CONTEXT *query_context, char *query, int len, Node *node);
+extern void pool_set_node_to_be_sent(POOL_QUERY_CONTEXT *query_context, int node_id);
+extern bool pool_is_node_to_be_sent(POOL_QUERY_CONTEXT *query_context, int node_id);
+extern void pool_set_node_to_be_sent(POOL_QUERY_CONTEXT *query_context, int node_id);
+extern void pool_unset_node_to_be_sent(POOL_QUERY_CONTEXT *query_context, int node_id);
+extern void pool_clear_node_to_be_sent(POOL_QUERY_CONTEXT *query_context);
+extern void pool_setall_node_to_be_sent(POOL_QUERY_CONTEXT *query_context);
+extern bool pool_multi_node_to_be_sent(POOL_QUERY_CONTEXT *query_context);
+extern void pool_where_to_send(POOL_QUERY_CONTEXT *query_context, char *query, Node *node);
+extern POOL_STATUS pool_send_and_wait(POOL_QUERY_CONTEXT *query_context, int send_type, int node_id);
+extern POOL_STATUS pool_extended_send_and_wait(POOL_QUERY_CONTEXT *query_context, char *kind, int len, char *contents, int send_type, int node_id, bool nowait);
extern Node *pool_get_parse_tree(void);
extern char *pool_get_query_string(void);
extern bool is_set_transaction_serializable(Node *node);
extern bool is_start_transaction_query(Node *node);
extern bool is_read_write(TransactionStmt *node);
extern bool is_serializable(TransactionStmt *node);
-extern bool pool_need_to_treat_as_if_default_transaction(POOL_QUERY_CONTEXT * query_context);
+extern bool pool_need_to_treat_as_if_default_transaction(POOL_QUERY_CONTEXT *query_context);
extern bool is_savepoint_query(Node *node);
extern bool is_2pc_transaction_query(Node *node);
-extern void pool_set_query_state(POOL_QUERY_CONTEXT * query_context, POOL_QUERY_STATE state);
+extern void pool_set_query_state(POOL_QUERY_CONTEXT *query_context, POOL_QUERY_STATE state);
extern int statecmp(POOL_QUERY_STATE s1, POOL_QUERY_STATE s2);
extern bool pool_is_cache_safe(void);
extern void pool_set_cache_safe(void);
extern void pool_set_cache_exceeded(void);
extern void pool_unset_cache_exceeded(void);
extern bool pool_is_transaction_read_only(Node *node);
-extern void pool_force_query_node_to_backend(POOL_QUERY_CONTEXT * query_context, int backend_id);
+extern void pool_force_query_node_to_backend(POOL_QUERY_CONTEXT *query_context, int backend_id);
extern void check_object_relationship_list(char *name, bool is_func_name);
-extern int wait_for_failover_to_finish(void);
+extern int wait_for_failover_to_finish(void);
#endif /* POOL_QUERY_CONTEXT_H */
POOL_READ_COMMITTED, /* Read committed */
POOL_REPEATABLE_READ, /* Repeatable read */
POOL_SERIALIZABLE /* Serializable */
-} POOL_TRANSACTION_ISOLATION;
+} POOL_TRANSACTION_ISOLATION;
/*
* Return values for pool_use_sync_map
POOL_SENT_MESSAGE_CREATED, /* initial state of sent message */
POOL_SENT_MESSAGE_CLOSED /* sent message closed but close complete
* message has not arrived yet */
-} POOL_SENT_MESSAGE_STATE;
+} POOL_SENT_MESSAGE_STATE;
/*
* Message content of extended query
int param_offset; /* Offset from contents where actual bind
* parameters are stored. This is meaningful
* only when is_cache_safe is true. */
-} POOL_SENT_MESSAGE;
+} POOL_SENT_MESSAGE;
/*
* List of POOL_SENT_MESSAGE (XXX this should have been implemented using a
int capacity; /* capacity of list */
int size; /* number of elements */
POOL_SENT_MESSAGE **sent_messages;
-} POOL_SENT_MESSAGE_LIST;
+} POOL_SENT_MESSAGE_LIST;
/*
* Received message queue used in extended query/streaming replication mode.
POOL_DESCRIBE,
POOL_CLOSE,
POOL_SYNC
-} POOL_MESSAGE_TYPE;
+} POOL_MESSAGE_TYPE;
typedef struct
{
bool not_forward_to_frontend; /* Do not forward response from
* backend to frontend. This is
* used by parse_before_bind() */
- bool node_ids[MAX_NUM_BACKENDS]; /* backend node map which this message was sent to */
+ bool node_ids[MAX_NUM_BACKENDS]; /* backend node map which this
+ * message was sent to */
POOL_QUERY_CONTEXT *query_context; /* query context */
+
/*
* If "flush" message arrives, this flag is set to true until all buffered
* message for frontend are sent out.
*/
bool flush_pending;
- bool is_tx_started_by_multi_statement; /* true if an explicit transaction has been started by
- multi statement query */
-} POOL_PENDING_MESSAGE;
+ bool is_tx_started_by_multi_statement; /* true if an explicit
+ * transaction has been
+ * started by multi
+ * statement query */
+} POOL_PENDING_MESSAGE;
-typedef enum {
- TEMP_TABLE_CREATING = 1, /* temp table creating, not committed yet. */
- TEMP_TABLE_DROPPING, /* temp table dropping, not committed yet. */
- TEMP_TABLE_CREATE_COMMITTED, /* temp table created and committed. */
- TEMP_TABLE_DROP_COMMITTED, /* temp table dropped and committed. */
-} POOL_TEMP_TABLE_STATE;
+typedef enum
+{
+ TEMP_TABLE_CREATING = 1, /* temp table creating, not committed yet. */
+ TEMP_TABLE_DROPPING, /* temp table dropping, not committed yet. */
+ TEMP_TABLE_CREATE_COMMITTED, /* temp table created and committed. */
+ TEMP_TABLE_DROP_COMMITTED, /* temp table dropped and committed. */
+} POOL_TEMP_TABLE_STATE;
-typedef struct {
+typedef struct
+{
char tablename[MAX_IDENTIFIER_LEN]; /* temporary table name */
- POOL_TEMP_TABLE_STATE state; /* see above */
-} POOL_TEMP_TABLE;
+ POOL_TEMP_TABLE_STATE state; /* see above */
+} POOL_TEMP_TABLE;
typedef enum
int preferred_main_node_id;
#endif
- /* Whether snapshot is acquired in this transaction. Only used by Snapshot Isolation mode. */
+ /*
+ * Whether snapshot is acquired in this transaction. Only used by Snapshot
+ * Isolation mode.
+ */
SI_STATE si_state;
/* Whether transaction is read only. Only used by Snapshot Isolation mode. */
SI_STATE transaction_read_only;
* transaction has been
* started by a
* multi-statement-query */
+
/*
- * True if query cache feature disabled until session ends.
- * This is set when SET ROLE/SET SESSION AUTHORIZATION executed.
+ * True if query cache feature disabled until session ends. This is set
+ * when SET ROLE/SET SESSION AUTHORIZATION executed.
*/
- bool query_cache_disabled;
+ bool query_cache_disabled;
+
/*
* True if query cache feature disabled until current transaction ends.
* This is set when REVOKE executed in a transaction.
*/
- bool query_cache_disabled_tx;
+ bool query_cache_disabled_tx;
-} POOL_SESSION_CONTEXT;
+} POOL_SESSION_CONTEXT;
-extern void pool_init_session_context(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend);
+extern void pool_init_session_context(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
extern void pool_session_context_destroy(void);
-extern POOL_SESSION_CONTEXT * pool_get_session_context(bool noerror);
+extern POOL_SESSION_CONTEXT *pool_get_session_context(bool noerror);
extern int pool_get_local_session_id(void);
extern bool pool_is_query_in_progress(void);
extern void pool_set_query_in_progress(void);
extern bool pool_is_ignore_till_sync(void);
extern void pool_set_ignore_till_sync(void);
extern void pool_unset_ignore_till_sync(void);
-extern POOL_SENT_MESSAGE * pool_create_sent_message(char kind, int len, char *contents,
- int num_tsparams, const char *name,
- POOL_QUERY_CONTEXT * query_context);
-extern void pool_add_sent_message(POOL_SENT_MESSAGE * message);
+extern POOL_SENT_MESSAGE *pool_create_sent_message(char kind, int len, char *contents,
+ int num_tsparams, const char *name,
+ POOL_QUERY_CONTEXT *query_context);
+extern void pool_add_sent_message(POOL_SENT_MESSAGE *message);
extern bool pool_remove_sent_message(char kind, const char *name);
extern void pool_remove_sent_messages(char kind);
extern void pool_clear_sent_message_list(void);
-extern void pool_sent_message_destroy(POOL_SENT_MESSAGE * message);
-extern POOL_SENT_MESSAGE * pool_get_sent_message(char kind, const char *name, POOL_SENT_MESSAGE_STATE state);
-extern void pool_set_sent_message_state(POOL_SENT_MESSAGE * message);
+extern void pool_sent_message_destroy(POOL_SENT_MESSAGE *message);
+extern POOL_SENT_MESSAGE *pool_get_sent_message(char kind, const char *name, POOL_SENT_MESSAGE_STATE state);
+extern void pool_set_sent_message_state(POOL_SENT_MESSAGE *message);
extern void pool_zap_query_context_in_sent_messages(POOL_QUERY_CONTEXT *query_context);
-extern POOL_SENT_MESSAGE * pool_get_sent_message_by_query_context(POOL_QUERY_CONTEXT * query_context);
+extern POOL_SENT_MESSAGE *pool_get_sent_message_by_query_context(POOL_QUERY_CONTEXT *query_context);
extern void pool_unset_writing_transaction(void);
extern void pool_set_writing_transaction(void);
extern bool pool_is_writing_transaction(void);
extern void pool_set_command_success(void);
extern bool pool_is_command_success(void);
extern void pool_copy_prep_where(bool *src, bool *dest);
-extern bool can_query_context_destroy(POOL_QUERY_CONTEXT * qc);
+extern bool can_query_context_destroy(POOL_QUERY_CONTEXT *qc);
extern void pool_pending_messages_init(void);
extern void pool_pending_messages_destroy(void);
-extern POOL_PENDING_MESSAGE * pool_pending_message_create(char kind, int len, char *contents);
-extern void pool_pending_message_free_pending_message(POOL_PENDING_MESSAGE * message);
-extern void pool_pending_message_dest_set(POOL_PENDING_MESSAGE * message, POOL_QUERY_CONTEXT * query_context);
-extern void pool_pending_message_query_context_dest_set(POOL_PENDING_MESSAGE * message, POOL_QUERY_CONTEXT * query_context);
-extern void pool_pending_message_query_set(POOL_PENDING_MESSAGE * message, POOL_QUERY_CONTEXT * query_context);
-extern void pool_pending_message_add(POOL_PENDING_MESSAGE * message);
-extern POOL_PENDING_MESSAGE * pool_pending_message_head_message(void);
-extern POOL_PENDING_MESSAGE * pool_pending_message_pull_out(void);
-extern POOL_PENDING_MESSAGE * pool_pending_message_get(POOL_MESSAGE_TYPE type);
-extern char pool_get_close_message_spec(POOL_PENDING_MESSAGE * msg);
-extern char *pool_get_close_message_name(POOL_PENDING_MESSAGE * msg);
+extern POOL_PENDING_MESSAGE *pool_pending_message_create(char kind, int len, char *contents);
+extern void pool_pending_message_free_pending_message(POOL_PENDING_MESSAGE *message);
+extern void pool_pending_message_dest_set(POOL_PENDING_MESSAGE *message, POOL_QUERY_CONTEXT *query_context);
+extern void pool_pending_message_query_context_dest_set(POOL_PENDING_MESSAGE *message, POOL_QUERY_CONTEXT *query_context);
+extern void pool_pending_message_query_set(POOL_PENDING_MESSAGE *message, POOL_QUERY_CONTEXT *query_context);
+extern void pool_pending_message_add(POOL_PENDING_MESSAGE *message);
+extern POOL_PENDING_MESSAGE *pool_pending_message_head_message(void);
+extern POOL_PENDING_MESSAGE *pool_pending_message_pull_out(void);
+extern POOL_PENDING_MESSAGE *pool_pending_message_get(POOL_MESSAGE_TYPE type);
+extern char pool_get_close_message_spec(POOL_PENDING_MESSAGE *msg);
+extern char *pool_get_close_message_name(POOL_PENDING_MESSAGE *msg);
extern void pool_pending_message_reset_previous_message(void);
-extern void pool_pending_message_set_previous_message(POOL_PENDING_MESSAGE * message);
-extern POOL_PENDING_MESSAGE * pool_pending_message_get_previous_message(void);
+extern void pool_pending_message_set_previous_message(POOL_PENDING_MESSAGE *message);
+extern POOL_PENDING_MESSAGE *pool_pending_message_get_previous_message(void);
extern bool pool_pending_message_exists(void);
extern const char *pool_pending_message_type_to_string(POOL_MESSAGE_TYPE type);
extern void pool_check_pending_message_and_reply(POOL_MESSAGE_TYPE type, char kind);
-extern POOL_PENDING_MESSAGE * pool_pending_message_find_lastest_by_query_context(POOL_QUERY_CONTEXT * qc);
-extern int pool_pending_message_get_target_backend_id(POOL_PENDING_MESSAGE * msg);
+extern POOL_PENDING_MESSAGE *pool_pending_message_find_lastest_by_query_context(POOL_QUERY_CONTEXT *qc);
+extern int pool_pending_message_get_target_backend_id(POOL_PENDING_MESSAGE *msg);
extern int pool_pending_message_get_message_num_by_backend_id(int backend_id);
extern void pool_pending_message_set_flush_request(void);
extern void dump_pending_message(void);
extern void pool_temp_tables_init(void);
extern void pool_temp_tables_destroy(void);
-extern void pool_temp_tables_add(char * tablename, POOL_TEMP_TABLE_STATE state);
-extern POOL_TEMP_TABLE * pool_temp_tables_find(char * tablename);
-extern void pool_temp_tables_delete(char * tablename, POOL_TEMP_TABLE_STATE state);
-extern void pool_temp_tables_commit_pending(void);
-extern void pool_temp_tables_remove_pending(void);
-extern void pool_temp_tables_dump(void);
+extern void pool_temp_tables_add(char *tablename, POOL_TEMP_TABLE_STATE state);
+extern POOL_TEMP_TABLE *pool_temp_tables_find(char *tablename);
+extern void pool_temp_tables_delete(char *tablename, POOL_TEMP_TABLE_STATE state);
+extern void pool_temp_tables_commit_pending(void);
+extern void pool_temp_tables_remove_pending(void);
+extern void pool_temp_tables_dump(void);
extern bool is_tx_started_by_multi_statement_query(void);
extern void set_tx_started_by_multi_statement_query(void);
/*
* Health check statistics per node
*/
-typedef struct {
- uint64 total_count; /* total count of health check */
- uint64 success_count; /* total count of successful health check */
- uint64 fail_count; /* total count of failed health check */
- uint64 skip_count; /* total count of skipped health check */
- uint64 retry_count; /* total count of health check retries */
- uint32 max_retry_count; /* max retry count in a health check session */
- uint64 total_health_check_duration; /* sum of health check duration */
- int32 max_health_check_duration; /* maximum duration spent for a health check session in milli seconds */
- int32 min_health_check_duration; /* minimum duration spent for a health check session in milli seconds */
- time_t last_health_check; /* last health check timestamp */
- time_t last_successful_health_check; /* last successful health check timestamp */
- time_t last_skip_health_check; /* last skipped health check timestamp */
- time_t last_failed_health_check; /* last failed health check timestamp */
+typedef struct
+{
+ uint64 total_count; /* total count of health check */
+ uint64 success_count; /* total count of successful health check */
+ uint64 fail_count; /* total count of failed health check */
+ uint64 skip_count; /* total count of skipped health check */
+ uint64 retry_count; /* total count of health check retries */
+ uint32 max_retry_count; /* max retry count in a health check
+ * session */
+ uint64 total_health_check_duration; /* sum of health check
+ * duration */
+ int32 max_health_check_duration; /* maximum duration spent for a
+ * health check session in milli
+ * seconds */
+ int32 min_health_check_duration; /* minimum duration spent for a
+ * health check session in milli
+ * seconds */
+ time_t last_health_check; /* last health check timestamp */
+ time_t last_successful_health_check; /* last successful health
+ * check timestamp */
+ time_t last_skip_health_check; /* last skipped health check timestamp */
+ time_t last_failed_health_check; /* last failed health check
+ * timestamp */
} POOL_HEALTH_CHECK_STATISTICS;
-extern volatile POOL_HEALTH_CHECK_STATISTICS *health_check_stats; /* health check stats area in shared memory */
+extern volatile POOL_HEALTH_CHECK_STATISTICS *health_check_stats; /* health check stats
+ * area in shared memory */
extern void do_health_check_child(int *node_id);
-extern size_t health_check_stats_shared_memory_size(void);
-extern void health_check_stats_init(POOL_HEALTH_CHECK_STATISTICS *addr);
+extern size_t health_check_stats_shared_memory_size(void);
+extern void health_check_stats_init(POOL_HEALTH_CHECK_STATISTICS *addr);
-#endif /* health_check_h */
+#endif /* health_check_h */
int32 pid; /* writer's pid */
char is_last; /* last chunk of message? 't' or 'f' ('T' or
* 'F' for CSV case) */
- char data[]; /* data payload starts here */
+ char data[]; /* data payload starts here */
} PipeProtoHeader;
typedef union
extern void register_inform_quarantine_nodes_req(void);
extern bool register_node_operation_request(POOL_REQUEST_KIND kind,
int *node_id_set, int count, unsigned char flags);
-#endif /* pool_internal_comms_h */
+#endif /* pool_internal_comms_h */
EXPLAIN_FORMAT_XML,
EXPLAIN_FORMAT_JSON,
EXPLAIN_FORMAT_YAML
-} ExplainFormat;
+} ExplainFormat;
typedef struct ExplainState
{
List *rtable_names; /* alias names for RTEs */
List *deparse_cxt; /* context list for deparsing expressions */
Bitmapset *printed_subplans; /* ids of SubPlans we've printed */
-} ExplainState;
+} ExplainState;
/* Hook for plugins to get control in ExplainOneQuery() */
typedef void (*ExplainOneQuery_hook_type) (Query *query,
IntoClause *into,
- ExplainState *es,
+ ExplainState * es,
const char *queryString,
ParamListInfo params);
extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook;
extern void ExplainQuery(ExplainStmt *stmt, const char *queryString,
- ParamListInfo params, DestReceiver *dest);
+ ParamListInfo params, DestReceiver * dest);
-extern ExplainState *NewExplainState(void);
+extern ExplainState * NewExplainState(void);
extern TupleDesc ExplainResultDesc(ExplainStmt *stmt);
extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
- ExplainState *es,
- const char *queryString, ParamListInfo params);
+ ExplainState * es,
+ const char *queryString, ParamListInfo params);
-extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
- ExplainState *es, const char *queryString,
- ParamListInfo params, const instr_time *planduration);
+extern void ExplainOnePlan(PlannedStmt * plannedstmt, IntoClause *into,
+ ExplainState * es, const char *queryString,
+ ParamListInfo params, const instr_time * planduration);
-extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
-extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
+extern void ExplainPrintPlan(ExplainState * es, QueryDesc * queryDesc);
+extern void ExplainPrintTriggers(ExplainState * es, QueryDesc * queryDesc);
-extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
+extern void ExplainQueryText(ExplainState * es, QueryDesc * queryDesc);
-extern void ExplainBeginOutput(ExplainState *es);
-extern void ExplainEndOutput(ExplainState *es);
-extern void ExplainSeparatePlans(ExplainState *es);
+extern void ExplainBeginOutput(ExplainState * es);
+extern void ExplainEndOutput(ExplainState * es);
+extern void ExplainSeparatePlans(ExplainState * es);
extern void ExplainPropertyList(const char *qlabel, List *data,
- ExplainState *es);
+ ExplainState * es);
extern void ExplainPropertyListNested(const char *qlabel, List *data,
- ExplainState *es);
+ ExplainState * es);
extern void ExplainPropertyText(const char *qlabel, const char *value,
- ExplainState *es);
+ ExplainState * es);
extern void ExplainPropertyInteger(const char *qlabel, int value,
- ExplainState *es);
+ ExplainState * es);
extern void ExplainPropertyLong(const char *qlabel, long value,
- ExplainState *es);
+ ExplainState * es);
extern void ExplainPropertyFloat(const char *qlabel, double value, int ndigits,
- ExplainState *es);
+ ExplainState * es);
extern void ExplainPropertyBool(const char *qlabel, bool value,
- ExplainState *es);
+ ExplainState * es);
#endif /* EXPLAIN_H */
{
NodeTag type;
const char *extnodename; /* identifier of ExtensibleNodeMethods */
-} ExtensibleNode;
+} ExtensibleNode;
/*
* node_size is the size of an extensible node of this type in bytes.
void (*nodeOut) (struct StringInfoData *str,
const struct ExtensibleNode *node);
void (*nodeRead) (struct ExtensibleNode *node);
-} ExtensibleNodeMethods;
+} ExtensibleNodeMethods;
-extern void RegisterExtensibleNodeMethods(const ExtensibleNodeMethods *method);
+extern void RegisterExtensibleNodeMethods(const ExtensibleNodeMethods * method);
extern const ExtensibleNodeMethods *GetExtensibleNodeMethods(const char *name,
- bool missing_ok);
+ bool missing_ok);
/*
* Flags for custom paths, indicating what capabilities the resulting scan
/* from parser.c */
-extern int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp,
- core_yyscan_t yyscanner);
-extern int minimal_base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp,
+extern int base_yylex(YYSTYPE *lvalp, YYLTYPE * llocp,
core_yyscan_t yyscanner);
+extern int minimal_base_yylex(YYSTYPE *lvalp, YYLTYPE * llocp,
+ core_yyscan_t yyscanner);
/* from gram.y */
extern void parser_init(base_yy_extra_type *yyext);
T_Invalid = 0,
/* pgpool Extension */
- T_PgpoolVariableSetStmt,
- T_PgpoolVariableShowStmt,
- T_PgpoolQueryCacheStmt,
+ T_PgpoolVariableSetStmt,
+ T_PgpoolVariableShowStmt,
+ T_PgpoolQueryCacheStmt,
#include "nodetags.h"
} NodeTag;
extern void outBitmapset(struct StringInfoData *str,
const struct Bitmapset *bms);
extern void outDatum(struct StringInfoData *str, uintptr_t value,
- int typlen, bool typbyval);
+ int typlen, bool typbyval);
extern char *nodeToString(const void *obj);
extern char *nodeToStringWithLocations(const void *obj);
extern char *bmsToString(const struct Bitmapset *bms);
AGG_SORTED, /* grouped agg, input must be sorted */
AGG_HASHED, /* grouped agg, use internal hashtable */
AGG_MIXED, /* grouped agg, hash and sort both used */
-} AggStrategy;
+} AggStrategy;
/*
* AggSplit -
SETOPCMD_INTERSECT_ALL,
SETOPCMD_EXCEPT,
SETOPCMD_EXCEPT_ALL,
-} SetOpCmd;
+} SetOpCmd;
typedef enum SetOpStrategy
{
SETOP_SORTED, /* input must be sorted */
SETOP_HASHED, /* use internal hashtable */
-} SetOpStrategy;
+} SetOpStrategy;
/*
* OnConflictAction -
List *lowerdatums; /* List of PartitionRangeDatums */
List *upperdatums; /* List of PartitionRangeDatums */
- ParseLoc location; /* token location, or -1 if unknown */
+ ParseLoc location; /* token location, or -1 if unknown */
} PartitionBoundSpec;
/*
typedef struct SinglePartitionSpec
{
NodeTag type;
-} SinglePartitionSpec;
+} SinglePartitionSpec;
/*
* PartitionCmd - info for ALTER TABLE/INDEX ATTACH/DETACH PARTITION commands
Bitmapset *selectedCols; /* columns needing SELECT permission */
Bitmapset *insertedCols; /* columns needing INSERT permission */
Bitmapset *updatedCols; /* columns needing UPDATE permission */
-} RTEPermissionInfo;
+} RTEPermissionInfo;
/*
* RangeTblFunction -
NodeTag type;
bool is_grant; /* true = GRANT, false = REVOKE */
GrantTargetType targtype; /* type of the grant target */
- ObjectType objtype; /* kind of object being operated on */
+ ObjectType objtype; /* kind of object being operated on */
List *objects; /* list of RangeVar nodes, ObjectWithArgs
* nodes, or plain names (as String values) */
List *privileges; /* list of AccessPriv nodes */
Oid langOid; /* OID of selected language */
bool langIsTrusted; /* trusted property of the language */
bool atomic; /* atomic execution context */
-} InlineCodeBlock;
+} InlineCodeBlock;
/* ----------------------
* CALL statement
NodeTag type;
bool atomic;
-} CallContext;
+} CallContext;
/* ----------------------
* Alter Object Rename Statement
extern List *get_dummy_write_query_tree(void);
extern List *get_dummy_read_query_tree(void);
-extern Node * get_dummy_insert_query_node(void);
+extern Node *get_dummy_insert_query_node(void);
#endif /* PARSER_H */
* the format of pg_class relation.