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