2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.69 1999-07-21 08:31:33 adam
8 * More version info on WIN32.
10 * Revision 1.68 1999/07/14 10:59:26 adam
11 * Changed functions isc_getmethod, isams_getmethod.
12 * Improved fatal error handling (such as missing EXPLAIN schema).
14 * Revision 1.67 1999/07/06 12:28:04 adam
15 * Updated record index structure. Format includes version ID. Compression
16 * algorithm ID is stored for each record block.
18 * Revision 1.66 1999/06/25 13:48:02 adam
19 * Updated MSVC project files.
20 * Added BZIP2 record compression (not very well tested).
22 * Revision 1.65 1999/05/20 12:57:18 adam
23 * Implemented TCL filter. Updated recctrl system.
25 * Revision 1.64 1999/05/15 14:36:38 adam
26 * Updated dictionary. Implemented "compression" of dictionary.
28 * Revision 1.63 1999/03/09 16:27:49 adam
29 * More work on SDRKit integration.
31 * Revision 1.62 1999/02/18 15:01:24 adam
34 * Revision 1.61 1999/02/02 14:51:00 adam
35 * Updated WIN32 code specific sections. Changed header.
37 * Revision 1.60 1998/10/28 10:54:39 adam
40 * Revision 1.59 1998/10/16 08:14:32 adam
41 * Updated record control system.
43 * Revision 1.58 1998/06/08 14:43:13 adam
44 * Added suport for EXPLAIN Proxy servers - added settings databasePath
45 * and explainDatabase to facilitate this. Increased maximum number
46 * of databases and attributes in one register.
48 * Revision 1.57 1998/05/20 10:12:18 adam
49 * Implemented automatic EXPLAIN database maintenance.
50 * Modified Zebra to work with ASN.1 compiled version of YAZ.
52 * Revision 1.56 1998/03/05 08:45:12 adam
53 * New result set model and modular ranking system. Moved towards
54 * descent server API. System information stored as "SGML" records.
56 * Revision 1.55 1998/01/26 10:37:34 adam
59 * Revision 1.54 1998/01/12 15:04:08 adam
60 * The test option (-s) only uses read-lock (and not write lock).
62 * Revision 1.53 1997/11/18 10:05:08 adam
63 * Changed character map facility so that admin can specify character
64 * mapping files for each register type, w, p, etc.
66 * Revision 1.52 1997/10/31 12:34:04 adam
67 * Added missing nmem_init.
69 * Revision 1.51 1997/10/27 14:33:05 adam
70 * Moved towards generic character mapping depending on "structure"
71 * field in abstract syntax file. Fixed a few memory leaks. Fixed
72 * bug with negative integers when doing searches with relational
75 * Revision 1.50 1997/09/25 14:55:52 adam
78 * Revision 1.49 1997/09/17 12:19:15 adam
79 * Zebra version corresponds to YAZ version 1.4.
80 * Changed Zebra server so that it doesn't depend on global common_resource.
82 * Revision 1.48 1997/09/09 13:38:08 adam
83 * Partial port to WIN95/NT.
85 * Revision 1.47 1997/02/12 20:39:46 adam
86 * Implemented options -f <n> that limits the log to the first <n>
88 * Changed some log messages also.
90 * Revision 1.46 1997/02/10 10:20:13 adam
91 * Flag fileVerboseFlag set to 0 (default).
93 * Revision 1.45 1996/11/08 11:10:26 adam
94 * Buffers used during file match got bigger.
95 * Compressed ISAM support everywhere.
96 * Bug fixes regarding masking characters in queries.
97 * Redesigned Regexp-2 queries.
99 * Revision 1.44 1996/10/29 14:09:48 adam
100 * Use of cisam system - enabled if setting isamc is 1.
102 * Revision 1.43 1996/06/06 12:08:42 quinn
103 * Added showRecord function
105 * Revision 1.42 1996/05/31 09:07:01 quinn
106 * Work on character-set handling
108 * Revision 1.41 1996/05/14 14:04:34 adam
109 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
112 * Revision 1.40 1996/04/26 10:00:23 adam
113 * Added option -V to zebraidx to display version information.
114 * Removed stupid warnings from file update.
116 * Revision 1.39 1996/04/09 10:05:21 adam
117 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
119 * Revision 1.38 1996/03/26 16:01:14 adam
120 * New setting lockPath: directory of various lock files.
122 * Revision 1.37 1996/03/19 12:43:26 adam
123 * Bug fix: File update traversal didn't handle trailing slashes correctly.
124 * Bug fix: Update of sub directory groups wasn't handled correctly.
126 * Revision 1.36 1996/02/12 18:45:37 adam
127 * New fileVerboseFlag in record group control.
129 * Revision 1.35 1996/02/12 15:56:11 adam
130 * New code command: unread.
132 * Revision 1.34 1996/02/07 14:06:39 adam
133 * Better progress report during register merge.
134 * New command: clean - removes temporary shadow files.
136 * Revision 1.33 1996/02/06 17:11:18 adam
139 * Revision 1.32 1996/02/01 20:50:04 adam
140 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
141 * was never called - happens when no commands are specified.
143 * Revision 1.31 1996/01/08 19:15:46 adam
144 * New input filter that works!
146 * Revision 1.30 1995/12/12 16:00:59 adam
147 * System call sync(2) used after update/commit.
148 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
151 * Revision 1.29 1995/12/11 11:43:30 adam
152 * Locking based on fcntl instead of flock.
153 * Setting commitEnable removed. Command line option -n can be used to
154 * prevent commit if commit setting is defined in the configuration file.
156 * Revision 1.28 1995/12/08 16:22:56 adam
157 * Work on update while servers are running. Three lock files introduced.
158 * The servers reload their registers when necessary, but they don't
159 * reestablish result sets yet.
161 * Revision 1.27 1995/12/07 17:38:47 adam
162 * Work locking mechanisms for concurrent updates/commit.
164 * Revision 1.26 1995/12/06 12:41:23 adam
165 * New command 'stat' for the index program.
166 * Filenames can be read from stdin by specifying '-'.
167 * Bug fix/enhancement of the transformation from terms to regular
168 * expressons in the search engine.
170 * Revision 1.25 1995/12/01 16:24:39 adam
171 * Commit files use separate meta file area.
173 * Revision 1.24 1995/11/30 17:01:38 adam
174 * New setting commitCache: points to commit directories/files.
175 * New command commit: commits at the end of a zebraidx run.
177 * Revision 1.23 1995/11/30 08:34:31 adam
178 * Started work on commit facility.
179 * Changed a few malloc/free to xmalloc/xfree.
181 * Revision 1.22 1995/11/28 09:09:42 adam
182 * Zebra config renamed.
183 * Use setting 'recordId' to identify record now.
184 * Bug fix in recindex.c: rec_release_blocks was invokeded even
185 * though the blocks were already released.
186 * File traversal properly deletes records when needed.
188 * Revision 1.21 1995/11/27 14:27:39 adam
189 * Renamed 'update' command to 'dir'.
191 * Revision 1.20 1995/11/27 13:58:53 adam
192 * New option -t. storeStore data implemented in server.
194 * Revision 1.19 1995/11/25 10:24:06 adam
195 * More record fields - they are enumerated now.
196 * New options: flagStoreData flagStoreKey.
198 * Revision 1.18 1995/11/22 17:19:17 adam
199 * Record management uses the bfile system.
201 * Revision 1.17 1995/11/21 15:01:16 adam
202 * New general match criteria implemented.
203 * New feature: document groups.
205 * Revision 1.16 1995/11/20 11:56:27 adam
206 * Work on new traversal.
208 * Revision 1.15 1995/11/01 16:25:51 quinn
209 * *** empty log message ***
211 * Revision 1.14 1995/10/17 18:02:09 adam
212 * New feature: databases. Implemented as prefix to words in dictionary.
214 * Revision 1.13 1995/10/10 12:24:39 adam
215 * Temporary sort files are compressed.
217 * Revision 1.12 1995/10/04 16:57:20 adam
218 * Key input and merge sort in one pass.
220 * Revision 1.11 1995/09/29 14:01:45 adam
223 * Revision 1.10 1995/09/28 14:22:57 adam
224 * Sort uses smaller temporary files.
226 * Revision 1.9 1995/09/14 07:48:24 adam
227 * Record control management.
229 * Revision 1.8 1995/09/06 16:11:18 adam
230 * Option: only one word key per file.
232 * Revision 1.7 1995/09/05 15:28:39 adam
233 * More work on search engine.
235 * Revision 1.6 1995/09/04 12:33:43 adam
236 * Various cleanup. YAZ util used instead.
238 * Revision 1.5 1995/09/04 09:10:39 adam
239 * More work on index add/del/update.
240 * Merge sort implemented.
241 * Initial work on z39 server.
243 * Revision 1.4 1995/09/01 14:06:36 adam
244 * Split of work into more files.
246 * Revision 1.3 1995/09/01 10:57:07 adam
249 * Revision 1.2 1995/09/01 10:30:24 adam
250 * More work on indexing. Not working yet.
252 * Revision 1.1 1995/08/31 14:50:24 adam
253 * New simple file index tool.
266 #include "recindex.h"
273 #include "zebrasdr.h"
278 Res common_resource = 0;
280 int main (int argc, char **argv)
285 char *configName = NULL;
287 int disableCommit = 0;
290 struct recordGroup rGroupDef;
296 rGroupDef.useSDR = 0;
298 rGroupDef.groupName = NULL;
299 rGroupDef.databaseName = NULL;
300 rGroupDef.path = NULL;
301 rGroupDef.recordId = NULL;
302 rGroupDef.recordType = NULL;
303 rGroupDef.flagStoreData = -1;
304 rGroupDef.flagStoreKeys = -1;
305 rGroupDef.flagRw = 1;
306 rGroupDef.databaseNamePath = 0;
307 rGroupDef.explainDatabase = 0;
308 rGroupDef.fileVerboseLimit = 100000;
309 rGroupDef.zebra_maps = NULL;
310 rGroupDef.dh = data1_create ();
311 rGroupDef.recTypes = recTypes_init (rGroupDef.dh);
312 recTypes_default_handlers (rGroupDef.recTypes);
317 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
319 " update <dir> Update index with files below <dir>.\n"
320 " If <dir> is empty filenames are read from stdin.\n"
321 " delete <dir> Delete index with files below <dir>.\n"
322 " commit Commit changes\n"
323 " clean Clean shadow files\n"
325 " -t <type> Index files as <type> (grs or text).\n"
326 " -c <config> Read configuration file <config>.\n"
327 " -g <group> Index files according to group settings.\n"
328 " -d <database> Records belong to Z39.50 database <database>.\n"
329 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
330 " -n Don't use shadow system.\n"
331 " -s Show analysis on stdout, but do no work.\n"
332 " -v <level> Set logging to <level>.\n"
333 " -l <file> Write log to <file>.\n"
334 " -f <n> Display information for the first <n> records.\n"
338 " -V Show version.\n"
342 while ((ret = options ("sVt:c:g:d:m:v:nf:l:"
346 , argv, argc, &arg)) != -2)
351 if(cmd == 0) /* command */
353 if (!common_resource)
355 logf (LOG_LOG, "zebra version %s %s",
356 ZEBRAVER, ZEBRADATE);
357 common_resource = res_open (configName ?
358 configName : FNAME_CONFIG);
359 if (!common_resource)
361 logf (LOG_FATAL, "cannot configuration file `%s'",
365 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
369 bfs_create (res_get (common_resource, "register"));
371 bf_lockDir (rGroupDef.bfs,
372 res_get (common_resource, "lockDir"));
373 rGroupDef.zebra_maps = zebra_maps_open (common_resource);
375 if (!strcmp (arg, "update"))
377 else if (!strcmp (arg, "update1"))
379 else if (!strcmp (arg, "update2"))
381 else if (!strcmp (arg, "dump"))
383 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
385 else if (!strcmp (arg, "commit"))
387 rval = res_get (common_resource, "shadow");
388 zebraIndexLock (rGroupDef.bfs, 1, rval);
390 bf_cache (rGroupDef.bfs, rval);
393 logf (LOG_FATAL, "Cannot perform commit");
394 logf (LOG_FATAL, "No shadow area defined");
397 if (bf_commitExists (rGroupDef.bfs))
399 logf (LOG_LOG, "commit start");
400 zebraIndexLockMsg ("c");
402 logf (LOG_LOG, "commit execute");
403 bf_commitExec (rGroupDef.bfs);
407 zebraIndexLockMsg ("d");
409 logf (LOG_LOG, "commit clean");
410 bf_commitClean (rGroupDef.bfs, rval);
413 logf (LOG_LOG, "cothing to commit");
415 else if (!strcmp (arg, "clean"))
417 rval = res_get (common_resource, "shadow");
418 zebraIndexLock (rGroupDef.bfs, 1, rval);
419 if (bf_commitExists (rGroupDef.bfs))
421 zebraIndexLockMsg ("d");
423 logf (LOG_LOG, "commit clean");
424 bf_commitClean (rGroupDef.bfs, rval);
427 logf (LOG_LOG, "nothing to clean");
429 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
432 rval = res_get (common_resource, "shadow");
433 zebraIndexLock (rGroupDef.bfs, 0, rval);
436 bf_cache (rGroupDef.bfs, rval);
437 zebraIndexLockMsg ("r");
439 records = rec_open (rGroupDef.bfs, 0, 0);
440 rec_prstat (records);
441 rec_close (&records);
442 inv_prstat (rGroupDef.bfs);
444 else if (!strcmp (arg, "compact"))
446 rval = res_get (common_resource, "shadow");
447 zebraIndexLock (rGroupDef.bfs, 0, rval);
450 bf_cache (rGroupDef.bfs, rval);
451 zebraIndexLockMsg ("r");
453 inv_compact(rGroupDef.bfs);
457 logf (LOG_FATAL, "unknown command: %s", arg);
463 struct recordGroup rGroup;
465 rval = res_get (common_resource, "shadow");
466 zebraIndexLock (rGroupDef.bfs, 0, rval);
467 if (rGroupDef.flagRw)
469 if (rval && *rval && !disableCommit)
471 bf_cache (rGroupDef.bfs, rval);
472 zebraIndexLockMsg ("r");
476 bf_cache (rGroupDef.bfs, 0);
477 zebraIndexLockMsg ("w");
481 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
486 if (!key_open (&rGroup, mem_max))
488 logf (LOG_LOG, "updating %s", rGroup.path);
489 repositoryUpdate (&rGroup);
490 nsections = key_close (&rGroup);
494 if (!key_open (&rGroup, mem_max))
496 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
497 repositoryUpdate (&rGroup);
503 if (!key_open (&rGroup,mem_max))
505 logf (LOG_LOG, "deleting %s", rGroup.path);
506 repositoryDelete (&rGroup);
507 nsections = key_close (&rGroup);
511 logf (LOG_LOG, "dumping %s", rGroup.path);
512 repositoryShow (&rGroup);
524 logf (LOG_LOG, "merging with index");
525 key_input (rGroup.bfs, nsections, 60);
530 log_event_end (NULL, NULL);
535 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
536 fprintf (stderr, " (C) 1994-1999, Index Data ApS\n");
539 fprintf (stderr, " WIN32 Debug\n");
541 fprintf (stderr, " WIN32 Release\n");
545 fprintf (stderr, "libbzip2\n"
546 " (C) 1996-1998 Julian R Seward. All rights reserved.\n");
550 log_init_level (log_mask_str(arg));
554 mem_max = 1024*1024*atoi(arg);
556 rGroupDef.databaseName = arg;
558 rGroupDef.flagRw = 0;
560 rGroupDef.groupName = arg;
562 rGroupDef.fileVerboseLimit = atoi(arg);
566 rGroupDef.recordType = arg;
571 rGroupDef.useSDR = 1;
574 logf (LOG_WARN, "unknown option '-%s'", arg);
576 recTypes_destroy (rGroupDef.recTypes);
580 bfs_destroy (rGroupDef.bfs);
582 data1_destroy (rGroupDef.dh);