2 * Copyright (C) 1994-1998, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.56 1998-03-05 08:45:12 adam
8 * New result set model and modular ranking system. Moved towards
9 * descent server API. System information stored as "SGML" records.
11 * Revision 1.55 1998/01/26 10:37:34 adam
14 * Revision 1.54 1998/01/12 15:04:08 adam
15 * The test option (-s) only uses read-lock (and not write lock).
17 * Revision 1.53 1997/11/18 10:05:08 adam
18 * Changed character map facility so that admin can specify character
19 * mapping files for each register type, w, p, etc.
21 * Revision 1.52 1997/10/31 12:34:04 adam
22 * Added missing nmem_init.
24 * Revision 1.51 1997/10/27 14:33:05 adam
25 * Moved towards generic character mapping depending on "structure"
26 * field in abstract syntax file. Fixed a few memory leaks. Fixed
27 * bug with negative integers when doing searches with relational
30 * Revision 1.50 1997/09/25 14:55:52 adam
33 * Revision 1.49 1997/09/17 12:19:15 adam
34 * Zebra version corresponds to YAZ version 1.4.
35 * Changed Zebra server so that it doesn't depend on global common_resource.
37 * Revision 1.48 1997/09/09 13:38:08 adam
38 * Partial port to WIN95/NT.
40 * Revision 1.47 1997/02/12 20:39:46 adam
41 * Implemented options -f <n> that limits the log to the first <n>
43 * Changed some log messages also.
45 * Revision 1.46 1997/02/10 10:20:13 adam
46 * Flag fileVerboseFlag set to 0 (default).
48 * Revision 1.45 1996/11/08 11:10:26 adam
49 * Buffers used during file match got bigger.
50 * Compressed ISAM support everywhere.
51 * Bug fixes regarding masking characters in queries.
52 * Redesigned Regexp-2 queries.
54 * Revision 1.44 1996/10/29 14:09:48 adam
55 * Use of cisam system - enabled if setting isamc is 1.
57 * Revision 1.43 1996/06/06 12:08:42 quinn
58 * Added showRecord function
60 * Revision 1.42 1996/05/31 09:07:01 quinn
61 * Work on character-set handling
63 * Revision 1.41 1996/05/14 14:04:34 adam
64 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
67 * Revision 1.40 1996/04/26 10:00:23 adam
68 * Added option -V to zebraidx to display version information.
69 * Removed stupid warnings from file update.
71 * Revision 1.39 1996/04/09 10:05:21 adam
72 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
74 * Revision 1.38 1996/03/26 16:01:14 adam
75 * New setting lockPath: directory of various lock files.
77 * Revision 1.37 1996/03/19 12:43:26 adam
78 * Bug fix: File update traversal didn't handle trailing slashes correctly.
79 * Bug fix: Update of sub directory groups wasn't handled correctly.
81 * Revision 1.36 1996/02/12 18:45:37 adam
82 * New fileVerboseFlag in record group control.
84 * Revision 1.35 1996/02/12 15:56:11 adam
85 * New code command: unread.
87 * Revision 1.34 1996/02/07 14:06:39 adam
88 * Better progress report during register merge.
89 * New command: clean - removes temporary shadow files.
91 * Revision 1.33 1996/02/06 17:11:18 adam
94 * Revision 1.32 1996/02/01 20:50:04 adam
95 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
96 * was never called - happens when no commands are specified.
98 * Revision 1.31 1996/01/08 19:15:46 adam
99 * New input filter that works!
101 * Revision 1.30 1995/12/12 16:00:59 adam
102 * System call sync(2) used after update/commit.
103 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
106 * Revision 1.29 1995/12/11 11:43:30 adam
107 * Locking based on fcntl instead of flock.
108 * Setting commitEnable removed. Command line option -n can be used to
109 * prevent commit if commit setting is defined in the configuration file.
111 * Revision 1.28 1995/12/08 16:22:56 adam
112 * Work on update while servers are running. Three lock files introduced.
113 * The servers reload their registers when necessary, but they don't
114 * reestablish result sets yet.
116 * Revision 1.27 1995/12/07 17:38:47 adam
117 * Work locking mechanisms for concurrent updates/commit.
119 * Revision 1.26 1995/12/06 12:41:23 adam
120 * New command 'stat' for the index program.
121 * Filenames can be read from stdin by specifying '-'.
122 * Bug fix/enhancement of the transformation from terms to regular
123 * expressons in the search engine.
125 * Revision 1.25 1995/12/01 16:24:39 adam
126 * Commit files use separate meta file area.
128 * Revision 1.24 1995/11/30 17:01:38 adam
129 * New setting commitCache: points to commit directories/files.
130 * New command commit: commits at the end of a zebraidx run.
132 * Revision 1.23 1995/11/30 08:34:31 adam
133 * Started work on commit facility.
134 * Changed a few malloc/free to xmalloc/xfree.
136 * Revision 1.22 1995/11/28 09:09:42 adam
137 * Zebra config renamed.
138 * Use setting 'recordId' to identify record now.
139 * Bug fix in recindex.c: rec_release_blocks was invokeded even
140 * though the blocks were already released.
141 * File traversal properly deletes records when needed.
143 * Revision 1.21 1995/11/27 14:27:39 adam
144 * Renamed 'update' command to 'dir'.
146 * Revision 1.20 1995/11/27 13:58:53 adam
147 * New option -t. storeStore data implemented in server.
149 * Revision 1.19 1995/11/25 10:24:06 adam
150 * More record fields - they are enumerated now.
151 * New options: flagStoreData flagStoreKey.
153 * Revision 1.18 1995/11/22 17:19:17 adam
154 * Record management uses the bfile system.
156 * Revision 1.17 1995/11/21 15:01:16 adam
157 * New general match criteria implemented.
158 * New feature: document groups.
160 * Revision 1.16 1995/11/20 11:56:27 adam
161 * Work on new traversal.
163 * Revision 1.15 1995/11/01 16:25:51 quinn
164 * *** empty log message ***
166 * Revision 1.14 1995/10/17 18:02:09 adam
167 * New feature: databases. Implemented as prefix to words in dictionary.
169 * Revision 1.13 1995/10/10 12:24:39 adam
170 * Temporary sort files are compressed.
172 * Revision 1.12 1995/10/04 16:57:20 adam
173 * Key input and merge sort in one pass.
175 * Revision 1.11 1995/09/29 14:01:45 adam
178 * Revision 1.10 1995/09/28 14:22:57 adam
179 * Sort uses smaller temporary files.
181 * Revision 1.9 1995/09/14 07:48:24 adam
182 * Record control management.
184 * Revision 1.8 1995/09/06 16:11:18 adam
185 * Option: only one word key per file.
187 * Revision 1.7 1995/09/05 15:28:39 adam
188 * More work on search engine.
190 * Revision 1.6 1995/09/04 12:33:43 adam
191 * Various cleanup. YAZ util used instead.
193 * Revision 1.5 1995/09/04 09:10:39 adam
194 * More work on index add/del/update.
195 * Merge sort implemented.
196 * Initial work on z39 server.
198 * Revision 1.4 1995/09/01 14:06:36 adam
199 * Split of work into more files.
201 * Revision 1.3 1995/09/01 10:57:07 adam
204 * Revision 1.2 1995/09/01 10:30:24 adam
205 * More work on indexing. Not working yet.
207 * Revision 1.1 1995/08/31 14:50:24 adam
208 * New simple file index tool.
221 #include "recindex.h"
225 Res common_resource = 0;
227 int main (int argc, char **argv)
232 char *configName = NULL;
234 int disableCommit = 0;
237 struct recordGroup rGroupDef;
241 rGroupDef.groupName = NULL;
242 rGroupDef.databaseName = NULL;
243 rGroupDef.path = NULL;
244 rGroupDef.recordId = NULL;
245 rGroupDef.recordType = NULL;
246 rGroupDef.flagStoreData = -1;
247 rGroupDef.flagStoreKeys = -1;
248 rGroupDef.flagRw = 1;
249 rGroupDef.fileVerboseLimit = 100000;
250 rGroupDef.zebra_maps = NULL;
251 rGroupDef.dh = data1_create ();
256 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
258 " update <dir> Update index with files below <dir>.\n"
259 " If <dir> is empty filenames are read from stdin.\n"
260 " delete <dir> Delete index with files below <dir>.\n"
261 " commit Commit changes\n"
262 " clean Clean shadow files\n"
264 " -t <type> Index files as <type> (grs or text).\n"
265 " -c <config> Read configuration file <config>.\n"
266 " -g <group> Index files according to group settings.\n"
267 " -d <database> Records belong to Z39.50 database <database>.\n"
268 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
269 " -n Don't use shadow system.\n"
270 " -s Show analysis on stdout, but do no work.\n"
271 " -v <level> Set logging to <level>.\n"
272 " -f <n> Display information for the first <n> records.\n"
273 " -V Show version.\n"
277 while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2)
282 if(cmd == 0) /* command */
284 if (!common_resource)
286 logf (LOG_LOG, "zebra version %s %s",
287 ZEBRAVER, ZEBRADATE);
288 common_resource = res_open (configName ?
289 configName : FNAME_CONFIG);
290 if (!common_resource)
292 logf (LOG_FATAL, "cannot configuration file `%s'",
296 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
300 bfs_create (res_get (common_resource, "register"));
302 bf_lockDir (rGroupDef.bfs,
303 res_get (common_resource, "lockDir"));
304 rGroupDef.zebra_maps = zebra_maps_open (common_resource);
306 if (!strcmp (arg, "update"))
308 else if (!strcmp (arg, "update1"))
310 else if (!strcmp (arg, "update2"))
312 else if (!strcmp (arg, "dump"))
314 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
316 else if (!strcmp (arg, "commit"))
318 rval = res_get (common_resource, "shadow");
319 zebraIndexLock (rGroupDef.bfs, 1, rval);
321 bf_cache (rGroupDef.bfs, rval);
324 logf (LOG_FATAL, "Cannot perform commit");
325 logf (LOG_FATAL, "No shadow area defined");
328 if (bf_commitExists (rGroupDef.bfs))
330 logf (LOG_LOG, "commit start");
331 zebraIndexLockMsg ("c");
333 logf (LOG_LOG, "commit execute");
334 bf_commitExec (rGroupDef.bfs);
338 zebraIndexLockMsg ("d");
340 logf (LOG_LOG, "commit clean");
341 bf_commitClean (rGroupDef.bfs, rval);
344 logf (LOG_LOG, "cothing to commit");
346 else if (!strcmp (arg, "clean"))
348 rval = res_get (common_resource, "shadow");
349 zebraIndexLock (rGroupDef.bfs, 1, rval);
350 if (bf_commitExists (rGroupDef.bfs))
352 zebraIndexLockMsg ("d");
354 logf (LOG_LOG, "commit clean");
355 bf_commitClean (rGroupDef.bfs, rval);
358 logf (LOG_LOG, "nothing to clean");
360 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
363 rval = res_get (common_resource, "shadow");
364 zebraIndexLock (rGroupDef.bfs, 0, rval);
367 bf_cache (rGroupDef.bfs, rval);
368 zebraIndexLockMsg ("r");
370 records = rec_open (rGroupDef.bfs, 0);
371 rec_prstat (records);
372 rec_close (&records);
373 inv_prstat (rGroupDef.bfs);
377 logf (LOG_FATAL, "unknown command: %s", arg);
383 struct recordGroup rGroup;
385 rval = res_get (common_resource, "shadow");
386 zebraIndexLock (rGroupDef.bfs, 0, rval);
387 if (rGroupDef.flagRw)
389 if (rval && *rval && !disableCommit)
391 bf_cache (rGroupDef.bfs, rval);
392 zebraIndexLockMsg ("r");
396 bf_cache (rGroupDef.bfs, 0);
397 zebraIndexLockMsg ("w");
401 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
406 if (!key_open (rGroup.bfs, mem_max, rGroup.flagRw,
409 logf (LOG_LOG, "updating %s", rGroup.path);
410 repositoryUpdate (&rGroup);
411 nsections = key_close (rGroup.flagRw);
415 if (!key_open (rGroup.bfs,mem_max, rGroup.flagRw,
418 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
419 repositoryUpdate (&rGroup);
420 key_close (rGroup.flagRw);
425 if (!key_open (rGroup.bfs,mem_max, rGroup.flagRw,
428 logf (LOG_LOG, "deleting %s", rGroup.path);
429 repositoryDelete (&rGroup);
430 nsections = key_close (rGroup.flagRw);
434 logf (LOG_LOG, "dumping %s", rGroup.path);
435 repositoryShow (&rGroup);
447 logf (LOG_LOG, "merging with index");
448 key_input (rGroup.bfs, nsections, 60);
453 log_event_end (NULL, NULL);
458 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
461 log_init (log_mask_str(arg), prog, NULL);
463 mem_max = 1024*1024*atoi(arg);
465 rGroupDef.databaseName = arg;
467 rGroupDef.flagRw = 0;
469 rGroupDef.groupName = arg;
471 rGroupDef.fileVerboseLimit = atoi(arg);
475 rGroupDef.recordType = arg;
479 logf (LOG_WARN, "unknown option '-%s'", arg);
484 bfs_destroy (rGroupDef.bfs);
486 data1_destroy (rGroupDef.dh);