From: Heikki Levanto Date: Tue, 31 Aug 2004 14:43:41 +0000 (+0000) Subject: Using proper nmems for more rsets around the system, X-Git-Tag: snippet.version.1~376 X-Git-Url: http://jsfdemo.indexdata.com/?a=commitdiff_plain;h=230fdc17aa503a23c842cd587f241cfe2fce1c0d;p=idzebra-moved-to-github.git Using proper nmems for more rsets around the system, especially scan and zrpn. Still a few nulls get passed to them (test/api/t4 fails if I assert on nmem). --- diff --git a/index/index.h b/index/index.h index 0132e3d..7359cfc 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.115 2004-08-30 12:32:24 heikki Exp $ +/* $Id: index.h,v 1.116 2004-08-31 14:43:41 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -73,6 +73,13 @@ struct it_key { }; #endif +struct key_info { + int keysize; + int (*key_compare) (const void *p1, const void *p2); + void (*key_logdump_txt) (int logmask, const void *p, const char *txt); + /* FIXME - decode and encode, and lots of other stuff */ +}; + enum dirsKind { dirs_dir, dirs_file }; struct dir_entry { @@ -372,7 +379,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no, const char *term, int length_term, const char *flags, - int preserve_position, int term_type); + int preserve_position, int term_type, NMEM rset_nmem); void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type, const char *db, int set, diff --git a/index/trunc.c b/index/trunc.c index 5cc49f0..a537f38 100644 --- a/index/trunc.c +++ b/index/trunc.c @@ -1,4 +1,4 @@ -/* $Id: trunc.c,v 1.40 2004-08-31 10:43:35 heikki Exp $ +/* $Id: trunc.c,v 1.41 2004-08-31 14:43:41 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -131,7 +131,7 @@ static void heap_close (struct trunc_info *ti) static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, const char *flags, ISAMS_P *isam_p, int from, int to, int merge_chunk, int preserve_position, - int term_type) + int term_type, NMEM rset_nmem) { RSET result; RSFD result_rsfd; @@ -144,7 +144,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, parms.temp_path = res_get (zi->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); */ - result=rstemp_create(NULL, /* FIXME - use a proper nmem */ + result=rstemp_create( rset_nmem, /* NULL, FIXME - use a proper nmem */ sizeof(struct it_key), key_compare_it, res_get (zi->res, "setTmpDir")); result_rsfd = rset_open (result, RSETF_WRITE); @@ -167,12 +167,12 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, rset[rscur] = rset_trunc_r (zi, term, length, flags, isam_p, i, i+i_add, merge_chunk, preserve_position, - term_type); + term_type, rset_nmem); else rset[rscur] = rset_trunc_r (zi, term, length, flags, isam_p, i, to, merge_chunk, preserve_position, - term_type); + term_type, rset_nmem); rscur++; } ti = heap_init (rscur, sizeof(struct it_key), key_compare_it); @@ -407,15 +407,15 @@ static int isamc_trunc_cmp (const void *p1, const void *p2) RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, const char *term, int length, const char *flags, - int preserve_position, int term_type) + int preserve_position, int term_type, NMEM rset_nmem) { logf (LOG_DEBUG, "rset_trunc no=%d", no); if (no < 1) - return rsnull_create (NULL); /* FIXME - use a proper nmem */ + return rsnull_create (rset_nmem); /* FIXME - use a proper nmem */ if (zi->reg->isams) { if (no == 1) - return rsisams_create(NULL, /* FIXME - use some nmem */ + return rsisams_create(rset_nmem, /* FIXME - use some nmem */ sizeof(struct it_key), key_compare_it, zi->reg->isams, *isam_p); /* @@ -432,7 +432,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, else if (zi->reg->isamc) { if (no == 1) - return rsisamc_create(NULL, /* FIXME - use some nmem */ + return rsisamc_create(rset_nmem, /* FIXME - use some nmem */ sizeof(struct it_key), key_compare_it, zi->reg->isamc, *isam_p); /* @@ -466,7 +466,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, else if (zi->reg->isamb) { if (no == 1) - return rsisamb_create(NULL, /* FIXME - use some nmem */ + return rsisamb_create(rset_nmem, /* FIXME - use some nmem */ sizeof(struct it_key), key_compare_it, zi->reg->isamb, *isam_p); /* @@ -489,7 +489,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, rsets[i]=rsisamb_create(NULL, /* */ sizeof(struct it_key), key_compare_it, zi->reg->isamb, isam_p[i] ); - r=rsmultior_create( NULL, /* FIXME - use some nmem */ + r=rsmultior_create( rset_nmem, /* FIXME - use some nmem */ sizeof(struct it_key), key_compare_it, no, rsets); xfree(rsets); @@ -522,6 +522,6 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, return rsnull_create (NULL); /* FIXME - nmem */ } return rset_trunc_r (zi, term, length, flags, isam_p, 0, no, 100, - preserve_position, term_type); + preserve_position, term_type, rset_nmem); } diff --git a/index/zrpn.c b/index/zrpn.c index fc43193..b4b7472 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,4 +1,4 @@ -/* $Id: zrpn.c,v 1.147 2004-08-31 10:43:35 heikki Exp $ +/* $Id: zrpn.c,v 1.148 2004-08-31 14:43:41 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -877,7 +877,8 @@ static RSET term_trunc (ZebraHandle zh, Z_AttributesPlusTerm *zapt, int reg_type, int complete_flag, int num_bases, char **basenames, char *term_dst, - const char *rank_type, int xpath_use) + const char *rank_type, int xpath_use, + NMEM rset_nmem) { int r; grep_info->isam_p_indx = 0; @@ -890,7 +891,7 @@ static RSET term_trunc (ZebraHandle zh, Z_AttributesPlusTerm *zapt, return rset_trunc (zh, grep_info->isam_p_buf, grep_info->isam_p_indx, term_dst, strlen(term_dst), rank_type, 1 /* preserve pos */, - zapt->term->which); + zapt->term->which, rset_nmem); } @@ -1362,7 +1363,8 @@ static RSET rpn_search_APT_phrase (ZebraHandle zh, NMEM stream, int reg_type, int complete_flag, const char *rank_type, int xpath_use, - int num_bases, char **basenames) + int num_bases, char **basenames, + NMEM rset_nmem) { char term_dst[IT_MAX_WORD+1]; RSET rset[60], result; @@ -1382,7 +1384,7 @@ static RSET rpn_search_APT_phrase (ZebraHandle zh, reg_type, complete_flag, num_bases, basenames, term_dst, rank_type, - xpath_use); + xpath_use,rset_nmem); if (!rset[rset_no]) break; if (++rset_no >= (int) (sizeof(rset)/sizeof(*rset))) @@ -1410,7 +1412,8 @@ static RSET rpn_search_APT_or_list (ZebraHandle zh, int reg_type, int complete_flag, const char *rank_type, int xpath_use, - int num_bases, char **basenames) + int num_bases, char **basenames, + NMEM rset_nmem) { char term_dst[IT_MAX_WORD+1]; RSET rset[60]; @@ -1429,7 +1432,7 @@ static RSET rpn_search_APT_or_list (ZebraHandle zh, reg_type, complete_flag, num_bases, basenames, term_dst, rank_type, - xpath_use); + xpath_use,rset_nmem); if (!rset[rset_no]) break; if (++rset_no >= (int) (sizeof(rset)/sizeof(*rset))) @@ -1437,8 +1440,8 @@ static RSET rpn_search_APT_or_list (ZebraHandle zh, } grep_info_delete (&grep_info); if (rset_no == 0) - return rsnull_create (NULL); /* FIXME - Use a proper nmem */ - return rsmultior_create(NULL, /* FIXME */ + return rsnull_create (rset_nmem); + return rsmultior_create(rset_nmem, sizeof(struct it_key), key_compare_it, rset_no, rset); @@ -1468,7 +1471,8 @@ static RSET rpn_search_APT_and_list (ZebraHandle zh, int reg_type, int complete_flag, const char *rank_type, int xpath_use, - int num_bases, char **basenames) + int num_bases, char **basenames, + NMEM rset_nmem) { char term_dst[IT_MAX_WORD+1]; RSET rset[60], result; @@ -1487,7 +1491,7 @@ static RSET rpn_search_APT_and_list (ZebraHandle zh, reg_type, complete_flag, num_bases, basenames, term_dst, rank_type, - xpath_use); + xpath_use, rset_nmem); if (!rset[rset_no]) break; assert (rset[rset_no]); @@ -1496,7 +1500,7 @@ static RSET rpn_search_APT_and_list (ZebraHandle zh, } grep_info_delete (&grep_info); if (rset_no == 0) - return rsnull_create (NULL); /* FIXME - Use a proper nmem */ + return rsnull_create (rset_nmem); result = rset[0]; /* FIXME - Use a proper rsmultiand */ for (i = 1; iterm->which); + zapt->term->which, rset_nmem); assert (rset[rset_no]); if (++rset_no >= (int) (sizeof(rset)/sizeof(*rset))) break; } grep_info_delete (&grep_info); if (rset_no == 0) - return rsnull_create (NULL); /* FIXME - Use a proper nmem */ + return rsnull_create (rset_nmem); result = rset[0]; for (i = 1; ires, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); */ - result = rstemp_create( NULL, /* FIXME - use a proper nmem */ + result = rstemp_create( rset_nmem, sizeof (struct it_key), key_compare_it, res_get (zh->res, "setTmpDir") ); rsfd = rset_open (result, RSETF_WRITE); @@ -1917,7 +1922,7 @@ static int parse_xpath(ZebraHandle zh, Z_AttributesPlusTerm *zapt, static RSET xpath_trunc(ZebraHandle zh, NMEM stream, int reg_type, const char *term, int use, - oid_value curAttributeSet) + oid_value curAttributeSet, NMEM rset_nmem) { RSET rset; struct grep_info grep_info; @@ -1930,10 +1935,10 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, const char *flags = "void"; if (grep_info_prepare (zh, 0 /* zapt */, &grep_info, '0', stream)) - return rsnull_create (NULL); /* FIXME - Use a proper nmem */ + return rsnull_create (rset_nmem); if (ord < 0) - return rsnull_create (NULL); /* FIXME - Use a proper nmem */ + return rsnull_create (rset_nmem); if (prefix_len) term_dict[prefix_len++] = '|'; else @@ -1958,7 +1963,7 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, grep_info.isam_p_indx); rset = rset_trunc (zh, grep_info.isam_p_buf, grep_info.isam_p_indx, term, strlen(term), - flags, 1, term_type); + flags, 1, term_type,rset_nmem); grep_info_delete (&grep_info); return rset; } @@ -1967,7 +1972,8 @@ static RSET rpn_search_xpath (ZebraHandle zh, oid_value attributeSet, int num_bases, char **basenames, NMEM stream, const char *rank_type, RSET rset, - int xpath_len, struct xpath_location_step *xpath) + int xpath_len, struct xpath_location_step *xpath, + NMEM rset_nmem) { oid_value curAttributeSet = attributeSet; int base_no; @@ -2076,7 +2082,8 @@ static RSET rpn_search_xpath (ZebraHandle zh, } wrbuf_puts(wbuf, ""); rset_attr = xpath_trunc ( - zh, stream, '0', wrbuf_buf(wbuf), 3, curAttributeSet); + zh, stream, '0', wrbuf_buf(wbuf), 3, + curAttributeSet,rset_nmem); wrbuf_free(wbuf, 1); } else @@ -2087,11 +2094,11 @@ static RSET rpn_search_xpath (ZebraHandle zh, yaz_log (LOG_LOG, "xpath_rev (%d) = %s", level, xpath_rev); if (strlen(xpath_rev)) { - rset_start_tag = xpath_trunc(zh, stream, - '0', xpath_rev, 1, curAttributeSet); + rset_start_tag = xpath_trunc(zh, stream, '0', + xpath_rev, 1, curAttributeSet, rset_nmem); - rset_end_tag = xpath_trunc(zh, stream, - '0', xpath_rev, 2, curAttributeSet); + rset_end_tag = xpath_trunc(zh, stream, '0', + xpath_rev, 2, curAttributeSet, rset_nmem); /* parms.key_size = sizeof(struct it_key); @@ -2103,7 +2110,7 @@ static RSET rpn_search_xpath (ZebraHandle zh, parms.printer = key_print_it; rset = rset_create (rset_kind_between, &parms); */ - rset=rsbetween_create( NULL, /* FIXME */ + rset=rsbetween_create( rset_nmem, sizeof(struct it_key), key_compare_it, rset_start_tag, rset, rset_end_tag, rset_attr, key_print_it ); @@ -2120,7 +2127,8 @@ static RSET rpn_search_xpath (ZebraHandle zh, static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, oid_value attributeSet, NMEM stream, Z_SortKeySpecList *sort_sequence, - int num_bases, char **basenames) + int num_bases, char **basenames, + NMEM rset_nmem) { unsigned reg_id; char *search_type = NULL; @@ -2160,33 +2168,33 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, rset = rpn_search_APT_phrase (zh, zapt, termz, attributeSet, stream, reg_id, complete_flag, rank_type, xpath_use, - num_bases, basenames); + num_bases, basenames, rset_nmem); } else if (!strcmp (search_type, "and-list")) { rset = rpn_search_APT_and_list (zh, zapt, termz, attributeSet, stream, reg_id, complete_flag, rank_type, xpath_use, - num_bases, basenames); + num_bases, basenames, rset_nmem); } else if (!strcmp (search_type, "or-list")) { rset = rpn_search_APT_or_list (zh, zapt, termz, attributeSet, stream, reg_id, complete_flag, rank_type, xpath_use, - num_bases, basenames); + num_bases, basenames, rset_nmem); } else if (!strcmp (search_type, "local")) { rset = rpn_search_APT_local (zh, zapt, termz, attributeSet, stream, - rank_type); + rank_type, rset_nmem); } else if (!strcmp (search_type, "numeric")) { rset = rpn_search_APT_numeric (zh, zapt, termz, attributeSet, stream, reg_id, complete_flag, rank_type, xpath_use, - num_bases, basenames); + num_bases, basenames, rset_nmem); } else if (!strcmp (search_type, "always")) { @@ -2195,7 +2203,8 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, else zh->errCode = 118; return rpn_search_xpath (zh, attributeSet, num_bases, basenames, - stream, rank_type, rset, xpath_len, xpath); + stream, rank_type, rset, + xpath_len, xpath, rset_nmem); } static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs, @@ -2302,7 +2311,7 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs, logf (LOG_DEBUG, "rpn_search_APT"); r = rpn_search_APT (zh, zs->u.simple->u.attributesPlusTerm, attributeSet, stream, sort_sequence, - num_bases, basenames); + num_bases, basenames,rset_nmem); } else if (zs->u.simple->which == Z_Operand_resultSetId) { @@ -2512,6 +2521,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, char rank_type[128]; int complete_flag; int sort_flag; + NMEM rset_nmem=NULL; *list = 0; @@ -2655,6 +2665,8 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, glist = (ZebraScanEntry *) odr_malloc (stream, (before+after)*sizeof(*glist)); + rset_nmem=nmem_create(); + /* consider terms after main term */ for (i = 0; i < ord_no; i++) ptr[i] = before; @@ -2683,7 +2695,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, &glist[i+before].term, mterm); rset = rset_trunc (zh, &scan_info_array[j0].list[ptr[j0]].isam_p, 1, glist[i+before].term, strlen(glist[i+before].term), - NULL, 0, zapt->term->which); + NULL, 0, zapt->term->which, rset_nmem); ptr[j0]++; for (j = j0+1; jterm->which); -/* - bool_parms.key_size = sizeof(struct it_key); - bool_parms.cmp = key_compare_it; - bool_parms.log_item = key_logdump_txt; - bool_parms.rset_l = rset; - bool_parms.rset_r = rset2; - rset = rset_create (rset_kind_or, &bool_parms); -*/ - rset = rsbool_create_or(NULL, /* FIXME -use a proper nmem */ + zapt->term->which,rset_nmem); + rset = rsbool_create_or(rset_nmem, sizeof(struct it_key), key_compare_it, rset, rset2, key_logdump_txt); @@ -2715,21 +2719,10 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, } } if (limit_set) - { - /* - rset_bool_parms bool_parms; - bool_parms.key_size = sizeof(struct it_key); - bool_parms.cmp = key_compare_it; - bool_parms.log_item = key_logdump_txt; - bool_parms.rset_l = rset; - bool_parms.rset_r = rset_dup(limit_set); - rset = rset_create (rset_kind_and, &bool_parms); - */ - rset = rsbool_create_and(NULL, /* FIXME -use a proper nmem */ + rset = rsbool_create_and(rset_nmem, sizeof(struct it_key), key_compare_it, rset, rset_dup(limit_set), key_logdump_txt); - } count_set (rset, &glist[i+before].occurrences); rset_delete (rset); } @@ -2769,7 +2762,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, rset = rset_trunc (zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1, glist[before-1-i].term, strlen(glist[before-1-i].term), - NULL, 0, zapt->term->which); + NULL, 0, zapt->term->which,rset_nmem); ptr[j0]++; @@ -2785,16 +2778,8 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, &scan_info_array[j].list[before-1-ptr[j]].isam_p, 1, glist[before-1-i].term, strlen(glist[before-1-i].term), NULL, 0, - zapt->term->which); -/* - bool_parms.key_size = sizeof(struct it_key); - bool_parms.cmp = key_compare_it; - bool_parms.log_item = key_logdump_txt; - bool_parms.rset_l = rset; - bool_parms.rset_r = rset2; - rset = rset_create (rset_kind_or, &bool_parms); -*/ - rset = rsbool_create_and(NULL, /* FIXME -use a proper nmem */ + zapt->term->which, rset_nmem); + rset = rsbool_create_and(rset_nmem, sizeof(struct it_key), key_compare_it, rset, rset2, key_logdump_txt); @@ -2802,23 +2787,10 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, } } if (limit_set) - { - /* - rset_bool_parms bool_parms; - - bool_parms.key_size = sizeof(struct it_key); - bool_parms.cmp = key_compare_it; - bool_parms.log_item = key_logdump_txt; - bool_parms.rset_l = rset; - bool_parms.rset_r = rset_dup(limit_set); - - rset = rset_create (rset_kind_and, &bool_parms); - */ - rset = rsbool_create_and(NULL, /* FIXME -use a proper nmem */ + rset = rsbool_create_and(rset_nmem, sizeof(struct it_key), key_compare_it, rset, rset_dup(limit_set), key_logdump_txt); - } count_set (rset, &glist[before-1-i].occurrences); rset_delete (rset); } @@ -2829,6 +2801,8 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, *position -= i; *num_entries -= i; } + + nmem_destroy(rset_nmem); *list = glist + i; /* list is set to first 'real' entry */ logf (LOG_DEBUG, "position = %d, num_entries = %d", diff --git a/rset/rset.c b/rset/rset.c index 51df906..798ff8b 100644 --- a/rset/rset.c +++ b/rset/rset.c @@ -1,4 +1,4 @@ -/* $Id: rset.c,v 1.29 2004-08-31 10:43:39 heikki Exp $ +/* $Id: rset.c,v 1.30 2004-08-31 14:43:42 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -66,12 +66,14 @@ void rfd_delete_base(RSFD rfd) rs->free_list=rfd; } + RSET rset_create_base(const struct rset_control *sel, NMEM nmem) /* FIXME - Add keysize and cmp function */ /* FIXME - Add a general key-func block for cmp, dump, etc */ { RSET rnew; NMEM M; + /* assert(nmem); */ /* can not yet be used, api/t4 fails */ if (nmem) M=nmem; else diff --git a/rset/rsisamb.c b/rset/rsisamb.c index e39ac6b..e4c58e1 100644 --- a/rset/rsisamb.c +++ b/rset/rsisamb.c @@ -1,4 +1,4 @@ -/* $Id: rsisamb.c,v 1.19 2004-08-31 10:43:39 heikki Exp $ +/* $Id: rsisamb.c,v 1.20 2004-08-31 14:43:42 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -49,7 +49,7 @@ static const struct rset_control control = r_open, r_close, r_rewind, - r_forward, /* rset_default_forward, */ + r_forward, r_pos, r_read, r_write,