2 * Copyright (C) 1994-1998, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.59 1998-10-16 08:14:32 adam
8 * Updated record control system.
10 * Revision 1.58 1998/06/08 14:43:13 adam
11 * Added suport for EXPLAIN Proxy servers - added settings databasePath
12 * and explainDatabase to facilitate this. Increased maximum number
13 * of databases and attributes in one register.
15 * Revision 1.57 1998/05/20 10:12:18 adam
16 * Implemented automatic EXPLAIN database maintenance.
17 * Modified Zebra to work with ASN.1 compiled version of YAZ.
19 * Revision 1.56 1998/03/05 08:45:12 adam
20 * New result set model and modular ranking system. Moved towards
21 * descent server API. System information stored as "SGML" records.
23 * Revision 1.55 1998/01/26 10:37:34 adam
26 * Revision 1.54 1998/01/12 15:04:08 adam
27 * The test option (-s) only uses read-lock (and not write lock).
29 * Revision 1.53 1997/11/18 10:05:08 adam
30 * Changed character map facility so that admin can specify character
31 * mapping files for each register type, w, p, etc.
33 * Revision 1.52 1997/10/31 12:34:04 adam
34 * Added missing nmem_init.
36 * Revision 1.51 1997/10/27 14:33:05 adam
37 * Moved towards generic character mapping depending on "structure"
38 * field in abstract syntax file. Fixed a few memory leaks. Fixed
39 * bug with negative integers when doing searches with relational
42 * Revision 1.50 1997/09/25 14:55:52 adam
45 * Revision 1.49 1997/09/17 12:19:15 adam
46 * Zebra version corresponds to YAZ version 1.4.
47 * Changed Zebra server so that it doesn't depend on global common_resource.
49 * Revision 1.48 1997/09/09 13:38:08 adam
50 * Partial port to WIN95/NT.
52 * Revision 1.47 1997/02/12 20:39:46 adam
53 * Implemented options -f <n> that limits the log to the first <n>
55 * Changed some log messages also.
57 * Revision 1.46 1997/02/10 10:20:13 adam
58 * Flag fileVerboseFlag set to 0 (default).
60 * Revision 1.45 1996/11/08 11:10:26 adam
61 * Buffers used during file match got bigger.
62 * Compressed ISAM support everywhere.
63 * Bug fixes regarding masking characters in queries.
64 * Redesigned Regexp-2 queries.
66 * Revision 1.44 1996/10/29 14:09:48 adam
67 * Use of cisam system - enabled if setting isamc is 1.
69 * Revision 1.43 1996/06/06 12:08:42 quinn
70 * Added showRecord function
72 * Revision 1.42 1996/05/31 09:07:01 quinn
73 * Work on character-set handling
75 * Revision 1.41 1996/05/14 14:04:34 adam
76 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
79 * Revision 1.40 1996/04/26 10:00:23 adam
80 * Added option -V to zebraidx to display version information.
81 * Removed stupid warnings from file update.
83 * Revision 1.39 1996/04/09 10:05:21 adam
84 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
86 * Revision 1.38 1996/03/26 16:01:14 adam
87 * New setting lockPath: directory of various lock files.
89 * Revision 1.37 1996/03/19 12:43:26 adam
90 * Bug fix: File update traversal didn't handle trailing slashes correctly.
91 * Bug fix: Update of sub directory groups wasn't handled correctly.
93 * Revision 1.36 1996/02/12 18:45:37 adam
94 * New fileVerboseFlag in record group control.
96 * Revision 1.35 1996/02/12 15:56:11 adam
97 * New code command: unread.
99 * Revision 1.34 1996/02/07 14:06:39 adam
100 * Better progress report during register merge.
101 * New command: clean - removes temporary shadow files.
103 * Revision 1.33 1996/02/06 17:11:18 adam
106 * Revision 1.32 1996/02/01 20:50:04 adam
107 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
108 * was never called - happens when no commands are specified.
110 * Revision 1.31 1996/01/08 19:15:46 adam
111 * New input filter that works!
113 * Revision 1.30 1995/12/12 16:00:59 adam
114 * System call sync(2) used after update/commit.
115 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
118 * Revision 1.29 1995/12/11 11:43:30 adam
119 * Locking based on fcntl instead of flock.
120 * Setting commitEnable removed. Command line option -n can be used to
121 * prevent commit if commit setting is defined in the configuration file.
123 * Revision 1.28 1995/12/08 16:22:56 adam
124 * Work on update while servers are running. Three lock files introduced.
125 * The servers reload their registers when necessary, but they don't
126 * reestablish result sets yet.
128 * Revision 1.27 1995/12/07 17:38:47 adam
129 * Work locking mechanisms for concurrent updates/commit.
131 * Revision 1.26 1995/12/06 12:41:23 adam
132 * New command 'stat' for the index program.
133 * Filenames can be read from stdin by specifying '-'.
134 * Bug fix/enhancement of the transformation from terms to regular
135 * expressons in the search engine.
137 * Revision 1.25 1995/12/01 16:24:39 adam
138 * Commit files use separate meta file area.
140 * Revision 1.24 1995/11/30 17:01:38 adam
141 * New setting commitCache: points to commit directories/files.
142 * New command commit: commits at the end of a zebraidx run.
144 * Revision 1.23 1995/11/30 08:34:31 adam
145 * Started work on commit facility.
146 * Changed a few malloc/free to xmalloc/xfree.
148 * Revision 1.22 1995/11/28 09:09:42 adam
149 * Zebra config renamed.
150 * Use setting 'recordId' to identify record now.
151 * Bug fix in recindex.c: rec_release_blocks was invokeded even
152 * though the blocks were already released.
153 * File traversal properly deletes records when needed.
155 * Revision 1.21 1995/11/27 14:27:39 adam
156 * Renamed 'update' command to 'dir'.
158 * Revision 1.20 1995/11/27 13:58:53 adam
159 * New option -t. storeStore data implemented in server.
161 * Revision 1.19 1995/11/25 10:24:06 adam
162 * More record fields - they are enumerated now.
163 * New options: flagStoreData flagStoreKey.
165 * Revision 1.18 1995/11/22 17:19:17 adam
166 * Record management uses the bfile system.
168 * Revision 1.17 1995/11/21 15:01:16 adam
169 * New general match criteria implemented.
170 * New feature: document groups.
172 * Revision 1.16 1995/11/20 11:56:27 adam
173 * Work on new traversal.
175 * Revision 1.15 1995/11/01 16:25:51 quinn
176 * *** empty log message ***
178 * Revision 1.14 1995/10/17 18:02:09 adam
179 * New feature: databases. Implemented as prefix to words in dictionary.
181 * Revision 1.13 1995/10/10 12:24:39 adam
182 * Temporary sort files are compressed.
184 * Revision 1.12 1995/10/04 16:57:20 adam
185 * Key input and merge sort in one pass.
187 * Revision 1.11 1995/09/29 14:01:45 adam
190 * Revision 1.10 1995/09/28 14:22:57 adam
191 * Sort uses smaller temporary files.
193 * Revision 1.9 1995/09/14 07:48:24 adam
194 * Record control management.
196 * Revision 1.8 1995/09/06 16:11:18 adam
197 * Option: only one word key per file.
199 * Revision 1.7 1995/09/05 15:28:39 adam
200 * More work on search engine.
202 * Revision 1.6 1995/09/04 12:33:43 adam
203 * Various cleanup. YAZ util used instead.
205 * Revision 1.5 1995/09/04 09:10:39 adam
206 * More work on index add/del/update.
207 * Merge sort implemented.
208 * Initial work on z39 server.
210 * Revision 1.4 1995/09/01 14:06:36 adam
211 * Split of work into more files.
213 * Revision 1.3 1995/09/01 10:57:07 adam
216 * Revision 1.2 1995/09/01 10:30:24 adam
217 * More work on indexing. Not working yet.
219 * Revision 1.1 1995/08/31 14:50:24 adam
220 * New simple file index tool.
233 #include "recindex.h"
237 Res common_resource = 0;
239 int main (int argc, char **argv)
244 char *configName = NULL;
246 int disableCommit = 0;
249 struct recordGroup rGroupDef;
253 rGroupDef.groupName = NULL;
254 rGroupDef.databaseName = NULL;
255 rGroupDef.path = NULL;
256 rGroupDef.recordId = NULL;
257 rGroupDef.recordType = NULL;
258 rGroupDef.flagStoreData = -1;
259 rGroupDef.flagStoreKeys = -1;
260 rGroupDef.flagRw = 1;
261 rGroupDef.databaseNamePath = 0;
262 rGroupDef.explainDatabase = 0;
263 rGroupDef.fileVerboseLimit = 100000;
264 rGroupDef.zebra_maps = NULL;
265 rGroupDef.dh = data1_create ();
266 rGroupDef.recTypes = recTypes_init (rGroupDef.dh);
267 recTypes_default_handlers (rGroupDef.recTypes);
272 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
274 " update <dir> Update index with files below <dir>.\n"
275 " If <dir> is empty filenames are read from stdin.\n"
276 " delete <dir> Delete index with files below <dir>.\n"
277 " commit Commit changes\n"
278 " clean Clean shadow files\n"
280 " -t <type> Index files as <type> (grs or text).\n"
281 " -c <config> Read configuration file <config>.\n"
282 " -g <group> Index files according to group settings.\n"
283 " -d <database> Records belong to Z39.50 database <database>.\n"
284 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
285 " -n Don't use shadow system.\n"
286 " -s Show analysis on stdout, but do no work.\n"
287 " -v <level> Set logging to <level>.\n"
288 " -f <n> Display information for the first <n> records.\n"
289 " -V Show version.\n"
293 while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2)
298 if(cmd == 0) /* command */
300 if (!common_resource)
302 logf (LOG_LOG, "zebra version %s %s",
303 ZEBRAVER, ZEBRADATE);
304 common_resource = res_open (configName ?
305 configName : FNAME_CONFIG);
306 if (!common_resource)
308 logf (LOG_FATAL, "cannot configuration file `%s'",
312 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
316 bfs_create (res_get (common_resource, "register"));
318 bf_lockDir (rGroupDef.bfs,
319 res_get (common_resource, "lockDir"));
320 rGroupDef.zebra_maps = zebra_maps_open (common_resource);
322 if (!strcmp (arg, "update"))
324 else if (!strcmp (arg, "update1"))
326 else if (!strcmp (arg, "update2"))
328 else if (!strcmp (arg, "dump"))
330 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
332 else if (!strcmp (arg, "commit"))
334 rval = res_get (common_resource, "shadow");
335 zebraIndexLock (rGroupDef.bfs, 1, rval);
337 bf_cache (rGroupDef.bfs, rval);
340 logf (LOG_FATAL, "Cannot perform commit");
341 logf (LOG_FATAL, "No shadow area defined");
344 if (bf_commitExists (rGroupDef.bfs))
346 logf (LOG_LOG, "commit start");
347 zebraIndexLockMsg ("c");
349 logf (LOG_LOG, "commit execute");
350 bf_commitExec (rGroupDef.bfs);
354 zebraIndexLockMsg ("d");
356 logf (LOG_LOG, "commit clean");
357 bf_commitClean (rGroupDef.bfs, rval);
360 logf (LOG_LOG, "cothing to commit");
362 else if (!strcmp (arg, "clean"))
364 rval = res_get (common_resource, "shadow");
365 zebraIndexLock (rGroupDef.bfs, 1, rval);
366 if (bf_commitExists (rGroupDef.bfs))
368 zebraIndexLockMsg ("d");
370 logf (LOG_LOG, "commit clean");
371 bf_commitClean (rGroupDef.bfs, rval);
374 logf (LOG_LOG, "nothing to clean");
376 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
379 rval = res_get (common_resource, "shadow");
380 zebraIndexLock (rGroupDef.bfs, 0, rval);
383 bf_cache (rGroupDef.bfs, rval);
384 zebraIndexLockMsg ("r");
386 records = rec_open (rGroupDef.bfs, 0);
387 rec_prstat (records);
388 rec_close (&records);
389 inv_prstat (rGroupDef.bfs);
393 logf (LOG_FATAL, "unknown command: %s", arg);
399 struct recordGroup rGroup;
401 rval = res_get (common_resource, "shadow");
402 zebraIndexLock (rGroupDef.bfs, 0, rval);
403 if (rGroupDef.flagRw)
405 if (rval && *rval && !disableCommit)
407 bf_cache (rGroupDef.bfs, rval);
408 zebraIndexLockMsg ("r");
412 bf_cache (rGroupDef.bfs, 0);
413 zebraIndexLockMsg ("w");
417 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
422 if (!key_open (&rGroup, mem_max))
424 logf (LOG_LOG, "updating %s", rGroup.path);
425 repositoryUpdate (&rGroup);
426 nsections = key_close (&rGroup);
430 if (!key_open (&rGroup, mem_max))
432 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
433 repositoryUpdate (&rGroup);
439 if (!key_open (&rGroup,mem_max))
441 logf (LOG_LOG, "deleting %s", rGroup.path);
442 repositoryDelete (&rGroup);
443 nsections = key_close (&rGroup);
447 logf (LOG_LOG, "dumping %s", rGroup.path);
448 repositoryShow (&rGroup);
460 logf (LOG_LOG, "merging with index");
461 key_input (rGroup.bfs, nsections, 60);
466 log_event_end (NULL, NULL);
471 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
474 log_init (log_mask_str(arg), prog, NULL);
476 mem_max = 1024*1024*atoi(arg);
478 rGroupDef.databaseName = arg;
480 rGroupDef.flagRw = 0;
482 rGroupDef.groupName = arg;
484 rGroupDef.fileVerboseLimit = atoi(arg);
488 rGroupDef.recordType = arg;
492 logf (LOG_WARN, "unknown option '-%s'", arg);
497 bfs_destroy (rGroupDef.bfs);
499 data1_destroy (rGroupDef.dh);