From: Adam Dickmeiss Date: Wed, 20 Dec 2006 22:19:35 +0000 (+0000) Subject: Reduce size of database struct. Pass temp NMEM memory to show. X-Git-Tag: before.append.child~88 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=b9a83dec2858e9aa4247b29b3f8f8cf42a1a786d;hp=1feb0a041e752e096256750c1ec0e8e00f1c30e5;p=pazpar2-moved-to-github.git Reduce size of database struct. Pass temp NMEM memory to show. --- diff --git a/src/command.c b/src/command.c index 5411b39..c400585 100644 --- a/src/command.c +++ b/src/command.c @@ -1,4 +1,4 @@ -/* $Id: command.c,v 1.1 2006-12-20 20:47:16 quinn Exp $ */ +/* $Id: command.c,v 1.2 2006-12-20 22:19:35 adam Exp $ */ #include #include @@ -90,11 +90,12 @@ static int cmd_show(struct command_session *s, char **argv, int argc) int num = 10; int merged, total; int i; + NMEM nmem_show = nmem_create(); if (argc == 2) num = atoi(argv[1]); - recs = show(s->psession, 0, &num, &merged, &total); + recs = show(s->psession, 0, &num, &merged, &total, nmem_show); for (i = 0; i < num; i++) { @@ -113,6 +114,7 @@ static int cmd_show(struct command_session *s, char **argv, int argc) } command_puts(s, "\n"); } + nmem_destroy(nmem_show); return 1; } diff --git a/src/http_command.c b/src/http_command.c index 6c99232..e453a9d 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $Id: http_command.c,v 1.1 2006-12-20 20:47:16 quinn Exp $ + * $Id: http_command.c,v 1.2 2006-12-20 22:19:35 adam Exp $ */ #include @@ -213,6 +213,7 @@ static void show_records(struct http_channel *c) struct http_response *rs = c->response; struct http_session *s = locate_session(rq, rs); struct record **rl; + NMEM nmem_show; char *start = http_argbyname(rq, "start"); char *num = http_argbyname(rq, "num"); int startn = 0; @@ -229,7 +230,8 @@ static void show_records(struct http_channel *c) if (num) numn = atoi(num); - rl = show(s->psession, startn, &numn, &total, &total_hits); + nmem_show = nmem_create(); + rl = show(s->psession, startn, &numn, &total, &total_hits, nmem_show); wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, "\nOK\n"); @@ -255,6 +257,7 @@ static void show_records(struct http_channel *c) wrbuf_puts(c->wrbuf, "\n"); rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf)); http_send_response(c); + nmem_destroy(nmem_show); } static void show_records_ready(void *data) diff --git a/src/pazpar2.c b/src/pazpar2.c index c95ce3a..8df9491 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.1 2006-12-20 20:47:16 quinn Exp $ */; +/* $Id: pazpar2.c,v 1.2 2006-12-20 22:19:35 adam Exp $ */; #include #include @@ -153,10 +153,10 @@ static void send_search(IOCHAN i) zquery->u.type_1 = ccl_rpn_query(global_parameters.odr_out, cn); ccl_rpn_delete(cn); - for (ndb = 0; *db->databases[ndb]; ndb++) + for (ndb = 0; db->databases[ndb]; ndb++) ; databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb); - for (ndb = 0; *db->databases[ndb]; ndb++) + for (ndb = 0; db->databases[ndb]; ndb++) databaselist[ndb] = db->databases[ndb]; a->u.presentRequest->preferredRecordSyntax = @@ -1038,8 +1038,10 @@ void load_simpletargets(const char *fn) strcpy(database->url, url); strcat(database->url, "/"); strcat(database->url, db); - strcpy(database->databases[0], db); - *database->databases[1] = '\0'; + + database->databases = xmalloc(2 * sizeof(char *)); + database->databases[0] = xstrdup(db); + database->databases[1] = 0; database->errors = 0; database->next = databases; databases = database; @@ -1257,9 +1259,22 @@ struct termlist_score **termlist(struct session *s, int *num) return termlist_highscore(s->termlist, num); } -struct record **show(struct session *s, int start, int *num, int *total, int *sumhits) +void report_nmem_stats(void) { - struct record **recs = nmem_malloc(s->nmem, *num * sizeof(struct record *)); + size_t in_use, is_free; + + nmem_get_memory_in_use(&in_use); + nmem_get_memory_free(&is_free); + + yaz_log(YLOG_LOG, "nmem stat: use=%ld free=%ld", + (long) in_use, (long) is_free); +} + +struct record **show(struct session *s, int start, int *num, int *total, + int *sumhits, NMEM nmem_show) +{ + struct record **recs = nmem_malloc(nmem_show, *num + * sizeof(struct record *)); int i; relevance_prepare_read(s->relevance, s->reclist); diff --git a/src/pazpar2.h b/src/pazpar2.h index 8de4b91..a15b68b 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -13,8 +13,6 @@ struct record; #include "relevance.h" #include "eventl.h" -#define MAX_DATABASES 512 - struct record { struct client *client; int target_offset; @@ -40,7 +38,7 @@ struct host { struct database { struct host *host; char *url; - char databases[MAX_DATABASES][128]; + char **databases; int errors; struct database *next; }; @@ -157,7 +155,7 @@ void destroy_session(struct session *s); int load_targets(struct session *s, const char *fn); void statistics(struct session *s, struct statistics *stat); char *search(struct session *s, char *query); -struct record **show(struct session *s, int start, int *num, int *total, int *sumhits); +struct record **show(struct session *s, int start, int *num, int *total, int *sumhits, NMEM nmem_show); struct termlist_score **termlist(struct session *s, int *num); void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);