2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.62 1999-02-18 15:01:24 adam
10 * Revision 1.61 1999/02/02 14:51:00 adam
11 * Updated WIN32 code specific sections. Changed header.
13 * Revision 1.60 1998/10/28 10:54:39 adam
16 * Revision 1.59 1998/10/16 08:14:32 adam
17 * Updated record control system.
19 * Revision 1.58 1998/06/08 14:43:13 adam
20 * Added suport for EXPLAIN Proxy servers - added settings databasePath
21 * and explainDatabase to facilitate this. Increased maximum number
22 * of databases and attributes in one register.
24 * Revision 1.57 1998/05/20 10:12:18 adam
25 * Implemented automatic EXPLAIN database maintenance.
26 * Modified Zebra to work with ASN.1 compiled version of YAZ.
28 * Revision 1.56 1998/03/05 08:45:12 adam
29 * New result set model and modular ranking system. Moved towards
30 * descent server API. System information stored as "SGML" records.
32 * Revision 1.55 1998/01/26 10:37:34 adam
35 * Revision 1.54 1998/01/12 15:04:08 adam
36 * The test option (-s) only uses read-lock (and not write lock).
38 * Revision 1.53 1997/11/18 10:05:08 adam
39 * Changed character map facility so that admin can specify character
40 * mapping files for each register type, w, p, etc.
42 * Revision 1.52 1997/10/31 12:34:04 adam
43 * Added missing nmem_init.
45 * Revision 1.51 1997/10/27 14:33:05 adam
46 * Moved towards generic character mapping depending on "structure"
47 * field in abstract syntax file. Fixed a few memory leaks. Fixed
48 * bug with negative integers when doing searches with relational
51 * Revision 1.50 1997/09/25 14:55:52 adam
54 * Revision 1.49 1997/09/17 12:19:15 adam
55 * Zebra version corresponds to YAZ version 1.4.
56 * Changed Zebra server so that it doesn't depend on global common_resource.
58 * Revision 1.48 1997/09/09 13:38:08 adam
59 * Partial port to WIN95/NT.
61 * Revision 1.47 1997/02/12 20:39:46 adam
62 * Implemented options -f <n> that limits the log to the first <n>
64 * Changed some log messages also.
66 * Revision 1.46 1997/02/10 10:20:13 adam
67 * Flag fileVerboseFlag set to 0 (default).
69 * Revision 1.45 1996/11/08 11:10:26 adam
70 * Buffers used during file match got bigger.
71 * Compressed ISAM support everywhere.
72 * Bug fixes regarding masking characters in queries.
73 * Redesigned Regexp-2 queries.
75 * Revision 1.44 1996/10/29 14:09:48 adam
76 * Use of cisam system - enabled if setting isamc is 1.
78 * Revision 1.43 1996/06/06 12:08:42 quinn
79 * Added showRecord function
81 * Revision 1.42 1996/05/31 09:07:01 quinn
82 * Work on character-set handling
84 * Revision 1.41 1996/05/14 14:04:34 adam
85 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
88 * Revision 1.40 1996/04/26 10:00:23 adam
89 * Added option -V to zebraidx to display version information.
90 * Removed stupid warnings from file update.
92 * Revision 1.39 1996/04/09 10:05:21 adam
93 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
95 * Revision 1.38 1996/03/26 16:01:14 adam
96 * New setting lockPath: directory of various lock files.
98 * Revision 1.37 1996/03/19 12:43:26 adam
99 * Bug fix: File update traversal didn't handle trailing slashes correctly.
100 * Bug fix: Update of sub directory groups wasn't handled correctly.
102 * Revision 1.36 1996/02/12 18:45:37 adam
103 * New fileVerboseFlag in record group control.
105 * Revision 1.35 1996/02/12 15:56:11 adam
106 * New code command: unread.
108 * Revision 1.34 1996/02/07 14:06:39 adam
109 * Better progress report during register merge.
110 * New command: clean - removes temporary shadow files.
112 * Revision 1.33 1996/02/06 17:11:18 adam
115 * Revision 1.32 1996/02/01 20:50:04 adam
116 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
117 * was never called - happens when no commands are specified.
119 * Revision 1.31 1996/01/08 19:15:46 adam
120 * New input filter that works!
122 * Revision 1.30 1995/12/12 16:00:59 adam
123 * System call sync(2) used after update/commit.
124 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
127 * Revision 1.29 1995/12/11 11:43:30 adam
128 * Locking based on fcntl instead of flock.
129 * Setting commitEnable removed. Command line option -n can be used to
130 * prevent commit if commit setting is defined in the configuration file.
132 * Revision 1.28 1995/12/08 16:22:56 adam
133 * Work on update while servers are running. Three lock files introduced.
134 * The servers reload their registers when necessary, but they don't
135 * reestablish result sets yet.
137 * Revision 1.27 1995/12/07 17:38:47 adam
138 * Work locking mechanisms for concurrent updates/commit.
140 * Revision 1.26 1995/12/06 12:41:23 adam
141 * New command 'stat' for the index program.
142 * Filenames can be read from stdin by specifying '-'.
143 * Bug fix/enhancement of the transformation from terms to regular
144 * expressons in the search engine.
146 * Revision 1.25 1995/12/01 16:24:39 adam
147 * Commit files use separate meta file area.
149 * Revision 1.24 1995/11/30 17:01:38 adam
150 * New setting commitCache: points to commit directories/files.
151 * New command commit: commits at the end of a zebraidx run.
153 * Revision 1.23 1995/11/30 08:34:31 adam
154 * Started work on commit facility.
155 * Changed a few malloc/free to xmalloc/xfree.
157 * Revision 1.22 1995/11/28 09:09:42 adam
158 * Zebra config renamed.
159 * Use setting 'recordId' to identify record now.
160 * Bug fix in recindex.c: rec_release_blocks was invokeded even
161 * though the blocks were already released.
162 * File traversal properly deletes records when needed.
164 * Revision 1.21 1995/11/27 14:27:39 adam
165 * Renamed 'update' command to 'dir'.
167 * Revision 1.20 1995/11/27 13:58:53 adam
168 * New option -t. storeStore data implemented in server.
170 * Revision 1.19 1995/11/25 10:24:06 adam
171 * More record fields - they are enumerated now.
172 * New options: flagStoreData flagStoreKey.
174 * Revision 1.18 1995/11/22 17:19:17 adam
175 * Record management uses the bfile system.
177 * Revision 1.17 1995/11/21 15:01:16 adam
178 * New general match criteria implemented.
179 * New feature: document groups.
181 * Revision 1.16 1995/11/20 11:56:27 adam
182 * Work on new traversal.
184 * Revision 1.15 1995/11/01 16:25:51 quinn
185 * *** empty log message ***
187 * Revision 1.14 1995/10/17 18:02:09 adam
188 * New feature: databases. Implemented as prefix to words in dictionary.
190 * Revision 1.13 1995/10/10 12:24:39 adam
191 * Temporary sort files are compressed.
193 * Revision 1.12 1995/10/04 16:57:20 adam
194 * Key input and merge sort in one pass.
196 * Revision 1.11 1995/09/29 14:01:45 adam
199 * Revision 1.10 1995/09/28 14:22:57 adam
200 * Sort uses smaller temporary files.
202 * Revision 1.9 1995/09/14 07:48:24 adam
203 * Record control management.
205 * Revision 1.8 1995/09/06 16:11:18 adam
206 * Option: only one word key per file.
208 * Revision 1.7 1995/09/05 15:28:39 adam
209 * More work on search engine.
211 * Revision 1.6 1995/09/04 12:33:43 adam
212 * Various cleanup. YAZ util used instead.
214 * Revision 1.5 1995/09/04 09:10:39 adam
215 * More work on index add/del/update.
216 * Merge sort implemented.
217 * Initial work on z39 server.
219 * Revision 1.4 1995/09/01 14:06:36 adam
220 * Split of work into more files.
222 * Revision 1.3 1995/09/01 10:57:07 adam
225 * Revision 1.2 1995/09/01 10:30:24 adam
226 * More work on indexing. Not working yet.
228 * Revision 1.1 1995/08/31 14:50:24 adam
229 * New simple file index tool.
242 #include "recindex.h"
249 #include "zebrasdr.h"
254 Res common_resource = 0;
256 int main (int argc, char **argv)
261 char *configName = NULL;
263 int disableCommit = 0;
266 struct recordGroup rGroupDef;
273 rGroupDef.groupName = NULL;
274 rGroupDef.databaseName = NULL;
275 rGroupDef.path = NULL;
276 rGroupDef.recordId = NULL;
277 rGroupDef.recordType = NULL;
278 rGroupDef.flagStoreData = -1;
279 rGroupDef.flagStoreKeys = -1;
280 rGroupDef.flagRw = 1;
281 rGroupDef.databaseNamePath = 0;
282 rGroupDef.explainDatabase = 0;
283 rGroupDef.fileVerboseLimit = 100000;
284 rGroupDef.zebra_maps = NULL;
285 rGroupDef.dh = data1_create ();
286 rGroupDef.recTypes = recTypes_init (rGroupDef.dh);
287 recTypes_default_handlers (rGroupDef.recTypes);
292 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
294 " update <dir> Update index with files below <dir>.\n"
295 " If <dir> is empty filenames are read from stdin.\n"
296 " delete <dir> Delete index with files below <dir>.\n"
297 " commit Commit changes\n"
298 " clean Clean shadow files\n"
300 " -t <type> Index files as <type> (grs or text).\n"
301 " -c <config> Read configuration file <config>.\n"
302 " -g <group> Index files according to group settings.\n"
303 " -d <database> Records belong to Z39.50 database <database>.\n"
304 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
305 " -n Don't use shadow system.\n"
306 " -s Show analysis on stdout, but do no work.\n"
307 " -v <level> Set logging to <level>.\n"
308 " -l <file> Write log to <file>.\n"
309 " -f <n> Display information for the first <n> records.\n"
310 " -V Show version.\n"
314 while ((ret = options ("sVt:c:g:d:m:v:nf:l:", argv, argc, &arg)) != -2)
319 if(cmd == 0) /* command */
321 if (!common_resource)
323 logf (LOG_LOG, "zebra version %s %s",
324 ZEBRAVER, ZEBRADATE);
325 common_resource = res_open (configName ?
326 configName : FNAME_CONFIG);
327 if (!common_resource)
329 logf (LOG_FATAL, "cannot configuration file `%s'",
333 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
337 bfs_create (res_get (common_resource, "register"));
339 bf_lockDir (rGroupDef.bfs,
340 res_get (common_resource, "lockDir"));
341 rGroupDef.zebra_maps = zebra_maps_open (common_resource);
343 if (!strcmp (arg, "update"))
345 else if (!strcmp (arg, "update1"))
347 else if (!strcmp (arg, "update2"))
349 else if (!strcmp (arg, "dump"))
351 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
353 else if (!strcmp (arg, "commit"))
355 rval = res_get (common_resource, "shadow");
356 zebraIndexLock (rGroupDef.bfs, 1, rval);
358 bf_cache (rGroupDef.bfs, rval);
361 logf (LOG_FATAL, "Cannot perform commit");
362 logf (LOG_FATAL, "No shadow area defined");
365 if (bf_commitExists (rGroupDef.bfs))
367 logf (LOG_LOG, "commit start");
368 zebraIndexLockMsg ("c");
370 logf (LOG_LOG, "commit execute");
371 bf_commitExec (rGroupDef.bfs);
375 zebraIndexLockMsg ("d");
377 logf (LOG_LOG, "commit clean");
378 bf_commitClean (rGroupDef.bfs, rval);
381 logf (LOG_LOG, "cothing to commit");
383 else if (!strcmp (arg, "clean"))
385 rval = res_get (common_resource, "shadow");
386 zebraIndexLock (rGroupDef.bfs, 1, rval);
387 if (bf_commitExists (rGroupDef.bfs))
389 zebraIndexLockMsg ("d");
391 logf (LOG_LOG, "commit clean");
392 bf_commitClean (rGroupDef.bfs, rval);
395 logf (LOG_LOG, "nothing to clean");
397 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
400 rval = res_get (common_resource, "shadow");
401 zebraIndexLock (rGroupDef.bfs, 0, rval);
404 bf_cache (rGroupDef.bfs, rval);
405 zebraIndexLockMsg ("r");
407 records = rec_open (rGroupDef.bfs, 0);
408 rec_prstat (records);
409 rec_close (&records);
410 inv_prstat (rGroupDef.bfs);
414 logf (LOG_FATAL, "unknown command: %s", arg);
420 struct recordGroup rGroup;
422 rval = res_get (common_resource, "shadow");
423 zebraIndexLock (rGroupDef.bfs, 0, rval);
424 if (rGroupDef.flagRw)
426 if (rval && *rval && !disableCommit)
428 bf_cache (rGroupDef.bfs, rval);
429 zebraIndexLockMsg ("r");
433 bf_cache (rGroupDef.bfs, 0);
434 zebraIndexLockMsg ("w");
438 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
443 if (!key_open (&rGroup, mem_max))
445 logf (LOG_LOG, "updating %s", rGroup.path);
446 repositoryUpdate (&rGroup);
447 nsections = key_close (&rGroup);
451 if (!key_open (&rGroup, mem_max))
453 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
454 repositoryUpdate (&rGroup);
460 if (!key_open (&rGroup,mem_max))
462 logf (LOG_LOG, "deleting %s", rGroup.path);
463 repositoryDelete (&rGroup);
464 nsections = key_close (&rGroup);
468 logf (LOG_LOG, "dumping %s", rGroup.path);
469 repositoryShow (&rGroup);
481 logf (LOG_LOG, "merging with index");
482 key_input (rGroup.bfs, nsections, 60);
487 log_event_end (NULL, NULL);
492 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
495 log_init_level (log_mask_str(arg));
499 mem_max = 1024*1024*atoi(arg);
501 rGroupDef.databaseName = arg;
503 rGroupDef.flagRw = 0;
505 rGroupDef.groupName = arg;
507 rGroupDef.fileVerboseLimit = atoi(arg);
511 rGroupDef.recordType = arg;
515 logf (LOG_WARN, "unknown option '-%s'", arg);
520 bfs_destroy (rGroupDef.bfs);
522 data1_destroy (rGroupDef.dh);