From f76093fc0b3b07a5b5a9d83e4c62dd467df8f53d Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 9 Sep 2004 09:07:12 +0000 Subject: [PATCH] Extra page_size arg for dict_open. Wrapper function dict_open_res that reads dict parmeters from resources (if set). --- dict/dcompact.c | 6 +++--- dict/dicttest.c | 4 ++-- dict/open.c | 18 +++++++----------- include/dict.h | 6 +++--- index/index.h | 5 ++++- index/trav.c | 8 ++++---- index/zebraapi.c | 25 ++++++++++++++++++++++--- 7 files changed, 45 insertions(+), 27 deletions(-) diff --git a/dict/dcompact.c b/dict/dcompact.c index e2f8a8c..489e79f 100644 --- a/dict/dcompact.c +++ b/dict/dcompact.c @@ -1,4 +1,4 @@ -/* $Id: dcompact.c,v 1.8 2002-08-02 19:26:55 adam Exp $ +/* $Id: dcompact.c,v 1.9 2004-09-09 09:07:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -93,13 +93,13 @@ int dict_copy_compact (BFiles bfs, const char *from_name, const char *to_name) int no_dir = 0; Dict dict_from, dict_to; int *map, i; - dict_from = dict_open (bfs, from_name, 0, 0, 0); + dict_from = dict_open (bfs, from_name, 0, 0, 0, 4096); if (!dict_from) return -1; map = (int *) xmalloc ((dict_from->head.last+1) * sizeof(*map)); for (i = 0; i <= (int) (dict_from->head.last); i++) map[i] = -1; - dict_to = dict_open (bfs, to_name, 0, 1, 1); + dict_to = dict_open (bfs, to_name, 0, 1, 1, 4096); if (!dict_to) return -1; map[0] = 0; diff --git a/dict/dicttest.c b/dict/dicttest.c index 85cce13..dbe0aeb 100644 --- a/dict/dicttest.c +++ b/dict/dicttest.c @@ -1,4 +1,4 @@ -/* $Id: dicttest.c,v 1.28 2004-01-22 11:27:20 adam Exp $ +/* $Id: dicttest.c,v 1.29 2004-09-09 09:07:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -172,7 +172,7 @@ int main (int argc, char **argv) logf (LOG_FATAL, "bfs_create fail"); exit (1); } - dict = dict_open (bfs, name, cache, rw, 0); + dict = dict_open (bfs, name, cache, rw, 0, 4096); if (!dict) { logf (LOG_FATAL, "dict_open fail of `%s'", name); diff --git a/dict/open.c b/dict/open.c index 4feca53..d43476b 100644 --- a/dict/open.c +++ b/dict/open.c @@ -1,5 +1,5 @@ -/* $Id: open.c,v 1.19 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: open.c,v 1.20 2004-09-09 09:07:12 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -29,25 +29,22 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include Dict dict_open (BFiles bfs, const char *name, int cache, int rw, - int compact_flag) + int compact_flag, int page_size) { Dict dict; void *head_buf; - char resource_str[80]; - int page_size; dict = (Dict) xmalloc (sizeof(*dict)); if (cache < 5) cache = 5; - sprintf (resource_str, "dict.%s.pagesize", name); dict->grep_cmap = NULL; page_size = DICT_DEFAULT_PAGESIZE; if (page_size < 2048) { - logf (LOG_WARN, "Resource %s was too small. Set to 2048", - resource_str); + logf (LOG_WARN, "Page size for dict %s %d<2048. Set to 2048", + name, page_size); page_size = 2048; } dict->dbf = dict_bf_open (bfs, name, page_size, cache, rw); @@ -83,9 +80,8 @@ Dict dict_open (BFiles bfs, const char *name, int cache, int rw, } if (dict->head.page_size != page_size) { - logf (LOG_WARN, "Resource %s is %d and pagesize of `%s' is %d", - resource_str, page_size, name, dict->head.page_size); - return 0; + logf (LOG_WARN, "Page size for existing dict %s is %d. Current is %d", + name, dict->head.page_size, page_size); } } if (dict->head.compact_flag) diff --git a/include/dict.h b/include/dict.h index 73ae9de..993e97a 100644 --- a/include/dict.h +++ b/include/dict.h @@ -1,5 +1,5 @@ -/* $Id: dict.h,v 1.32 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: dict.h,v 1.33 2004-09-09 09:07:12 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -93,7 +93,7 @@ int dict_bf_close (Dict_BFile dbf); void dict_bf_compact (Dict_BFile dbf); Dict dict_open (BFiles bfs, const char *name, int cache, int rw, - int compact_flag); + int compact_flag, int page_size); int dict_close (Dict dict); int dict_insert (Dict dict, const char *p, int userlen, void *userinfo); int dict_delete (Dict dict, const char *p); diff --git a/index/index.h b/index/index.h index d92e5e5..e170208 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.117 2004-09-01 15:01:32 heikki Exp $ +/* $Id: index.h,v 1.118 2004-09-09 09:07:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -498,6 +498,9 @@ void iscz1_stop (void *p); void iscz1_decode (void *vp, char **dst, const char **src); void iscz1_encode (void *vp, char **dst, const char **src); +Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw, + int compact_flag, Res res); + YAZ_END_CDECL #endif diff --git a/index/trav.c b/index/trav.c index bfa2a46..6b876b3 100644 --- a/index/trav.c +++ b/index/trav.c @@ -1,4 +1,4 @@ -/* $Id: trav.c,v 1.44 2004-01-22 11:27:21 adam Exp $ +/* $Id: trav.c,v 1.45 2004-09-09 09:07:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -258,7 +258,7 @@ void repositoryShow (ZebraHandle zh, const char *path) Dict dict; struct dirs_info *di; - if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50, 0, 0))) + if (!(dict = dict_open_res (zh->reg->bfs, FMATCH_DICT, 50, 0, 0, zh->res))) { yaz_log (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); return; @@ -398,8 +398,8 @@ void repositoryUpdate (ZebraHandle zh, const char *path) if (zh->m_record_id && !strcmp (zh->m_record_id, "file")) { Dict dict; - if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50, - zh->m_flag_rw, 0))) + if (!(dict = dict_open_res (zh->reg->bfs, FMATCH_DICT, 50, + zh->m_flag_rw, 0, zh->res))) { yaz_log (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); return ; diff --git a/index/zebraapi.c b/index/zebraapi.c index 3d9d89f..d1a3cce 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.128 2004-09-03 14:59:49 heikki Exp $ +/* $Id: zebraapi.c,v 1.129 2004-09-09 09:07:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -196,6 +196,25 @@ void zebra_pidfname(ZebraService zs, char *path) strcat(path, "zebrasrv.pid"); } +Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw, + int compact_flag, Res res) +{ + int page_size = 4096; + char resource_str[200]; + const char *v; + sprintf (resource_str, "dict.%.100s.pagesize", name); + + v = res_get(res, resource_str); + if (v) + { + page_size = atoi(v); + yaz_log(LOG_LOG, "Using custom dictionary page size %d for %s", + page_size, name); + } + return dict_open(bfs, name, cache, rw, compact_flag, page_size); +} + + static struct zebra_register *zebra_register_open (ZebraService zs, const char *name, int rw, int useshadow, Res res, @@ -286,9 +305,9 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, } if (rw) { - reg->matchDict = dict_open (reg->bfs, GMATCH_DICT, 20, 1, 0); + reg->matchDict = dict_open_res (reg->bfs, GMATCH_DICT, 20, 1, 0, res); } - if (!(reg->dict = dict_open (reg->bfs, FNAME_DICT, 40, rw, 0))) + if (!(reg->dict = dict_open_res (reg->bfs, FNAME_DICT, 40, rw, 0, res))) { logf (LOG_WARN, "dict_open"); return 0; -- 1.7.10.4