From: Adam Dickmeiss Date: Mon, 4 Feb 2013 13:21:13 +0000 (+0100) Subject: Revise extended fetch algorithm X-Git-Tag: v1.6.26~11 X-Git-Url: http://git.indexdata.com/?p=pazpar2-moved-to-github.git;a=commitdiff_plain;h=87e9791ee9a652b3665d59ca5bf0e927e935e666 Revise extended fetch algorithm If the show records returned were the last in the sorted "window" of records per-client , an extended fetch will be attempted. Only if there are more records to be fetched (hit count depending) and pz:extendrecs is defined, another fetch will be initiated. --- diff --git a/src/client.c b/src/client.c index 4c40d9c..39140a7 100644 --- a/src/client.c +++ b/src/client.c @@ -115,6 +115,7 @@ struct client { char *addinfo; // diagnostic info for most resent error Odr_int hits; int record_offset; + int show_stat_no; int filtered; // When using local:, this will count the number of filtered records. int maxrecs; int startrecs; @@ -762,6 +763,14 @@ static const char *get_strategy_plus_sort(struct client *l, const char *field) return strategy_plus_sort; } +void client_update_show_stat(struct client *cl, int cmd) +{ + if (cmd == 0) + cl->show_stat_no = 0; + else if (cmd == 1) + cl->show_stat_no++; +} + int client_fetch_more(struct client *cl) { struct session_database *sdb = client_get_database(cl); @@ -769,6 +778,12 @@ int client_fetch_more(struct client *cl) int extend_recs = 0; int number; + yaz_log(YLOG_LOG, "cl=%s show_stat_no=%d got=%d", + client_get_id(cl), cl->show_stat_no, cl->record_offset); + if (cl->show_stat_no < cl->record_offset) + return 0; + yaz_log(YLOG_LOG, "cl=%s Trying to get more", client_get_id(cl)); + str = session_setting_oneval(sdb, PZ_EXTENDRECS); if (str && *str) extend_recs = atoi(str); @@ -793,6 +808,10 @@ int client_fetch_more(struct client *cl) connection_continue(co); return 1; } + else + { + yaz_log(YLOG_LOG, "cl=%s. OK no more in total set", client_get_id(cl)); + } return 0; } diff --git a/src/client.h b/src/client.h index eeccf0f..483136b 100644 --- a/src/client.h +++ b/src/client.h @@ -117,6 +117,7 @@ const char *client_get_facet_limit_local(struct client *cl, NMEM nmem, int *num, char ***values); int client_test_sort_order(struct client *cl, struct reclist_sortparms *sp); +void client_update_show_stat(struct client *cl, int cmd); #endif diff --git a/src/session.c b/src/session.c index 41bcb30..e81c221 100644 --- a/src/session.c +++ b/src/session.c @@ -1271,7 +1271,6 @@ struct record_cluster **show_range_start(struct session *se, struct record_cluster **recs = 0; struct reclist_sortparms *spp; struct client_list *l; - int num0 = *num; int i; #if USE_TIMING yaz_timing_t t = yaz_timing_create(); @@ -1299,13 +1298,24 @@ struct record_cluster **show_range_start(struct session *se, reclist_enter(se->reclist); *total = reclist_get_num_records(se->reclist); + for (l = se->clients_active; l; l = l->next) + client_update_show_stat(l->client, 0); + for (i = 0; i < start; i++) - if (!reclist_read_record(se->reclist)) + { + struct record_cluster *r = reclist_read_record(se->reclist); + if (!r) { *num = 0; break; } - + else + { + struct record *rec = r->records; + for (;rec; rec = rec->next) + client_update_show_stat(rec->client, 1); + } + } if (*num > 0) recs = nmem_malloc(se->nmem, *num * sizeof(struct record_cluster *)); @@ -1317,7 +1327,13 @@ struct record_cluster **show_range_start(struct session *se, *num = i; break; } - recs[i] = r; + else + { + struct record *rec = r->records; + for (;rec; rec = rec->next) + client_update_show_stat(rec->client, 1); + recs[i] = r; + } } reclist_leave(se->reclist); #if USE_TIMING @@ -1327,27 +1343,23 @@ struct record_cluster **show_range_start(struct session *se, yaz_timing_get_sys(t)); yaz_timing_destroy(&t); #endif - if (*num < num0) + + if (!session_fetch_more(se)) + session_log(se, YLOG_LOG, "can not fetch more"); + else { - session_log(se, YLOG_LOG, - "Subset %d < %d retrieved for show", *num, num0); - if (!session_fetch_more(se)) - session_log(se, YLOG_LOG, "can not fetch more"); + show_range_stop(se, recs); + session_log(se, YLOG_LOG, "fetching more in progress"); + if (session_set_watch(se, SESSION_WATCH_SHOW, + show_records_ready, chan, chan)) + { + session_log(se, YLOG_WARN, "Ignoring show block"); + session_enter(se, "show_range_start"); + } else { - show_range_stop(se, recs); - session_log(se, YLOG_LOG, "fetching more in progress"); - if (session_set_watch(se, SESSION_WATCH_SHOW, - show_records_ready, chan, chan)) - { - session_log(se, YLOG_WARN, "Ignoring show block"); - session_enter(se, "show_range_start"); - } - else - { - session_log(se, YLOG_LOG, "session watch OK"); - return 0; - } + session_log(se, YLOG_LOG, "session watch OK"); + return 0; } } return recs;