Skip to content

Commit

Permalink
DO not ignore erros if server reset failed. (#583)
Browse files Browse the repository at this point in the history
* DO not ignore erros if server reset failed.

* fix comments
  • Loading branch information
reshke authored Mar 4, 2024
1 parent ed8ca61 commit 2848982
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
20 changes: 13 additions & 7 deletions sources/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,13 @@ int od_backend_update_parameter(od_server_t *server, char *context, char *data,
}

int od_backend_ready_wait(od_server_t *server, char *context, int count,
uint32_t time_ms)
uint32_t time_ms, uint32_t ignore_errors)
{
od_instance_t *instance = server->global->instance;
int ready = 0;
int query_rc;
query_rc = 0;

for (;;) {
machine_msg_t *msg;
msg = od_read(&server->io, time_ms);
Expand Down Expand Up @@ -730,17 +733,20 @@ int od_backend_ready_wait(od_server_t *server, char *context, int count,
od_backend_error(server, context, machine_msg_data(msg),
machine_msg_size(msg));
machine_msg_free(msg);
continue;
if (!ignore_errors) {
query_rc = -1;
}
} else if (type == KIWI_BE_READY_FOR_QUERY) {
od_backend_ready(server, machine_msg_data(msg),
machine_msg_size(msg));
ready++;
if (ready == count) {
machine_msg_free(msg);
return 0;
return query_rc;
}
} else {
machine_msg_free(msg);
}
machine_msg_free(msg);
}
/* never reached */
}
Expand Down Expand Up @@ -776,13 +782,13 @@ od_retcode_t od_backend_query_send(od_server_t *server, char *context,

od_retcode_t od_backend_query(od_server_t *server, char *context, char *query,
char *param, int len, uint32_t timeout,
uint32_t count)
uint32_t count, uint32_t ignore_errors)
{
if (od_backend_query_send(server, context, query, param, len) ==
NOT_OK_RESPONSE) {
return NOT_OK_RESPONSE;
}
od_retcode_t rc =
od_backend_ready_wait(server, context, count, timeout);
od_retcode_t rc = od_backend_ready_wait(server, context, count, timeout,
ignore_errors);
return rc;
}
4 changes: 2 additions & 2 deletions sources/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ void od_backend_error(od_server_t *, char *, char *, uint32_t);

int od_backend_update_parameter(od_server_t *, char *, char *, uint32_t, int);
int od_backend_ready(od_server_t *, char *, uint32_t);
int od_backend_ready_wait(od_server_t *, char *, int, uint32_t);
int od_backend_ready_wait(od_server_t *, char *, int, uint32_t, uint32_t);

od_retcode_t od_backend_query_send(od_server_t *server, char *context,
char *query, char *param, int len);
od_retcode_t od_backend_query(od_server_t *, char *, char *, char *, int,
uint32_t, uint32_t);
uint32_t, uint32_t, uint32_t);

#endif /* ODYSSEY_BACKEND_H */
44 changes: 24 additions & 20 deletions sources/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ int od_reset(od_server_t *server)
wait_timeout, wait_try);
wait_try++;
rc = od_backend_ready_wait(server, "reset", 1,
wait_timeout);
if (rc == -1)
wait_timeout,
1 /*ignore server errors*/);
if (rc == NOT_OK_RESPONSE)
break;
}
if (rc == -1) {
if (rc == NOT_OK_RESPONSE) {
if (!machine_timedout())
goto error;

Expand All @@ -104,7 +105,7 @@ int od_reset(od_server_t *server)
wait_try_cancel++;
rc = od_cancel(server->global, route->rule->storage,
&server->key, &server->id);
if (rc == -1)
if (rc == NOT_OK_RESPONSE)
goto error;
continue;
}
Expand All @@ -119,11 +120,11 @@ int od_reset(od_server_t *server)
if (route->rule->pool->rollback) {
if (server->is_transaction) {
char query_rlb[] = "ROLLBACK";
rc = od_backend_query(server, "reset-rollback",
query_rlb, NULL,
sizeof(query_rlb), wait_timeout,
1);
if (rc == -1)
rc = od_backend_query(
server, "reset-rollback", query_rlb, NULL,
sizeof(query_rlb), wait_timeout, 1,
0 /*do not ignore server error messages*/);
if (rc == NOT_OK_RESPONSE)
goto error;
assert(!server->is_transaction);
}
Expand All @@ -132,9 +133,10 @@ int od_reset(od_server_t *server)
/* send DISCARD ALL */
if (route->rule->pool->discard) {
char query_discard[] = "DISCARD ALL";
rc = od_backend_query(server, "reset-discard", query_discard,
NULL, sizeof(query_discard), wait_timeout,
1);
rc = od_backend_query(
server, "reset-discard", query_discard, NULL,
sizeof(query_discard), wait_timeout, 1,
0 /*do not ignore server error messages*/);
if (rc == NOT_OK_RESPONSE)
goto error;
}
Expand All @@ -144,18 +146,20 @@ int od_reset(od_server_t *server)
route->rule->pool->discard_query == NULL) {
char query_discard[] =
"SET SESSION AUTHORIZATION DEFAULT;RESET ALL;CLOSE ALL;UNLISTEN *;SELECT pg_advisory_unlock_all();DISCARD PLANS;DISCARD SEQUENCES;DISCARD TEMP;";
rc = od_backend_query(server, "reset-discard-smart",
query_discard, NULL,
sizeof(query_discard), wait_timeout, 1);
rc = od_backend_query(
server, "reset-discard-smart", query_discard, NULL,
sizeof(query_discard), wait_timeout, 1,
0 /*do not ignore server error messages*/);
if (rc == NOT_OK_RESPONSE)
goto error;
}
if (route->rule->pool->discard_query != NULL) {
rc = od_backend_query(server, "reset-discard-smart-string",
route->rule->pool->discard_query, NULL,
strlen(route->rule->pool->discard_query) +
1,
wait_timeout, 1);
rc = od_backend_query(
server, "reset-discard-smart-string",
route->rule->pool->discard_query, NULL,
strlen(route->rule->pool->discard_query) + 1,
wait_timeout, 1,
0 /*do not ignore server error messages*/);
if (rc == NOT_OK_RESPONSE)
goto error;
}
Expand Down

0 comments on commit 2848982

Please sign in to comment.