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