~ubuntu-branches/ubuntu/oneiric/pgpool2/oneiric

« back to all changes in this revision

Viewing changes to pool.h

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy
  • Date: 2010-02-17 13:58:08 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217135808-vqxtfe80r5z8toje
Tags: 2.3.2.1-0ubuntu1
* New upstream release (2.3.2.1)
 * Lots of bug fixes
 * Add SSL support
 * Add support for large object replication
 * Enhanced replication (TIMESTAMP, DATES)
 * Save node status on restart
 * Some other minor changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*-pgsql-c-*- */
2
2
/*
3
3
 *
4
 
 * $Header: /cvsroot/pgpool/pgpool-II/pool.h,v 1.36.2.4 2009/07/22 08:46:55 t-ishii Exp $
 
4
 * $Header: /cvsroot/pgpool/pgpool-II/pool.h,v 1.56 2010/02/03 08:11:42 t-ishii Exp $
5
5
 *
6
6
 * pgpool: a language independent connection pool server for PostgreSQL 
7
7
 * written by Tatsuo Ishii
8
8
 *
9
 
 * Copyright (c) 2003-2009      PgPool Global Development Group
 
9
 * Copyright (c) 2003-2010      PgPool Global Development Group
10
10
 *
11
11
 * Permission to use, copy, modify, and distribute this software and
12
12
 * its documentation for any purpose and without fee is hereby
35
35
#include <sys/types.h>
36
36
#include <limits.h>
37
37
 
 
38
#ifdef USE_SSL
 
39
#include <openssl/crypto.h>
 
40
#include <openssl/ssl.h>
 
41
#include <openssl/err.h>
 
42
#endif
 
43
 
38
44
/* undef this if you have problems with non blocking accept() */
39
45
#define NONE_BLOCK
40
46
 
58
64
/* pid file name */
59
65
#define DEFAULT_PID_FILE_NAME "/var/run/pgpool/pgpool.pid"
60
66
 
 
67
/* status file name */
 
68
#define STATUS_FILE_NAME "pgpool_status"
 
69
 
61
70
typedef enum {
62
71
        POOL_CONTINUE = 0,
63
72
        POOL_IDLE,
161
170
        char *health_check_user;                /* PostgreSQL user name for health check */
162
171
        char *failover_command;     /* execute command when failover happens */
163
172
        char *failback_command;     /* execute command when failback happens */
 
173
 
 
174
        /*
 
175
         * If true, trigger fail over when writing to the backend
 
176
         * communication socket fails. This is the same behavior of
 
177
         * pgpool-II 2.2.x or earlier. If set to false, pgpool will report
 
178
         * an error and disconnect the session.
 
179
         */
 
180
        int     fail_over_on_backend_error;
 
181
 
164
182
        char *recovery_user;            /* PostgreSQL user name for online recovery */
165
183
        char *recovery_password;                /* PostgreSQL user password for online recovery */
166
184
        char *recovery_1st_stage_command;   /* Online recovery command in 1st stage */
173
191
                                                   data consistency */
174
192
        int ignore_leading_white_space;         /* ignore leading white spaces of each query */
175
193
        int log_statement; /* 0:false, 1: true - logs all SQL statements */
 
194
        int log_per_node_statement; /* 0:false, 1: true - logs per node detailed SQL statements */
176
195
 
177
196
        int parallel_mode;      /* if non 0, run in parallel query mode */
178
197
 
186
205
        char *system_db_user;           /* user name to access system DB */
187
206
        char *system_db_password;       /* password to access system DB */
188
207
 
 
208
        char *lobj_lock_table;          /* table name to lock for rewriting lo_creat */
 
209
 
189
210
        BackendDesc *backend_desc;      /* PostgreSQL Server description. Placed on shared memory */
190
211
 
191
212
        LOAD_BALANCE_STATUS     load_balance_status[MAX_NUM_BACKENDS];  /* to remember which DB node is selected for load balancing */
195
216
        int replication_enabled;                /* replication mode enabled */
196
217
        int master_slave_enabled;               /* master/slave mode enabled */
197
218
        int num_reset_queries;          /* number of queries in reset_query_list */
 
219
 
 
220
        /* ssl configuration */
 
221
        int ssl;        /* if non 0, activate ssl support (frontend+backend) */
 
222
        char *ssl_cert; /* path to ssl certificate (frontend only) */
 
223
        char *ssl_key;  /* path to ssl key (frontend only) */
 
224
        char *ssl_ca_cert;      /* path to root (CA) certificate */
 
225
        char *ssl_ca_cert_dir;  /* path to directory containing CA certificates */
198
226
} POOL_CONFIG;
199
227
 
200
228
#define MAX_PASSWORD_SIZE               1024
215
243
        int wbufsz;     /* write buffer size */
216
244
        int wbufpo;     /* buffer offset */
217
245
 
 
246
#ifdef USE_SSL
 
247
        SSL_CTX *ssl_ctx; /* SSL connection context */
 
248
        SSL *ssl;       /* SSL connection */
 
249
#endif
 
250
        int ssl_active; /* SSL is failed if < 0, off if 0, on if > 0 */
 
251
 
218
252
        char *hp;       /* pending data buffer head address */
219
253
        int po;         /* pending data offset */
220
254
        int bufsz;      /* pending data buffer size */
309
343
        UNIT unit;
310
344
} Interval;
311
345
 
 
346
/*
 
347
 * Relation cache structure
 
348
 */
 
349
#define MAX_ITEM_LENGTH 1024
 
350
 
 
351
/* Relation lookup cache structure */
 
352
 
 
353
typedef void *(*func_ptr) ();
 
354
 
 
355
typedef struct {
 
356
        char dbname[MAX_ITEM_LENGTH];   /* database name */
 
357
        char relname[MAX_ITEM_LENGTH];  /* table name */
 
358
        void *data;     /* user data */
 
359
        int refcnt;             /* reference count */
 
360
        int session_id;         /* LocalSessionId */
 
361
} PoolRelCache;
 
362
 
 
363
typedef struct {
 
364
        int num;                /* number of cache items */
 
365
        char sql[MAX_ITEM_LENGTH];      /* Query to relation */
 
366
        /*
 
367
         * User defined function to be called at data register.
 
368
         * Argument is POOL_SELECT_RESULT *.
 
369
         * This function must return a pointer to be
 
370
         * saved in cache->data.
 
371
         */
 
372
        func_ptr        register_func;
 
373
        /*
 
374
         * User defined function to be called at data unregister.
 
375
         * Argument cache->data.
 
376
         */
 
377
        func_ptr        unregister_func;
 
378
        bool cache_is_session_local;            /* True if cache life time is session local */
 
379
        PoolRelCache *cache;    /* cache data */
 
380
} POOL_RELCACHE;
 
381
 
 
382
 
312
383
#ifdef NOT_USED
313
384
#define NUM_BACKENDS (in_load_balance? (selected_slot+1) : \
314
385
                                          (((!REPLICATION && !PARALLEL_MODE)||master_slave_dml)? Req_info->master_node_id+1: \
350
421
#define LOCK_COMMENT_SZ (sizeof(LOCK_COMMENT)-1)
351
422
#define NO_LOCK_COMMENT "/*NO INSERT LOCK*/"
352
423
#define NO_LOCK_COMMENT_SZ (sizeof(NO_LOCK_COMMENT)-1)
 
424
#define NO_LOAD_BALANCE "/*NO LOAD BALANCE*/"
 
425
#define NO_LOAD_BALANCE_COMMENT_SZ (sizeof(NO_LOAD_BALANCE)-1)
353
426
 
354
427
#define MAX_NUM_SEMAPHORES              3
355
428
#define CONN_COUNTER_SEM 0
429
502
#define QUERY_STRING_BUFFER_LEN 1024
430
503
extern char query_string_buffer[];              /* last query string sent to simpleQuery() */
431
504
 
 
505
extern int LocalSessionId;      /* Local session id. incremented when new frontend connected */
 
506
 
432
507
/*
433
508
 * public functions
434
509
 */
454
529
extern int pool_init_cp(void);
455
530
extern POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
456
531
                                                                          POOL_CONNECTION_POOL *backend,
457
 
                                                                          int connection_reuse,
458
 
                                                                          int first_ready_for_query_received);
 
532
                                                                          int reset_request);
459
533
 
460
534
extern POOL_CONNECTION *pool_open(int fd);
461
535
extern void pool_close(POOL_CONNECTION *cp);
477
551
extern void pool_discard_cp(char *user, char *database, int protoMajor);
478
552
extern void pool_backend_timer(void);
479
553
 
 
554
/* SSL functionality */
 
555
extern void pool_ssl_negotiate_serverclient(POOL_CONNECTION *cp);
 
556
extern void pool_ssl_negotiate_clientserver(POOL_CONNECTION *cp);
 
557
extern void pool_ssl_close(POOL_CONNECTION *cp);
 
558
extern int pool_ssl_read(POOL_CONNECTION *cp, void *buf, int size);
 
559
extern int pool_ssl_write(POOL_CONNECTION *cp, const void *buf, int size);
 
560
 
480
561
extern POOL_STATUS ErrorResponse(POOL_CONNECTION *frontend, 
481
562
                                                                  POOL_CONNECTION_POOL *backend);
482
563
 
523
604
                                                         char *hint,
524
605
                                                         char *file,
525
606
                                                         int line);
 
607
extern void pool_send_fatal_message(POOL_CONNECTION *frontend, int protoMajor,
 
608
                                                         char *code,
 
609
                                                         char *message,
 
610
                                                         char *detail,
 
611
                                                         char *hint,
 
612
                                                         char *file,
 
613
                                                         int line);
 
614
extern void pool_send_severity_message(POOL_CONNECTION *frontend, int protoMajor,
 
615
                                                         char *code,
 
616
                                                         char *message,
 
617
                                                         char *detail,
 
618
                                                         char *hint,
 
619
                                                         char *file,
 
620
                                                         char *severity,
 
621
                                                         int line);
526
622
extern void pool_send_readyforquery(POOL_CONNECTION *frontend);
527
623
extern int send_startup_packet(POOL_CONNECTION_POOL_SLOT *cp);
528
624
extern void pool_free_startup_packet(StartupPacket *sp);
529
625
extern void child_exit(int code);
530
626
 
531
 
extern void connection_count_up(void);
532
 
extern void connection_count_down(void);
533
 
 
534
627
extern int health_check(void);
535
628
extern int system_db_health_check(void);
536
629
 
553
646
extern POOL_CONNECTION_POOL_SLOT *make_persistent_db_connection(
554
647
        char *hostname, int port, char *dbname, char *user, char *password);
555
648
 
556
 
extern POOL_STATUS do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result);
557
 
 
558
649
/* define pool_system.c */
559
650
extern POOL_CONNECTION_POOL_SLOT *pool_system_db_connection(void);
560
651
extern DistDefInfo *pool_get_dist_def_info (char * dbname, char * schema_name, char * table_name);
596
687
extern void pool_set_nonblock(int fd);
597
688
extern void pool_unset_nonblock(int fd);
598
689
extern void cancel_request(CancelPacket *sp);
 
690
extern void check_stop_request(void);
 
691
 
 
692
/* pool_process_query.c */
 
693
extern void reset_variables(void);
 
694
extern void reset_connection(void);
 
695
extern void per_node_statement_log(POOL_CONNECTION_POOL *backend, int node_id, char *query);
 
696
extern void per_node_error_log(POOL_CONNECTION_POOL *backend, int node_id, char *query, char *prefix, bool unread);
 
697
extern int pool_extract_error_message(bool read_kind, POOL_CONNECTION *backend, int major, bool unread, char **message);
 
698
extern POOL_STATUS do_command(POOL_CONNECTION *frontend, POOL_CONNECTION *backend,
 
699
                                           char *query, int protoMajor, int pid, int key, int no_ready_for_query);
 
700
extern POOL_STATUS do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major);
 
701
extern void free_select_result(POOL_SELECT_RESULT *result);
 
702
 
 
703
/* pool_relcache.c */
 
704
extern POOL_RELCACHE *pool_create_relcache(int cachesize, char *sql,
 
705
                                                                        func_ptr register_func, func_ptr unregister_func,
 
706
                                                                        bool issessionlocal);
 
707
extern void pool_discard_relcache(POOL_RELCACHE *relcache);
 
708
extern void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backend, char *table);
 
709
extern void *int_register_func(POOL_SELECT_RESULT *res);
 
710
extern void *int_unregister_func(void *data);
 
711
 
 
712
/* pool_lobj.c */
 
713
extern char *pool_rewrite_lo_creat(char kind, char *packet, int packet_len, POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, int* len);
599
714
 
600
715
#endif /* POOL_H */