2017-05-29 15:33:44 +00:00
|
|
|
|
|
|
|
/*
|
2018-03-12 14:03:15 +00:00
|
|
|
* Odyssey.
|
2017-05-29 15:33:44 +00:00
|
|
|
*
|
2017-07-05 12:42:49 +00:00
|
|
|
* Advanced PostgreSQL connection pooler.
|
2017-05-29 15:33:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2017-05-31 15:47:15 +00:00
|
|
|
#include <inttypes.h>
|
2017-05-29 15:33:44 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <machinarium.h>
|
2017-06-07 11:50:58 +00:00
|
|
|
#include <shapito.h>
|
2017-05-29 15:33:44 +00:00
|
|
|
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/macro.h"
|
|
|
|
#include "sources/version.h"
|
2017-08-08 13:50:50 +00:00
|
|
|
#include "sources/atomic.h"
|
2017-11-27 12:54:16 +00:00
|
|
|
#include "sources/util.h"
|
|
|
|
#include "sources/error.h"
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/list.h"
|
|
|
|
#include "sources/pid.h"
|
|
|
|
#include "sources/id.h"
|
2017-07-26 14:05:29 +00:00
|
|
|
#include "sources/logger.h"
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/daemon.h"
|
2018-03-06 15:23:52 +00:00
|
|
|
#include "sources/config.h"
|
|
|
|
#include "sources/config_mgr.h"
|
2018-03-05 14:24:30 +00:00
|
|
|
#include "sources/config_reader.h"
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/msg.h"
|
|
|
|
#include "sources/system.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/io.h"
|
2017-09-15 12:58:29 +00:00
|
|
|
#include "sources/instance.h"
|
2018-02-22 13:43:52 +00:00
|
|
|
#include "sources/router_cancel.h"
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/router.h"
|
|
|
|
#include "sources/pooler.h"
|
2018-03-02 10:00:52 +00:00
|
|
|
#include "sources/worker.h"
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/frontend.h"
|
|
|
|
#include "sources/backend.h"
|
|
|
|
#include "sources/auth.h"
|
|
|
|
#include "sources/tls.h"
|
|
|
|
#include "sources/cancel.h"
|
2017-05-29 15:33:44 +00:00
|
|
|
|
2017-06-16 12:28:37 +00:00
|
|
|
int od_cancel(od_system_t *system,
|
2018-02-13 13:33:40 +00:00
|
|
|
shapito_stream_t *stream,
|
2018-03-06 15:23:52 +00:00
|
|
|
od_configstorage_t *server_config,
|
2017-07-06 13:36:14 +00:00
|
|
|
shapito_key_t *key,
|
2017-06-20 15:39:52 +00:00
|
|
|
od_id_t *server_id)
|
2017-05-29 15:33:44 +00:00
|
|
|
{
|
2017-06-16 12:28:37 +00:00
|
|
|
od_instance_t *instance = system->instance;
|
2017-09-21 13:44:19 +00:00
|
|
|
od_log(&instance->logger, "cancel", NULL, NULL,
|
|
|
|
"cancel for %s%.*s",
|
2017-07-26 14:35:39 +00:00
|
|
|
server_id->id_prefix,
|
2017-07-26 14:05:29 +00:00
|
|
|
sizeof(server_id->id), server_id->id);
|
2017-06-16 12:28:37 +00:00
|
|
|
od_server_t server;
|
|
|
|
od_server_init(&server);
|
|
|
|
server.system = system;
|
2018-03-06 15:23:52 +00:00
|
|
|
od_backend_connect_cancel(&server, stream, server_config, key);
|
2018-02-15 13:06:46 +00:00
|
|
|
od_backend_close_connection(&server);
|
2017-06-02 13:49:20 +00:00
|
|
|
od_backend_close(&server);
|
2017-05-29 15:33:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-30 11:34:08 +00:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
od_cancel_cmp(od_server_t *server, void *arg)
|
|
|
|
{
|
2017-07-06 13:36:14 +00:00
|
|
|
shapito_key_t *key = arg;
|
|
|
|
return shapito_key_cmp(&server->key_client, key);
|
2017-05-30 11:34:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 13:43:52 +00:00
|
|
|
int od_cancel_find(od_routepool_t *route_pool, shapito_key_t *key,
|
|
|
|
od_routercancel_t *cancel)
|
2017-05-30 11:34:08 +00:00
|
|
|
{
|
|
|
|
/* match server by client key (forge) */
|
|
|
|
od_server_t *server;
|
2017-08-17 15:38:28 +00:00
|
|
|
server = od_routepool_server_foreach(route_pool, OD_SACTIVE,
|
|
|
|
od_cancel_cmp,
|
|
|
|
key);
|
2017-05-30 11:34:08 +00:00
|
|
|
if (server == NULL)
|
|
|
|
return -1;
|
|
|
|
od_route_t *route = server->route;
|
2018-02-22 13:43:52 +00:00
|
|
|
cancel->id = server->id;
|
2018-03-06 15:23:52 +00:00
|
|
|
cancel->config = od_configstorage_copy(route->config->storage);
|
|
|
|
if (cancel->config == NULL)
|
2018-02-22 13:43:52 +00:00
|
|
|
return -1;
|
|
|
|
cancel->key = server->key;
|
|
|
|
return 0;
|
2017-05-30 11:34:08 +00:00
|
|
|
}
|