2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.65 1999-05-20 12:57:18 adam
8 * Implemented TCL filter. Updated recctrl system.
10 * Revision 1.64 1999/05/15 14:36:38 adam
11 * Updated dictionary. Implemented "compression" of dictionary.
13 * Revision 1.63 1999/03/09 16:27:49 adam
14 * More work on SDRKit integration.
16 * Revision 1.62 1999/02/18 15:01:24 adam
19 * Revision 1.61 1999/02/02 14:51:00 adam
20 * Updated WIN32 code specific sections. Changed header.
22 * Revision 1.60 1998/10/28 10:54:39 adam
25 * Revision 1.59 1998/10/16 08:14:32 adam
26 * Updated record control system.
28 * Revision 1.58 1998/06/08 14:43:13 adam
29 * Added suport for EXPLAIN Proxy servers - added settings databasePath
30 * and explainDatabase to facilitate this. Increased maximum number
31 * of databases and attributes in one register.
33 * Revision 1.57 1998/05/20 10:12:18 adam
34 * Implemented automatic EXPLAIN database maintenance.
35 * Modified Zebra to work with ASN.1 compiled version of YAZ.
37 * Revision 1.56 1998/03/05 08:45:12 adam
38 * New result set model and modular ranking system. Moved towards
39 * descent server API. System information stored as "SGML" records.
41 * Revision 1.55 1998/01/26 10:37:34 adam
44 * Revision 1.54 1998/01/12 15:04:08 adam
45 * The test option (-s) only uses read-lock (and not write lock).
47 * Revision 1.53 1997/11/18 10:05:08 adam
48 * Changed character map facility so that admin can specify character
49 * mapping files for each register type, w, p, etc.
51 * Revision 1.52 1997/10/31 12:34:04 adam
52 * Added missing nmem_init.
54 * Revision 1.51 1997/10/27 14:33:05 adam
55 * Moved towards generic character mapping depending on "structure"
56 * field in abstract syntax file. Fixed a few memory leaks. Fixed
57 * bug with negative integers when doing searches with relational
60 * Revision 1.50 1997/09/25 14:55:52 adam
63 * Revision 1.49 1997/09/17 12:19:15 adam
64 * Zebra version corresponds to YAZ version 1.4.
65 * Changed Zebra server so that it doesn't depend on global common_resource.
67 * Revision 1.48 1997/09/09 13:38:08 adam
68 * Partial port to WIN95/NT.
70 * Revision 1.47 1997/02/12 20:39:46 adam
71 * Implemented options -f <n> that limits the log to the first <n>
73 * Changed some log messages also.
75 * Revision 1.46 1997/02/10 10:20:13 adam
76 * Flag fileVerboseFlag set to 0 (default).
78 * Revision 1.45 1996/11/08 11:10:26 adam
79 * Buffers used during file match got bigger.
80 * Compressed ISAM support everywhere.
81 * Bug fixes regarding masking characters in queries.
82 * Redesigned Regexp-2 queries.
84 * Revision 1.44 1996/10/29 14:09:48 adam
85 * Use of cisam system - enabled if setting isamc is 1.
87 * Revision 1.43 1996/06/06 12:08:42 quinn
88 * Added showRecord function
90 * Revision 1.42 1996/05/31 09:07:01 quinn
91 * Work on character-set handling
93 * Revision 1.41 1996/05/14 14:04:34 adam
94 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
97 * Revision 1.40 1996/04/26 10:00:23 adam
98 * Added option -V to zebraidx to display version information.
99 * Removed stupid warnings from file update.
101 * Revision 1.39 1996/04/09 10:05:21 adam
102 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
104 * Revision 1.38 1996/03/26 16:01:14 adam
105 * New setting lockPath: directory of various lock files.
107 * Revision 1.37 1996/03/19 12:43:26 adam
108 * Bug fix: File update traversal didn't handle trailing slashes correctly.
109 * Bug fix: Update of sub directory groups wasn't handled correctly.
111 * Revision 1.36 1996/02/12 18:45:37 adam
112 * New fileVerboseFlag in record group control.
114 * Revision 1.35 1996/02/12 15:56:11 adam
115 * New code command: unread.
117 * Revision 1.34 1996/02/07 14:06:39 adam
118 * Better progress report during register merge.
119 * New command: clean - removes temporary shadow files.
121 * Revision 1.33 1996/02/06 17:11:18 adam
124 * Revision 1.32 1996/02/01 20:50:04 adam
125 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
126 * was never called - happens when no commands are specified.
128 * Revision 1.31 1996/01/08 19:15:46 adam
129 * New input filter that works!
131 * Revision 1.30 1995/12/12 16:00:59 adam
132 * System call sync(2) used after update/commit.
133 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
136 * Revision 1.29 1995/12/11 11:43:30 adam
137 * Locking based on fcntl instead of flock.
138 * Setting commitEnable removed. Command line option -n can be used to
139 * prevent commit if commit setting is defined in the configuration file.
141 * Revision 1.28 1995/12/08 16:22:56 adam
142 * Work on update while servers are running. Three lock files introduced.
143 * The servers reload their registers when necessary, but they don't
144 * reestablish result sets yet.
146 * Revision 1.27 1995/12/07 17:38:47 adam
147 * Work locking mechanisms for concurrent updates/commit.
149 * Revision 1.26 1995/12/06 12:41:23 adam
150 * New command 'stat' for the index program.
151 * Filenames can be read from stdin by specifying '-'.
152 * Bug fix/enhancement of the transformation from terms to regular
153 * expressons in the search engine.
155 * Revision 1.25 1995/12/01 16:24:39 adam
156 * Commit files use separate meta file area.
158 * Revision 1.24 1995/11/30 17:01:38 adam
159 * New setting commitCache: points to commit directories/files.
160 * New command commit: commits at the end of a zebraidx run.
162 * Revision 1.23 1995/11/30 08:34:31 adam
163 * Started work on commit facility.
164 * Changed a few malloc/free to xmalloc/xfree.
166 * Revision 1.22 1995/11/28 09:09:42 adam
167 * Zebra config renamed.
168 * Use setting 'recordId' to identify record now.
169 * Bug fix in recindex.c: rec_release_blocks was invokeded even
170 * though the blocks were already released.
171 * File traversal properly deletes records when needed.
173 * Revision 1.21 1995/11/27 14:27:39 adam
174 * Renamed 'update' command to 'dir'.
176 * Revision 1.20 1995/11/27 13:58:53 adam
177 * New option -t. storeStore data implemented in server.
179 * Revision 1.19 1995/11/25 10:24:06 adam
180 * More record fields - they are enumerated now.
181 * New options: flagStoreData flagStoreKey.
183 * Revision 1.18 1995/11/22 17:19:17 adam
184 * Record management uses the bfile system.
186 * Revision 1.17 1995/11/21 15:01:16 adam
187 * New general match criteria implemented.
188 * New feature: document groups.
190 * Revision 1.16 1995/11/20 11:56:27 adam
191 * Work on new traversal.
193 * Revision 1.15 1995/11/01 16:25:51 quinn
194 * *** empty log message ***
196 * Revision 1.14 1995/10/17 18:02:09 adam
197 * New feature: databases. Implemented as prefix to words in dictionary.
199 * Revision 1.13 1995/10/10 12:24:39 adam
200 * Temporary sort files are compressed.
202 * Revision 1.12 1995/10/04 16:57:20 adam
203 * Key input and merge sort in one pass.
205 * Revision 1.11 1995/09/29 14:01:45 adam
208 * Revision 1.10 1995/09/28 14:22:57 adam
209 * Sort uses smaller temporary files.
211 * Revision 1.9 1995/09/14 07:48:24 adam
212 * Record control management.
214 * Revision 1.8 1995/09/06 16:11:18 adam
215 * Option: only one word key per file.
217 * Revision 1.7 1995/09/05 15:28:39 adam
218 * More work on search engine.
220 * Revision 1.6 1995/09/04 12:33:43 adam
221 * Various cleanup. YAZ util used instead.
223 * Revision 1.5 1995/09/04 09:10:39 adam
224 * More work on index add/del/update.
225 * Merge sort implemented.
226 * Initial work on z39 server.
228 * Revision 1.4 1995/09/01 14:06:36 adam
229 * Split of work into more files.
231 * Revision 1.3 1995/09/01 10:57:07 adam
234 * Revision 1.2 1995/09/01 10:30:24 adam
235 * More work on indexing. Not working yet.
237 * Revision 1.1 1995/08/31 14:50:24 adam
238 * New simple file index tool.
251 #include "recindex.h"
258 #include "zebrasdr.h"
263 Res common_resource = 0;
265 int main (int argc, char **argv)
270 char *configName = NULL;
272 int disableCommit = 0;
275 struct recordGroup rGroupDef;
281 rGroupDef.useSDR = 0;
283 rGroupDef.groupName = NULL;
284 rGroupDef.databaseName = NULL;
285 rGroupDef.path = NULL;
286 rGroupDef.recordId = NULL;
287 rGroupDef.recordType = NULL;
288 rGroupDef.flagStoreData = -1;
289 rGroupDef.flagStoreKeys = -1;
290 rGroupDef.flagRw = 1;
291 rGroupDef.databaseNamePath = 0;
292 rGroupDef.explainDatabase = 0;
293 rGroupDef.fileVerboseLimit = 100000;
294 rGroupDef.zebra_maps = NULL;
295 rGroupDef.dh = data1_create ();
296 rGroupDef.recTypes = recTypes_init (rGroupDef.dh);
297 recTypes_default_handlers (rGroupDef.recTypes);
302 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
304 " update <dir> Update index with files below <dir>.\n"
305 " If <dir> is empty filenames are read from stdin.\n"
306 " delete <dir> Delete index with files below <dir>.\n"
307 " commit Commit changes\n"
308 " clean Clean shadow files\n"
310 " -t <type> Index files as <type> (grs or text).\n"
311 " -c <config> Read configuration file <config>.\n"
312 " -g <group> Index files according to group settings.\n"
313 " -d <database> Records belong to Z39.50 database <database>.\n"
314 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
315 " -n Don't use shadow system.\n"
316 " -s Show analysis on stdout, but do no work.\n"
317 " -v <level> Set logging to <level>.\n"
318 " -l <file> Write log to <file>.\n"
319 " -f <n> Display information for the first <n> records.\n"
323 " -V Show version.\n"
327 while ((ret = options ("sVt:c:g:d:m:v:nf:l:"
331 , argv, argc, &arg)) != -2)
336 if(cmd == 0) /* command */
338 if (!common_resource)
340 logf (LOG_LOG, "zebra version %s %s",
341 ZEBRAVER, ZEBRADATE);
342 common_resource = res_open (configName ?
343 configName : FNAME_CONFIG);
344 if (!common_resource)
346 logf (LOG_FATAL, "cannot configuration file `%s'",
350 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
354 bfs_create (res_get (common_resource, "register"));
356 bf_lockDir (rGroupDef.bfs,
357 res_get (common_resource, "lockDir"));
358 rGroupDef.zebra_maps = zebra_maps_open (common_resource);
360 if (!strcmp (arg, "update"))
362 else if (!strcmp (arg, "update1"))
364 else if (!strcmp (arg, "update2"))
366 else if (!strcmp (arg, "dump"))
368 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
370 else if (!strcmp (arg, "commit"))
372 rval = res_get (common_resource, "shadow");
373 zebraIndexLock (rGroupDef.bfs, 1, rval);
375 bf_cache (rGroupDef.bfs, rval);
378 logf (LOG_FATAL, "Cannot perform commit");
379 logf (LOG_FATAL, "No shadow area defined");
382 if (bf_commitExists (rGroupDef.bfs))
384 logf (LOG_LOG, "commit start");
385 zebraIndexLockMsg ("c");
387 logf (LOG_LOG, "commit execute");
388 bf_commitExec (rGroupDef.bfs);
392 zebraIndexLockMsg ("d");
394 logf (LOG_LOG, "commit clean");
395 bf_commitClean (rGroupDef.bfs, rval);
398 logf (LOG_LOG, "cothing to commit");
400 else if (!strcmp (arg, "clean"))
402 rval = res_get (common_resource, "shadow");
403 zebraIndexLock (rGroupDef.bfs, 1, rval);
404 if (bf_commitExists (rGroupDef.bfs))
406 zebraIndexLockMsg ("d");
408 logf (LOG_LOG, "commit clean");
409 bf_commitClean (rGroupDef.bfs, rval);
412 logf (LOG_LOG, "nothing to clean");
414 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
417 rval = res_get (common_resource, "shadow");
418 zebraIndexLock (rGroupDef.bfs, 0, rval);
421 bf_cache (rGroupDef.bfs, rval);
422 zebraIndexLockMsg ("r");
424 records = rec_open (rGroupDef.bfs, 0);
425 rec_prstat (records);
426 rec_close (&records);
427 inv_prstat (rGroupDef.bfs);
429 else if (!strcmp (arg, "compact"))
431 rval = res_get (common_resource, "shadow");
432 zebraIndexLock (rGroupDef.bfs, 0, rval);
435 bf_cache (rGroupDef.bfs, rval);
436 zebraIndexLockMsg ("r");
438 inv_compact(rGroupDef.bfs);
442 logf (LOG_FATAL, "unknown command: %s", arg);
448 struct recordGroup rGroup;
450 rval = res_get (common_resource, "shadow");
451 zebraIndexLock (rGroupDef.bfs, 0, rval);
452 if (rGroupDef.flagRw)
454 if (rval && *rval && !disableCommit)
456 bf_cache (rGroupDef.bfs, rval);
457 zebraIndexLockMsg ("r");
461 bf_cache (rGroupDef.bfs, 0);
462 zebraIndexLockMsg ("w");
466 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
471 if (!key_open (&rGroup, mem_max))
473 logf (LOG_LOG, "updating %s", rGroup.path);
474 repositoryUpdate (&rGroup);
475 nsections = key_close (&rGroup);
479 if (!key_open (&rGroup, mem_max))
481 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
482 repositoryUpdate (&rGroup);
488 if (!key_open (&rGroup,mem_max))
490 logf (LOG_LOG, "deleting %s", rGroup.path);
491 repositoryDelete (&rGroup);
492 nsections = key_close (&rGroup);
496 logf (LOG_LOG, "dumping %s", rGroup.path);
497 repositoryShow (&rGroup);
509 logf (LOG_LOG, "merging with index");
510 key_input (rGroup.bfs, nsections, 60);
515 log_event_end (NULL, NULL);
520 fprintf (stderr, "Zebra %s %s\n",
529 log_init_level (log_mask_str(arg));
533 mem_max = 1024*1024*atoi(arg);
535 rGroupDef.databaseName = arg;
537 rGroupDef.flagRw = 0;
539 rGroupDef.groupName = arg;
541 rGroupDef.fileVerboseLimit = atoi(arg);
545 rGroupDef.recordType = arg;
550 rGroupDef.useSDR = 1;
553 logf (LOG_WARN, "unknown option '-%s'", arg);
555 recTypes_destroy (rGroupDef.recTypes);
559 bfs_destroy (rGroupDef.bfs);
561 data1_destroy (rGroupDef.dh);