odissey: use serverstat_t for server synchronization

This commit is contained in:
Dmitry Simonenko 2017-08-10 15:07:29 +03:00
parent 1f8ddf885e
commit 625f9e8a0b
3 changed files with 18 additions and 12 deletions

View File

@ -79,7 +79,7 @@ int od_backend_terminate(od_server_t *server)
rc = od_write(server->io, stream);
if (rc == -1)
return -1;
server->count_request++;
od_atomic_u64_inc(&server->stats.count_request);
return 0;
}
@ -125,7 +125,7 @@ int od_backend_ready(od_server_t *server, char *data, int size)
* transaction block */
server->is_transaction = 1;
}
server->count_reply++;
od_atomic_u64_inc(&server->stats.count_reply);
return 0;
}
@ -190,7 +190,7 @@ od_backend_startup(od_server_t *server)
machine_error(server->io));
return -1;
}
server->count_request++;
od_atomic_u64_inc(&server->stats.count_request);
while (1) {
shapito_stream_reset(stream);
@ -384,7 +384,7 @@ od_backend_query(od_server_t *server, char *context, char *query, int len)
machine_error(server->io));
return -1;
}
server->count_request++;
od_atomic_u64_inc(&server->stats.count_request);
rc = od_backend_ready_wait(server, context, UINT32_MAX);
if (rc == -1)
return -1;

View File

@ -352,7 +352,7 @@ od_frontend_remote(od_client_t *client)
rc = od_write(server->io, stream);
if (rc == -1)
return OD_RS_ESERVER_WRITE;
server->count_request++;
od_atomic_u64_inc(&server->stats.count_request);
shapito_stream_reset(stream);
for (;;) {

View File

@ -7,7 +7,8 @@
* Advanced PostgreSQL connection pooler.
*/
typedef struct od_server od_server_t;
typedef struct od_serverstat od_serverstat_t;
typedef struct od_server od_server_t;
typedef enum
{
@ -17,6 +18,12 @@ typedef enum
OD_SEXPIRE
} od_serverstate_t;
struct od_serverstat
{
od_atomic_u64_t count_request;
od_atomic_u64_t count_reply;
};
struct od_server
{
od_serverstate_t state;
@ -27,8 +34,7 @@ struct od_server
int is_allocated;
int is_transaction;
int is_copy;
int64_t count_request;
int64_t count_reply;
od_serverstat_t stats;
int idle_time;
shapito_key_t key;
shapito_key_t key_client;
@ -39,8 +45,9 @@ struct od_server
};
static inline int
od_server_is_sync(od_server_t *server) {
return server->count_request == server->count_reply;
od_server_is_sync(od_server_t *server)
{
return server->stats.count_request == server->stats.count_reply;
}
static inline void
@ -55,8 +62,7 @@ od_server_init(od_server_t *server)
server->is_allocated = 0;
server->is_transaction = 0;
server->is_copy = 0;
server->count_request = 0;
server->count_reply = 0;
memset(&server->stats, 0, sizeof(server->stats));
shapito_key_init(&server->key);
shapito_key_init(&server->key_client);
shapito_stream_init(&server->stream);