From 7a8e8e37ed254a29f5085855e6d03fe4ff7573e9 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 17 Sep 2014 14:44:20 +0200 Subject: [PATCH] command=stop functional and works much better PAZ-967 --- src/client.c | 25 ++++++++++++++++++++++--- src/client.h | 1 + src/connection.c | 5 +++++ src/connection.h | 1 + src/http_command.c | 12 ++++++++++++ src/session.c | 27 +++++++++++++++++++++++++++ src/session.h | 1 + 7 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/client.c b/src/client.c index 9af8c2b..60553fd 100644 --- a/src/client.c +++ b/src/client.c @@ -927,6 +927,8 @@ int client_start_search(struct client *cl) int present_chunk = 20; // Default chunk size int rc_prep_connection; + cl->diagnostic = 0; + cl->record_failures = cl->ingest_failures = cl->filtered = 0; yaz_gettimeofday(&tval); tval.tv_sec += 5; @@ -961,9 +963,6 @@ int client_start_search(struct client *cl) session_log(se, YLOG_LOG, "%s: new search", client_get_id(cl)); - cl->diagnostic = 0; - cl->record_failures = cl->ingest_failures = cl->filtered = 0; - client_destroy_xdoc(cl); client_init_xdoc(cl); @@ -1165,6 +1164,26 @@ void client_disconnect(struct client *cl) client_set_connection(cl, 0); } +void client_stop(struct client *cl) +{ + client_lock(cl); + if (cl->state == Client_Working || cl->state == Client_Connecting) + { + yaz_log(YLOG_LOG, "client_stop: %s release", client_get_id(cl)); + if (cl->connection) + { + connection_release2(cl->connection); + assert(cl->ref_count > 1); + cl->ref_count--; + cl->connection = 0; + } + cl->state = Client_Disconnected; + } + else + yaz_log(YLOG_LOG, "client_stop: %s ignore", client_get_id(cl)); + client_unlock(cl); +} + // Initialize CCL map for a target static CCL_bibset prepare_cclmap(struct client *cl, CCL_bibset base_bibset) { diff --git a/src/client.h b/src/client.h index 5d8bace..6092dfa 100644 --- a/src/client.h +++ b/src/client.h @@ -101,6 +101,7 @@ void client_incref(struct client *c); void client_got_records(struct client *c); void client_lock(struct client *c); void client_unlock(struct client *c); +void client_stop(struct client *c); int client_has_facet(struct client *cl, const char *name); void client_check_preferred_watch(struct client *cl); diff --git a/src/connection.c b/src/connection.c index df01303..c52fcf3 100644 --- a/src/connection.c +++ b/src/connection.c @@ -360,6 +360,11 @@ static void connection_release(struct connection *co) co->client = 0; } +void connection_release2(struct connection *co) +{ + co->client = 0; +} + void connect_resolver_host(struct host *host, iochan_man_t iochan_man) { struct connection *con; diff --git a/src/connection.h b/src/connection.h index e92019e..1b7b24c 100644 --- a/src/connection.h +++ b/src/connection.h @@ -34,6 +34,7 @@ void connect_resolver_host(struct host *host, iochan_man_t iochan); ZOOM_connection connection_get_link(struct connection *co); void connection_continue(struct connection *co); void connect_resolver_host(struct host *host, iochan_man_t iochan_man); +void connection_release2(struct connection *co); #endif diff --git a/src/http_command.c b/src/http_command.c index 309a617..7c23404 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1457,6 +1457,17 @@ static void cmd_stat(struct http_channel *c) release_session(c, s); } +static void cmd_stop(struct http_channel *c) +{ + struct http_session *s = locate_session(c); + if (!s) + return; + response_open_ok(c, "stop"); + session_stop(s->psession); + response_close(c, "stop"); + release_session(c, s); +} + static void cmd_info(struct http_channel *c) { char yaz_version_str[20]; @@ -1516,6 +1527,7 @@ struct { { "ping", cmd_ping }, { "record", cmd_record }, { "info", cmd_info }, + { "stop", cmd_stop }, {0,0} }; diff --git a/src/session.c b/src/session.c index fb895de..ff0e038 100644 --- a/src/session.c +++ b/src/session.c @@ -726,6 +726,33 @@ void session_sort(struct session *se, struct reclist_sortparms *sp, } } +void session_stop(struct session *se) +{ + struct client_list *l; + session_enter(se, "session_stop1"); + if (se->clients_starting) + { + session_leave(se, "session_stop1"); + return; + } + se->clients_starting = 1; + session_leave(se, "session_stop1"); + + session_alert_watch(se, SESSION_WATCH_SHOW); + session_alert_watch(se, SESSION_WATCH_BYTARGET); + session_alert_watch(se, SESSION_WATCH_TERMLIST); + session_alert_watch(se, SESSION_WATCH_SHOW_PREF); + + for (l = se->clients_active; l; l = l->next) + { + struct client *cl = l->client; + client_stop(cl); + } + session_enter(se, "session_stop2"); + se->clients_starting = 0; + session_leave(se, "session_stop2"); +} + enum pazpar2_error_code session_search(struct session *se, const char *query, const char *startrecs, diff --git a/src/session.h b/src/session.h index 76786f4..ecc5549 100644 --- a/src/session.h +++ b/src/session.h @@ -186,6 +186,7 @@ int session_is_preferred_clients_ready(struct session *s); void session_apply_setting(struct session *se, const char *dbname, const char *setting, const char *value); const char *session_setting_oneval(struct session_database *db, int offset); +void session_stop(struct session *se); int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem); int ingest_xml_record(struct client *cl, xmlDoc *xdoc, -- 1.7.10.4