From b33ab4fd103294017212e045a0eb1bd7ecd292ff Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Tue, 22 Oct 2002 09:37:55 +0000 Subject: [PATCH] API to the resource system, passing memMax through it. --- index/extract.c | 11 +++++++++-- index/main.c | 18 +++++++++++++++--- index/zebraapi.c | 15 +++++++++++++-- index/zebraapi.h | 10 +++++++++- util/res.c | 26 +++++++++++++++++++------- 5 files changed, 65 insertions(+), 15 deletions(-) diff --git a/index/extract.c b/index/extract.c index e6d1aac..e7e8cc6 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.124 2002-10-16 09:30:57 heikki Exp $ +/* $Id: extract.c,v 1.125 2002-10-22 09:37:55 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -1222,7 +1222,14 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, if (!zh->reg->key_buf) { - int mem = 8*1024*1024; + int mem= 1024*1024* atoi( res_get_def( zh->res, "memmax", "8")); + if (mem <= 0) + { + logf(LOG_WARN, "Invalid memory setting, using default 8 MB"); + mem= 1024*1024*8; + } + /* FIXME: That "8" should be in a default settings include */ + /* not hard-coded here! -H */ zh->reg->key_buf = (char**) xmalloc (mem); zh->reg->ptr_top = mem/sizeof(char*); zh->reg->ptr_i = 0; diff --git a/index/main.c b/index/main.c index d9574c7..b86f13b 100644 --- a/index/main.c +++ b/index/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.98 2002-10-04 18:15:09 adam Exp $ +/* $Id: main.c,v 1.99 2002-10-22 09:37:55 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -48,7 +48,8 @@ int main (int argc, char **argv) char *configName = 0; int nsections = 0; int disableCommit = 0; - size_t mem_max = 0; + char *mem_max = 0; + int trans_started=0; #if HAVE_SYS_TIMES_H struct tms tms1, tms2; @@ -135,16 +136,27 @@ int main (int argc, char **argv) if (disableCommit) zebra_shadow_enable (zh, 0); } + if (rGroupDef.databaseName) { if (zebra_select_database (zh, rGroupDef.databaseName)) + { + logf(LOG_FATAL, "Could not select database %s errCode=%d", + rGroupDef.databaseName, zebra_errCode(zh) ); exit (1); + } } else { if (zebra_select_database (zh, "Default")) + { + logf(LOG_FATAL, "Could not select database Default errCode=%d", + zebra_errCode(zh) ); exit (1); + } } + if (mem_max) + zebra_set_resource(zh, "memmax",mem_max); if (!strcmp (arg, "update")) cmd = 'u'; @@ -236,7 +248,7 @@ int main (int argc, char **argv) else if (ret == 'l') yaz_log_init_file (arg); else if (ret == 'm') - mem_max = 1024*1024*atoi(arg); + mem_max = arg; else if (ret == 'd') rGroupDef.databaseName = arg; else if (ret == 's') diff --git a/index/zebraapi.c b/index/zebraapi.c index b8965cd..80d727b 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.73 2002-09-17 12:27:12 adam Exp $ +/* $Id: zebraapi.c,v 1.74 2002-10-22 09:37:56 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -84,7 +84,7 @@ ZebraHandle zebra_open (ZebraService zs) zh->destroyed = 0; zh->errCode = 0; zh->errString = 0; - zh->res = 0; + zh->res = 0; zh->reg_name = xstrdup (""); zh->path_reg = 0; @@ -1403,3 +1403,14 @@ int zebra_record_encoding (ZebraHandle zh, const char *encoding) zh->record_encoding = xstrdup (encoding); return 0; } + +void zebra_set_resource(ZebraHandle zh, const char *name, const char *value) +{ + res_put(zh->res, name, value); +} + +const char *zebra_get_resource(ZebraHandle zh, + const char *name, const char *defaultvalue) +{ + return res_get_def( zh->res, name, (char *)defaultvalue); +} diff --git a/index/zebraapi.h b/index/zebraapi.h index 9ac0a81..2e00a2d 100644 --- a/index/zebraapi.h +++ b/index/zebraapi.h @@ -1,4 +1,4 @@ -/* $Id: zebraapi.h,v 1.21 2002-09-17 12:27:12 adam Exp $ +/* $Id: zebraapi.h,v 1.22 2002-10-22 09:37:56 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -184,5 +184,13 @@ void zebra_register_statistics (ZebraHandle zh, int dumpdict); YAZ_EXPORT int zebra_record_encoding (ZebraHandle zh, const char *encoding); +/* Resources */ +YAZ_EXPORT +void zebra_set_resource(ZebraHandle zh, const char *name, const char *value); +YAZ_EXPORT +const char *zebra_get_resource(ZebraHandle zh, + const char *name, const char *defaultvalue); + + YAZ_END_CDECL #endif diff --git a/util/res.c b/util/res.c index 57c1d09..c1f5c12 100644 --- a/util/res.c +++ b/util/res.c @@ -1,4 +1,4 @@ -/* $Id: res.c,v 1.32 2002-09-09 09:35:48 adam Exp $ +/* $Id: res.c,v 1.33 2002-10-22 09:37:56 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -78,6 +78,9 @@ static void reread (Res r) val_buf = (char*) xmalloc (val_max); + if (!r->name) + return; + fr = fopen (r->name, "r"); if (!fr) { @@ -175,19 +178,26 @@ static void reread (Res r) Res res_open (const char *name, Res def_res) { Res r; + + if (name) + { #ifdef WIN32 - if (access (name, 4)) + if (access (name, 4)) #else - if (access (name, R_OK)) + if (access (name, R_OK)) #endif - { - logf (LOG_WARN|LOG_ERRNO, "Cannot open `%s'", name); - return 0; + { + logf (LOG_WARN|LOG_ERRNO, "Cannot open `%s'", name); + return 0; + } } r = (Res) xmalloc (sizeof(*r)); r->init = 0; r->first = r->last = NULL; - r->name = xstrdup (name); + if (name) + r->name = xstrdup (name); + else + r->name=0; r->def_res = def_res; return r; } @@ -305,6 +315,8 @@ int res_write (Res r) assert (r); if (!r->init) reread (r); + if (!r->name) + return 0; /* ok, this was not from a file */ fr = fopen (r->name, "w"); if (!fr) { -- 1.7.10.4