2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.63 1999-03-09 16:27:49 adam
8 * More work on SDRKit integration.
10 * Revision 1.62 1999/02/18 15:01:24 adam
13 * Revision 1.61 1999/02/02 14:51:00 adam
14 * Updated WIN32 code specific sections. Changed header.
16 * Revision 1.60 1998/10/28 10:54:39 adam
19 * Revision 1.59 1998/10/16 08:14:32 adam
20 * Updated record control system.
22 * Revision 1.58 1998/06/08 14:43:13 adam
23 * Added suport for EXPLAIN Proxy servers - added settings databasePath
24 * and explainDatabase to facilitate this. Increased maximum number
25 * of databases and attributes in one register.
27 * Revision 1.57 1998/05/20 10:12:18 adam
28 * Implemented automatic EXPLAIN database maintenance.
29 * Modified Zebra to work with ASN.1 compiled version of YAZ.
31 * Revision 1.56 1998/03/05 08:45:12 adam
32 * New result set model and modular ranking system. Moved towards
33 * descent server API. System information stored as "SGML" records.
35 * Revision 1.55 1998/01/26 10:37:34 adam
38 * Revision 1.54 1998/01/12 15:04:08 adam
39 * The test option (-s) only uses read-lock (and not write lock).
41 * Revision 1.53 1997/11/18 10:05:08 adam
42 * Changed character map facility so that admin can specify character
43 * mapping files for each register type, w, p, etc.
45 * Revision 1.52 1997/10/31 12:34:04 adam
46 * Added missing nmem_init.
48 * Revision 1.51 1997/10/27 14:33:05 adam
49 * Moved towards generic character mapping depending on "structure"
50 * field in abstract syntax file. Fixed a few memory leaks. Fixed
51 * bug with negative integers when doing searches with relational
54 * Revision 1.50 1997/09/25 14:55:52 adam
57 * Revision 1.49 1997/09/17 12:19:15 adam
58 * Zebra version corresponds to YAZ version 1.4.
59 * Changed Zebra server so that it doesn't depend on global common_resource.
61 * Revision 1.48 1997/09/09 13:38:08 adam
62 * Partial port to WIN95/NT.
64 * Revision 1.47 1997/02/12 20:39:46 adam
65 * Implemented options -f <n> that limits the log to the first <n>
67 * Changed some log messages also.
69 * Revision 1.46 1997/02/10 10:20:13 adam
70 * Flag fileVerboseFlag set to 0 (default).
72 * Revision 1.45 1996/11/08 11:10:26 adam
73 * Buffers used during file match got bigger.
74 * Compressed ISAM support everywhere.
75 * Bug fixes regarding masking characters in queries.
76 * Redesigned Regexp-2 queries.
78 * Revision 1.44 1996/10/29 14:09:48 adam
79 * Use of cisam system - enabled if setting isamc is 1.
81 * Revision 1.43 1996/06/06 12:08:42 quinn
82 * Added showRecord function
84 * Revision 1.42 1996/05/31 09:07:01 quinn
85 * Work on character-set handling
87 * Revision 1.41 1996/05/14 14:04:34 adam
88 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
91 * Revision 1.40 1996/04/26 10:00:23 adam
92 * Added option -V to zebraidx to display version information.
93 * Removed stupid warnings from file update.
95 * Revision 1.39 1996/04/09 10:05:21 adam
96 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
98 * Revision 1.38 1996/03/26 16:01:14 adam
99 * New setting lockPath: directory of various lock files.
101 * Revision 1.37 1996/03/19 12:43:26 adam
102 * Bug fix: File update traversal didn't handle trailing slashes correctly.
103 * Bug fix: Update of sub directory groups wasn't handled correctly.
105 * Revision 1.36 1996/02/12 18:45:37 adam
106 * New fileVerboseFlag in record group control.
108 * Revision 1.35 1996/02/12 15:56:11 adam
109 * New code command: unread.
111 * Revision 1.34 1996/02/07 14:06:39 adam
112 * Better progress report during register merge.
113 * New command: clean - removes temporary shadow files.
115 * Revision 1.33 1996/02/06 17:11:18 adam
118 * Revision 1.32 1996/02/01 20:50:04 adam
119 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
120 * was never called - happens when no commands are specified.
122 * Revision 1.31 1996/01/08 19:15:46 adam
123 * New input filter that works!
125 * Revision 1.30 1995/12/12 16:00:59 adam
126 * System call sync(2) used after update/commit.
127 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
130 * Revision 1.29 1995/12/11 11:43:30 adam
131 * Locking based on fcntl instead of flock.
132 * Setting commitEnable removed. Command line option -n can be used to
133 * prevent commit if commit setting is defined in the configuration file.
135 * Revision 1.28 1995/12/08 16:22:56 adam
136 * Work on update while servers are running. Three lock files introduced.
137 * The servers reload their registers when necessary, but they don't
138 * reestablish result sets yet.
140 * Revision 1.27 1995/12/07 17:38:47 adam
141 * Work locking mechanisms for concurrent updates/commit.
143 * Revision 1.26 1995/12/06 12:41:23 adam
144 * New command 'stat' for the index program.
145 * Filenames can be read from stdin by specifying '-'.
146 * Bug fix/enhancement of the transformation from terms to regular
147 * expressons in the search engine.
149 * Revision 1.25 1995/12/01 16:24:39 adam
150 * Commit files use separate meta file area.
152 * Revision 1.24 1995/11/30 17:01:38 adam
153 * New setting commitCache: points to commit directories/files.
154 * New command commit: commits at the end of a zebraidx run.
156 * Revision 1.23 1995/11/30 08:34:31 adam
157 * Started work on commit facility.
158 * Changed a few malloc/free to xmalloc/xfree.
160 * Revision 1.22 1995/11/28 09:09:42 adam
161 * Zebra config renamed.
162 * Use setting 'recordId' to identify record now.
163 * Bug fix in recindex.c: rec_release_blocks was invokeded even
164 * though the blocks were already released.
165 * File traversal properly deletes records when needed.
167 * Revision 1.21 1995/11/27 14:27:39 adam
168 * Renamed 'update' command to 'dir'.
170 * Revision 1.20 1995/11/27 13:58:53 adam
171 * New option -t. storeStore data implemented in server.
173 * Revision 1.19 1995/11/25 10:24:06 adam
174 * More record fields - they are enumerated now.
175 * New options: flagStoreData flagStoreKey.
177 * Revision 1.18 1995/11/22 17:19:17 adam
178 * Record management uses the bfile system.
180 * Revision 1.17 1995/11/21 15:01:16 adam
181 * New general match criteria implemented.
182 * New feature: document groups.
184 * Revision 1.16 1995/11/20 11:56:27 adam
185 * Work on new traversal.
187 * Revision 1.15 1995/11/01 16:25:51 quinn
188 * *** empty log message ***
190 * Revision 1.14 1995/10/17 18:02:09 adam
191 * New feature: databases. Implemented as prefix to words in dictionary.
193 * Revision 1.13 1995/10/10 12:24:39 adam
194 * Temporary sort files are compressed.
196 * Revision 1.12 1995/10/04 16:57:20 adam
197 * Key input and merge sort in one pass.
199 * Revision 1.11 1995/09/29 14:01:45 adam
202 * Revision 1.10 1995/09/28 14:22:57 adam
203 * Sort uses smaller temporary files.
205 * Revision 1.9 1995/09/14 07:48:24 adam
206 * Record control management.
208 * Revision 1.8 1995/09/06 16:11:18 adam
209 * Option: only one word key per file.
211 * Revision 1.7 1995/09/05 15:28:39 adam
212 * More work on search engine.
214 * Revision 1.6 1995/09/04 12:33:43 adam
215 * Various cleanup. YAZ util used instead.
217 * Revision 1.5 1995/09/04 09:10:39 adam
218 * More work on index add/del/update.
219 * Merge sort implemented.
220 * Initial work on z39 server.
222 * Revision 1.4 1995/09/01 14:06:36 adam
223 * Split of work into more files.
225 * Revision 1.3 1995/09/01 10:57:07 adam
228 * Revision 1.2 1995/09/01 10:30:24 adam
229 * More work on indexing. Not working yet.
231 * Revision 1.1 1995/08/31 14:50:24 adam
232 * New simple file index tool.
245 #include "recindex.h"
252 #include "zebrasdr.h"
257 Res common_resource = 0;
259 int main (int argc, char **argv)
264 char *configName = NULL;
266 int disableCommit = 0;
269 struct recordGroup rGroupDef;
275 rGroupDef.useSDR = 0;
277 rGroupDef.groupName = NULL;
278 rGroupDef.databaseName = NULL;
279 rGroupDef.path = NULL;
280 rGroupDef.recordId = NULL;
281 rGroupDef.recordType = NULL;
282 rGroupDef.flagStoreData = -1;
283 rGroupDef.flagStoreKeys = -1;
284 rGroupDef.flagRw = 1;
285 rGroupDef.databaseNamePath = 0;
286 rGroupDef.explainDatabase = 0;
287 rGroupDef.fileVerboseLimit = 100000;
288 rGroupDef.zebra_maps = NULL;
289 rGroupDef.dh = data1_create ();
290 rGroupDef.recTypes = recTypes_init (rGroupDef.dh);
291 recTypes_default_handlers (rGroupDef.recTypes);
296 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
298 " update <dir> Update index with files below <dir>.\n"
299 " If <dir> is empty filenames are read from stdin.\n"
300 " delete <dir> Delete index with files below <dir>.\n"
301 " commit Commit changes\n"
302 " clean Clean shadow files\n"
304 " -t <type> Index files as <type> (grs or text).\n"
305 " -c <config> Read configuration file <config>.\n"
306 " -g <group> Index files according to group settings.\n"
307 " -d <database> Records belong to Z39.50 database <database>.\n"
308 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
309 " -n Don't use shadow system.\n"
310 " -s Show analysis on stdout, but do no work.\n"
311 " -v <level> Set logging to <level>.\n"
312 " -l <file> Write log to <file>.\n"
313 " -f <n> Display information for the first <n> records.\n"
317 " -V Show version.\n"
321 while ((ret = options ("sVt:c:g:d:m:v:nf:l:"
325 , argv, argc, &arg)) != -2)
330 if(cmd == 0) /* command */
332 if (!common_resource)
334 logf (LOG_LOG, "zebra version %s %s",
335 ZEBRAVER, ZEBRADATE);
336 common_resource = res_open (configName ?
337 configName : FNAME_CONFIG);
338 if (!common_resource)
340 logf (LOG_FATAL, "cannot configuration file `%s'",
344 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
348 bfs_create (res_get (common_resource, "register"));
350 bf_lockDir (rGroupDef.bfs,
351 res_get (common_resource, "lockDir"));
352 rGroupDef.zebra_maps = zebra_maps_open (common_resource);
354 if (!strcmp (arg, "update"))
356 else if (!strcmp (arg, "update1"))
358 else if (!strcmp (arg, "update2"))
360 else if (!strcmp (arg, "dump"))
362 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
364 else if (!strcmp (arg, "commit"))
366 rval = res_get (common_resource, "shadow");
367 zebraIndexLock (rGroupDef.bfs, 1, rval);
369 bf_cache (rGroupDef.bfs, rval);
372 logf (LOG_FATAL, "Cannot perform commit");
373 logf (LOG_FATAL, "No shadow area defined");
376 if (bf_commitExists (rGroupDef.bfs))
378 logf (LOG_LOG, "commit start");
379 zebraIndexLockMsg ("c");
381 logf (LOG_LOG, "commit execute");
382 bf_commitExec (rGroupDef.bfs);
386 zebraIndexLockMsg ("d");
388 logf (LOG_LOG, "commit clean");
389 bf_commitClean (rGroupDef.bfs, rval);
392 logf (LOG_LOG, "cothing to commit");
394 else if (!strcmp (arg, "clean"))
396 rval = res_get (common_resource, "shadow");
397 zebraIndexLock (rGroupDef.bfs, 1, rval);
398 if (bf_commitExists (rGroupDef.bfs))
400 zebraIndexLockMsg ("d");
402 logf (LOG_LOG, "commit clean");
403 bf_commitClean (rGroupDef.bfs, rval);
406 logf (LOG_LOG, "nothing to clean");
408 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
411 rval = res_get (common_resource, "shadow");
412 zebraIndexLock (rGroupDef.bfs, 0, rval);
415 bf_cache (rGroupDef.bfs, rval);
416 zebraIndexLockMsg ("r");
418 records = rec_open (rGroupDef.bfs, 0);
419 rec_prstat (records);
420 rec_close (&records);
421 inv_prstat (rGroupDef.bfs);
423 else if (!strcmp (arg, "compact"))
425 printf ("--------- compact ------\n");
426 rval = res_get (common_resource, "shadow");
427 zebraIndexLock (rGroupDef.bfs, 0, rval);
430 bf_cache (rGroupDef.bfs, rval);
431 zebraIndexLockMsg ("r");
433 inv_compact(rGroupDef.bfs);
437 logf (LOG_FATAL, "unknown command: %s", arg);
443 struct recordGroup rGroup;
445 rval = res_get (common_resource, "shadow");
446 zebraIndexLock (rGroupDef.bfs, 0, rval);
447 if (rGroupDef.flagRw)
449 if (rval && *rval && !disableCommit)
451 bf_cache (rGroupDef.bfs, rval);
452 zebraIndexLockMsg ("r");
456 bf_cache (rGroupDef.bfs, 0);
457 zebraIndexLockMsg ("w");
461 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
466 if (!key_open (&rGroup, mem_max))
468 logf (LOG_LOG, "updating %s", rGroup.path);
469 repositoryUpdate (&rGroup);
470 nsections = key_close (&rGroup);
474 if (!key_open (&rGroup, mem_max))
476 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
477 repositoryUpdate (&rGroup);
483 if (!key_open (&rGroup,mem_max))
485 logf (LOG_LOG, "deleting %s", rGroup.path);
486 repositoryDelete (&rGroup);
487 nsections = key_close (&rGroup);
491 logf (LOG_LOG, "dumping %s", rGroup.path);
492 repositoryShow (&rGroup);
504 logf (LOG_LOG, "merging with index");
505 key_input (rGroup.bfs, nsections, 60);
510 log_event_end (NULL, NULL);
515 fprintf (stderr, "Zebra %s %s\n",
524 log_init_level (log_mask_str(arg));
528 mem_max = 1024*1024*atoi(arg);
530 rGroupDef.databaseName = arg;
532 rGroupDef.flagRw = 0;
534 rGroupDef.groupName = arg;
536 rGroupDef.fileVerboseLimit = atoi(arg);
540 rGroupDef.recordType = arg;
545 rGroupDef.useSDR = 1;
548 logf (LOG_WARN, "unknown option '-%s'", arg);
553 bfs_destroy (rGroupDef.bfs);
555 data1_destroy (rGroupDef.dh);