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