2017-06-01 12:45:49 +00:00
|
|
|
|
|
|
|
/*
|
2017-07-05 12:42:49 +00:00
|
|
|
* Odissey.
|
2017-06-01 12:45:49 +00:00
|
|
|
*
|
2017-07-05 12:42:49 +00:00
|
|
|
* Advanced PostgreSQL connection pooler.
|
2017-06-01 12:45:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/macro.h"
|
|
|
|
#include "sources/version.h"
|
|
|
|
#include "sources/list.h"
|
|
|
|
#include "sources/pid.h"
|
|
|
|
#include "sources/id.h"
|
|
|
|
#include "sources/syslog.h"
|
|
|
|
#include "sources/log.h"
|
|
|
|
#include "sources/daemon.h"
|
|
|
|
#include "sources/scheme.h"
|
2017-07-14 13:40:31 +00:00
|
|
|
#include "sources/scheme_mgr.h"
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/config.h"
|
|
|
|
#include "sources/msg.h"
|
|
|
|
#include "sources/system.h"
|
|
|
|
#include "sources/instance.h"
|
|
|
|
#include "sources/server.h"
|
|
|
|
#include "sources/server_pool.h"
|
|
|
|
#include "sources/client.h"
|
|
|
|
#include "sources/client_pool.h"
|
|
|
|
#include "sources/route_id.h"
|
|
|
|
#include "sources/route.h"
|
|
|
|
#include "sources/route_pool.h"
|
|
|
|
#include "sources/router.h"
|
|
|
|
#include "sources/pooler.h"
|
|
|
|
#include "sources/relay.h"
|
|
|
|
#include "sources/relay_pool.h"
|
|
|
|
#include "sources/frontend.h"
|
2017-06-01 12:45:49 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|