Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eleminate server IO leak on Cancel request #527

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions sources/cancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ int od_cancel(od_global_t *global, od_rule_storage_t *storage, kiwi_key_t *key,
od_instance_t *instance = global->instance;
od_log(&instance->logger, "cancel", NULL, NULL, "cancel for %s%.*s",
server_id->id_prefix, sizeof(server_id->id), server_id->id);
od_server_t server;
od_server_init(&server, 0);
server.global = global;
od_backend_connect_cancel(&server, storage, key);
od_backend_close_connection(&server);
od_backend_close(&server);
od_server_t *server = od_server_allocate(0);
server->global = global;
od_backend_connect_cancel(server, storage, key);
od_backend_close_connection(server);
od_backend_close(server);
return 0;
}
14 changes: 4 additions & 10 deletions sources/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ static inline bool od_should_drop_connection(od_client_t *client,
// general logic is: if client do nothing long enough we can assume this is just a stale connection
// but we need to ensure this connection was initialized etc
if (od_unlikely(
server != NULL && server->is_allocated &&
!server->is_transaction &&
server != NULL && !server->is_transaction &&
/* case when we are out of any transactional block ut perform some stmt */
od_server_synchronized(server))) {
if (od_eject_conn_with_timeout(
Expand All @@ -555,9 +554,8 @@ static inline bool od_should_drop_connection(od_client_t *client,
}
if (od_unlikely(
client->rule->pool->idle_in_transaction_timeout)) {
// the save as above but we are going to drop client inside transaction block
if (server != NULL && server->is_allocated &&
server->is_transaction &&
// the same as above but we are going to drop client inside transaction block
if (server != NULL && server->is_transaction &&
/*server is sync - that means client executed some stmts and got get result, and now just... do nothing */
od_server_synchronized(server)) {
if (od_eject_conn_with_timeout(
Expand Down Expand Up @@ -595,9 +593,6 @@ static inline bool od_should_drop_connection(od_client_t *client,
return od_eject_conn_with_rate(client, server,
instance);
}
if (!server->is_allocated) {
return true;
}
if (server->state ==
OD_SERVER_ACTIVE /* we can drop client that are just connected and do not perform any queries */
&& !od_server_synchronized(server)) {
Expand Down Expand Up @@ -1711,8 +1706,7 @@ static od_frontend_status_t od_frontend_remote(od_client_t *client)
}

#if OD_DEVEL_LVL != OD_RELEASE_MODE
if (server != NULL && server->is_allocated &&
server->is_transaction &&
if (server != NULL && server->is_transaction &&
od_server_synchronized(server)) {
od_dbg_printf_on_dvl_lvl(
1,
Expand Down
15 changes: 5 additions & 10 deletions sources/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct od_server {
machine_tls_t *tls;
od_io_t io;
od_relay_t relay;
int is_allocated;
int is_transaction;
/* Copy stmt state */
uint64_t done_fail_response_received;
Expand Down Expand Up @@ -73,7 +72,6 @@ static inline void od_server_init(od_server_t *server, int reserve_prep_stmts)
server->global = NULL;
server->tls = NULL;
server->idle_time = 0;
server->is_allocated = 0;
server->is_transaction = 0;
server->done_fail_response_received = 0;
server->in_out_response_received = 0;
Expand Down Expand Up @@ -114,20 +112,17 @@ static inline od_server_t *od_server_allocate(int reserve_prep_stmts)
if (server == NULL)
return NULL;
od_server_init(server, reserve_prep_stmts);
server->is_allocated = 1;
return server;
}

static inline void od_server_free(od_server_t *server)
{
if (server->is_allocated) {
od_relay_free(&server->relay);
od_io_free(&server->io);
if (server->prep_stmts) {
od_hashmap_free(server->prep_stmts);
}
free(server);
od_relay_free(&server->relay);
od_io_free(&server->io);
if (server->prep_stmts) {
od_hashmap_free(server->prep_stmts);
}
free(server);
}

static inline void od_server_sync_request(od_server_t *server, uint64_t count)
Expand Down
Loading