2017-06-01 12:45:49 +00:00
|
|
|
|
|
|
|
/*
|
2017-06-07 11:50:58 +00:00
|
|
|
* ODISSEY.
|
2017-06-01 12:45:49 +00:00
|
|
|
*
|
|
|
|
* PostgreSQL connection pooler and request router.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <machinarium.h>
|
2017-06-07 11:50:58 +00:00
|
|
|
#include <shapito.h>
|
2017-06-01 12:45:49 +00:00
|
|
|
|
|
|
|
#include "od_macro.h"
|
|
|
|
#include "od_version.h"
|
|
|
|
#include "od_list.h"
|
|
|
|
#include "od_pid.h"
|
2017-06-20 15:39:52 +00:00
|
|
|
#include "od_id.h"
|
2017-06-01 12:45:49 +00:00
|
|
|
#include "od_syslog.h"
|
|
|
|
#include "od_log.h"
|
|
|
|
#include "od_daemon.h"
|
|
|
|
#include "od_scheme.h"
|
|
|
|
#include "od_lex.h"
|
|
|
|
#include "od_config.h"
|
|
|
|
#include "od_msg.h"
|
|
|
|
#include "od_system.h"
|
|
|
|
#include "od_instance.h"
|
|
|
|
|
|
|
|
#include "od_server.h"
|
|
|
|
#include "od_server_pool.h"
|
|
|
|
#include "od_client.h"
|
|
|
|
#include "od_client_pool.h"
|
|
|
|
#include "od_route_id.h"
|
|
|
|
#include "od_route.h"
|
2017-06-05 13:45:28 +00:00
|
|
|
#include "od_route_pool.h"
|
2017-06-01 12:45:49 +00:00
|
|
|
|
2017-06-05 13:45:28 +00:00
|
|
|
#include "od_router.h"
|
2017-06-01 12:45:49 +00:00
|
|
|
#include "od_pooler.h"
|
|
|
|
#include "od_relay.h"
|
|
|
|
#include "od_relay_pool.h"
|
|
|
|
#include "od_frontend.h"
|
|
|
|
|
|
|
|
int od_relaypool_init(od_relaypool_t *pool, od_system_t *system, int count)
|
|
|
|
{
|
2017-06-19 10:30:56 +00:00
|
|
|
pool->round_robin = 0;
|
2017-06-01 12:45:49 +00:00
|
|
|
pool->count = count;
|
|
|
|
pool->pool = malloc(sizeof(od_relay_t) * count);
|
|
|
|
if (pool->pool == NULL)
|
|
|
|
return -1;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
od_relay_t *relay = &pool->pool[i];
|
|
|
|
od_relay_init(relay, system, i);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int od_relaypool_start(od_relaypool_t *pool)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < pool->count; i++) {
|
|
|
|
od_relay_t *relay = &pool->pool[i];
|
|
|
|
int rc;
|
|
|
|
rc = od_relay_start(relay);
|
|
|
|
if (rc == -1)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-19 10:30:56 +00:00
|
|
|
|
|
|
|
void od_relaypool_feed(od_relaypool_t *pool, machine_msg_t *msg)
|
|
|
|
{
|
|
|
|
int next = pool->round_robin;
|
|
|
|
if (pool->round_robin < pool->count) {
|
|
|
|
pool->round_robin++;
|
|
|
|
} else {
|
|
|
|
pool->round_robin = 0;
|
|
|
|
next = 0;
|
|
|
|
}
|
|
|
|
od_relay_t *relay;
|
|
|
|
relay = &pool->pool[next];
|
|
|
|
machine_queue_put(relay->task_queue, msg);
|
|
|
|
}
|