mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-01 19:13:36 +00:00
[MAJOR] Add new files src/peer.c, include/proto/peers.h and include/types/peers.h for sync stick table management
Add cmdline option -L to configure local peer name
This commit is contained in:
parent
85e77c7f0d
commit
2b920a1af1
3
Makefile
3
Makefile
@ -480,7 +480,8 @@ endif
|
|||||||
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
|
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
|
||||||
src/uri_auth.o src/standard.o src/buffers.o src/log.o src/task.o \
|
src/uri_auth.o src/standard.o src/buffers.o src/log.o src/task.o \
|
||||||
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
||||||
src/checks.o src/queue.o src/frontend.o src/proxy.o src/stick_table.o src/proto_uxst.o \
|
src/checks.o src/queue.o src/frontend.o src/proxy.o src/peers.o \
|
||||||
|
src/stick_table.o src/proto_uxst.o \
|
||||||
src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
|
src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
|
||||||
src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \
|
src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \
|
||||||
src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
|
src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
|
||||||
|
@ -106,7 +106,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
|
|||||||
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
||||||
src/checks.o src/queue.o src/frontend.o src/proxy.o src/proto_uxst.o \
|
src/checks.o src/queue.o src/frontend.o src/proxy.o src/proto_uxst.o \
|
||||||
src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
|
src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
|
||||||
src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
|
src/peers.o src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
|
||||||
src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \
|
src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \
|
||||||
src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \
|
src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \
|
||||||
src/ev_poll.o src/ev_kqueue.o \
|
src/ev_poll.o src/ev_kqueue.o \
|
||||||
|
@ -103,7 +103,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
|
|||||||
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
||||||
src/checks.o src/queue.o src/frontend.o src/proxy.o src/proto_uxst.o \
|
src/checks.o src/queue.o src/frontend.o src/proxy.o src/proto_uxst.o \
|
||||||
src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
|
src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
|
||||||
src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
|
src/peers.o src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
|
||||||
src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \
|
src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \
|
||||||
src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \
|
src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \
|
||||||
src/ev_poll.o \
|
src/ev_poll.o \
|
||||||
|
37
include/proto/peers.h
Normal file
37
include/proto/peers.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* include/proto/peers.h
|
||||||
|
* This file defines function prototypes for peers management.
|
||||||
|
*
|
||||||
|
* Copyright 2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, version 2.1
|
||||||
|
* exclusively.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PROTO_PEERS_H
|
||||||
|
#define _PROTO_PEERS_H
|
||||||
|
|
||||||
|
#include <common/config.h>
|
||||||
|
#include <common/ticks.h>
|
||||||
|
#include <common/time.h>
|
||||||
|
#include <types/session.h>
|
||||||
|
#include <types/peers.h>
|
||||||
|
|
||||||
|
struct session * peer_session_create(struct peer *);
|
||||||
|
struct session * peers_register_table(struct peers *, struct stktable *table);
|
||||||
|
|
||||||
|
int peer_accept(struct session *);
|
||||||
|
|
||||||
|
#endif /* _PROTO_PEERS_H */
|
||||||
|
|
@ -121,6 +121,7 @@ extern const int one;
|
|||||||
extern const struct linger nolinger;
|
extern const struct linger nolinger;
|
||||||
extern int stopping; /* non zero means stopping in progress */
|
extern int stopping; /* non zero means stopping in progress */
|
||||||
extern char hostname[MAX_HOSTNAME_LEN];
|
extern char hostname[MAX_HOSTNAME_LEN];
|
||||||
|
extern char localpeer[MAX_HOSTNAME_LEN];
|
||||||
|
|
||||||
#endif /* _TYPES_GLOBAL_H */
|
#endif /* _TYPES_GLOBAL_H */
|
||||||
|
|
||||||
|
99
include/types/peers.h
Normal file
99
include/types/peers.h
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* include/types/peers.h
|
||||||
|
* This file defines everything related to peers.
|
||||||
|
*
|
||||||
|
* Copyright 2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, version 2.1
|
||||||
|
* exclusively.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TYPES_PEERS_H
|
||||||
|
#define _TYPES_PEERS_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <common/appsession.h>
|
||||||
|
#include <common/config.h>
|
||||||
|
#include <common/mini-clist.h>
|
||||||
|
#include <common/regex.h>
|
||||||
|
#include <common/sessionhash.h>
|
||||||
|
#include <common/tools.h>
|
||||||
|
#include <eb32tree.h>
|
||||||
|
|
||||||
|
struct peer_session {
|
||||||
|
struct shared_table *table; /* shared table */
|
||||||
|
struct peer *peer; /* current peer */
|
||||||
|
struct session *session; /* current transport session */
|
||||||
|
unsigned int flags; /* peer session flags */
|
||||||
|
unsigned int statuscode; /* current/last session status code */
|
||||||
|
unsigned int update; /* current peer acked update */
|
||||||
|
unsigned int pushack; /* last commited update to ack */
|
||||||
|
unsigned int lastack; /* last acked update */
|
||||||
|
unsigned int lastpush; /* last pushed update */
|
||||||
|
unsigned int confirm; /* confirm message counter */
|
||||||
|
unsigned int pushed; /* equal to last pushed data or to table local update in case of total push
|
||||||
|
* or to teaching_origin if teaching is ended */
|
||||||
|
unsigned int reconnect; /* next connect timer */
|
||||||
|
unsigned int teaching_origin; /* resync teaching origine update */
|
||||||
|
struct peer_session *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct shared_table {
|
||||||
|
struct stktable *table; /* stick table to sync */
|
||||||
|
struct task *sync_task; /* main sync task */
|
||||||
|
struct peer_session *local_session; /* local peer session */
|
||||||
|
struct peer_session *sessions; /* peer sessions list */
|
||||||
|
unsigned int flags; /* current table resync state */
|
||||||
|
unsigned int resync_timeout; /* resync timeout timer */
|
||||||
|
struct shared_table *next; /* next shared table in list */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct peer {
|
||||||
|
int local; /* proxy state */
|
||||||
|
char *id;
|
||||||
|
struct peers *peers;
|
||||||
|
struct {
|
||||||
|
const char *file; /* file where the section appears */
|
||||||
|
int line; /* line where the section appears */
|
||||||
|
} conf; /* config information */
|
||||||
|
time_t last_change;
|
||||||
|
struct sockaddr_in addr; /* peer address */
|
||||||
|
struct peer *next; /* next peer in the list */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct peers {
|
||||||
|
int state; /* proxy state */
|
||||||
|
char *id; /* peer section name */
|
||||||
|
struct peer *remote; /* remote peers list */
|
||||||
|
struct proxy *peers_fe; /* peer frontend */
|
||||||
|
struct {
|
||||||
|
const char *file; /* file where the section appears */
|
||||||
|
int line; /* line where the section appears */
|
||||||
|
} conf; /* config information */
|
||||||
|
struct shared_table *tables; /* registered shared tables */
|
||||||
|
time_t last_change;
|
||||||
|
struct peers *next; /* next peer section */
|
||||||
|
int count; /* total of peers */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
extern struct peers *peers;
|
||||||
|
|
||||||
|
#endif /* _TYPES_PEERS_H */
|
||||||
|
|
@ -156,6 +156,7 @@ const int one = 1;
|
|||||||
const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
|
const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
|
||||||
|
|
||||||
char hostname[MAX_HOSTNAME_LEN];
|
char hostname[MAX_HOSTNAME_LEN];
|
||||||
|
char localpeer[MAX_HOSTNAME_LEN];
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
@ -224,6 +225,7 @@ void usage(char *name)
|
|||||||
" -n sets the maximum total # of connections (%d)\n"
|
" -n sets the maximum total # of connections (%d)\n"
|
||||||
" -m limits the usable amount of memory (in MB)\n"
|
" -m limits the usable amount of memory (in MB)\n"
|
||||||
" -N sets the default, per-proxy maximum # of connections (%d)\n"
|
" -N sets the default, per-proxy maximum # of connections (%d)\n"
|
||||||
|
" -L set local peer name (default to hostname)\n"
|
||||||
" -p writes pids of all children to this file\n"
|
" -p writes pids of all children to this file\n"
|
||||||
#if defined(ENABLE_EPOLL)
|
#if defined(ENABLE_EPOLL)
|
||||||
" -de disables epoll() usage even when available\n"
|
" -de disables epoll() usage even when available\n"
|
||||||
@ -351,6 +353,15 @@ void init(int argc, char **argv)
|
|||||||
int err_code = 0;
|
int err_code = 0;
|
||||||
struct wordlist *wl;
|
struct wordlist *wl;
|
||||||
|
|
||||||
|
/* NB: POSIX does not make it mandatory for gethostname() to NULL-terminate
|
||||||
|
* the string in case of truncation, and at least FreeBSD appears not to do
|
||||||
|
* it.
|
||||||
|
*/
|
||||||
|
memset(hostname, 0, sizeof(hostname));
|
||||||
|
gethostname(hostname, sizeof(hostname) - 1);
|
||||||
|
memset(localpeer, 0, sizeof(localpeer));
|
||||||
|
memcpy(localpeer, hostname, (sizeof(hostname) > sizeof(localpeer) ? sizeof(localpeer) : sizeof(hostname)) - 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the previously static variables.
|
* Initialize the previously static variables.
|
||||||
*/
|
*/
|
||||||
@ -469,6 +480,7 @@ void init(int argc, char **argv)
|
|||||||
case 'n' : cfg_maxconn = atol(*argv); break;
|
case 'n' : cfg_maxconn = atol(*argv); break;
|
||||||
case 'm' : global.rlimit_memmax = atol(*argv); break;
|
case 'm' : global.rlimit_memmax = atol(*argv); break;
|
||||||
case 'N' : cfg_maxpconn = atol(*argv); break;
|
case 'N' : cfg_maxpconn = atol(*argv); break;
|
||||||
|
case 'L' : strncpy(localpeer, *argv, sizeof(localpeer) - 1); break;
|
||||||
case 'f' :
|
case 'f' :
|
||||||
wl = (struct wordlist *)calloc(1, sizeof(*wl));
|
wl = (struct wordlist *)calloc(1, sizeof(*wl));
|
||||||
if (!wl) {
|
if (!wl) {
|
||||||
@ -495,13 +507,6 @@ void init(int argc, char **argv)
|
|||||||
if (LIST_ISEMPTY(&cfg_cfgfiles))
|
if (LIST_ISEMPTY(&cfg_cfgfiles))
|
||||||
usage(old_argv);
|
usage(old_argv);
|
||||||
|
|
||||||
/* NB: POSIX does not make it mandatory for gethostname() to NULL-terminate
|
|
||||||
* the string in case of truncation, and at least FreeBSD appears not to do
|
|
||||||
* it.
|
|
||||||
*/
|
|
||||||
memset(hostname, 0, sizeof(hostname));
|
|
||||||
gethostname(hostname, sizeof(hostname) - 1);
|
|
||||||
|
|
||||||
have_appsession = 0;
|
have_appsession = 0;
|
||||||
global.maxsock = 10; /* reserve 10 fds ; will be incremented by socket eaters */
|
global.maxsock = 10; /* reserve 10 fds ; will be incremented by socket eaters */
|
||||||
|
|
||||||
|
1482
src/peers.c
Normal file
1482
src/peers.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user