2 * Copyright (C) 1994-1998, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.54 1998-01-12 15:04:08 adam
8 * The test option (-s) only uses read-lock (and not write lock).
10 * Revision 1.53 1997/11/18 10:05:08 adam
11 * Changed character map facility so that admin can specify character
12 * mapping files for each register type, w, p, etc.
14 * Revision 1.52 1997/10/31 12:34:04 adam
15 * Added missing nmem_init.
17 * Revision 1.51 1997/10/27 14:33:05 adam
18 * Moved towards generic character mapping depending on "structure"
19 * field in abstract syntax file. Fixed a few memory leaks. Fixed
20 * bug with negative integers when doing searches with relational
23 * Revision 1.50 1997/09/25 14:55:52 adam
26 * Revision 1.49 1997/09/17 12:19:15 adam
27 * Zebra version corresponds to YAZ version 1.4.
28 * Changed Zebra server so that it doesn't depend on global common_resource.
30 * Revision 1.48 1997/09/09 13:38:08 adam
31 * Partial port to WIN95/NT.
33 * Revision 1.47 1997/02/12 20:39:46 adam
34 * Implemented options -f <n> that limits the log to the first <n>
36 * Changed some log messages also.
38 * Revision 1.46 1997/02/10 10:20:13 adam
39 * Flag fileVerboseFlag set to 0 (default).
41 * Revision 1.45 1996/11/08 11:10:26 adam
42 * Buffers used during file match got bigger.
43 * Compressed ISAM support everywhere.
44 * Bug fixes regarding masking characters in queries.
45 * Redesigned Regexp-2 queries.
47 * Revision 1.44 1996/10/29 14:09:48 adam
48 * Use of cisam system - enabled if setting isamc is 1.
50 * Revision 1.43 1996/06/06 12:08:42 quinn
51 * Added showRecord function
53 * Revision 1.42 1996/05/31 09:07:01 quinn
54 * Work on character-set handling
56 * Revision 1.41 1996/05/14 14:04:34 adam
57 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
60 * Revision 1.40 1996/04/26 10:00:23 adam
61 * Added option -V to zebraidx to display version information.
62 * Removed stupid warnings from file update.
64 * Revision 1.39 1996/04/09 10:05:21 adam
65 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
67 * Revision 1.38 1996/03/26 16:01:14 adam
68 * New setting lockPath: directory of various lock files.
70 * Revision 1.37 1996/03/19 12:43:26 adam
71 * Bug fix: File update traversal didn't handle trailing slashes correctly.
72 * Bug fix: Update of sub directory groups wasn't handled correctly.
74 * Revision 1.36 1996/02/12 18:45:37 adam
75 * New fileVerboseFlag in record group control.
77 * Revision 1.35 1996/02/12 15:56:11 adam
78 * New code command: unread.
80 * Revision 1.34 1996/02/07 14:06:39 adam
81 * Better progress report during register merge.
82 * New command: clean - removes temporary shadow files.
84 * Revision 1.33 1996/02/06 17:11:18 adam
87 * Revision 1.32 1996/02/01 20:50:04 adam
88 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
89 * was never called - happens when no commands are specified.
91 * Revision 1.31 1996/01/08 19:15:46 adam
92 * New input filter that works!
94 * Revision 1.30 1995/12/12 16:00:59 adam
95 * System call sync(2) used after update/commit.
96 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
99 * Revision 1.29 1995/12/11 11:43:30 adam
100 * Locking based on fcntl instead of flock.
101 * Setting commitEnable removed. Command line option -n can be used to
102 * prevent commit if commit setting is defined in the configuration file.
104 * Revision 1.28 1995/12/08 16:22:56 adam
105 * Work on update while servers are running. Three lock files introduced.
106 * The servers reload their registers when necessary, but they don't
107 * reestablish result sets yet.
109 * Revision 1.27 1995/12/07 17:38:47 adam
110 * Work locking mechanisms for concurrent updates/commit.
112 * Revision 1.26 1995/12/06 12:41:23 adam
113 * New command 'stat' for the index program.
114 * Filenames can be read from stdin by specifying '-'.
115 * Bug fix/enhancement of the transformation from terms to regular
116 * expressons in the search engine.
118 * Revision 1.25 1995/12/01 16:24:39 adam
119 * Commit files use separate meta file area.
121 * Revision 1.24 1995/11/30 17:01:38 adam
122 * New setting commitCache: points to commit directories/files.
123 * New command commit: commits at the end of a zebraidx run.
125 * Revision 1.23 1995/11/30 08:34:31 adam
126 * Started work on commit facility.
127 * Changed a few malloc/free to xmalloc/xfree.
129 * Revision 1.22 1995/11/28 09:09:42 adam
130 * Zebra config renamed.
131 * Use setting 'recordId' to identify record now.
132 * Bug fix in recindex.c: rec_release_blocks was invokeded even
133 * though the blocks were already released.
134 * File traversal properly deletes records when needed.
136 * Revision 1.21 1995/11/27 14:27:39 adam
137 * Renamed 'update' command to 'dir'.
139 * Revision 1.20 1995/11/27 13:58:53 adam
140 * New option -t. storeStore data implemented in server.
142 * Revision 1.19 1995/11/25 10:24:06 adam
143 * More record fields - they are enumerated now.
144 * New options: flagStoreData flagStoreKey.
146 * Revision 1.18 1995/11/22 17:19:17 adam
147 * Record management uses the bfile system.
149 * Revision 1.17 1995/11/21 15:01:16 adam
150 * New general match criteria implemented.
151 * New feature: document groups.
153 * Revision 1.16 1995/11/20 11:56:27 adam
154 * Work on new traversal.
156 * Revision 1.15 1995/11/01 16:25:51 quinn
157 * *** empty log message ***
159 * Revision 1.14 1995/10/17 18:02:09 adam
160 * New feature: databases. Implemented as prefix to words in dictionary.
162 * Revision 1.13 1995/10/10 12:24:39 adam
163 * Temporary sort files are compressed.
165 * Revision 1.12 1995/10/04 16:57:20 adam
166 * Key input and merge sort in one pass.
168 * Revision 1.11 1995/09/29 14:01:45 adam
171 * Revision 1.10 1995/09/28 14:22:57 adam
172 * Sort uses smaller temporary files.
174 * Revision 1.9 1995/09/14 07:48:24 adam
175 * Record control management.
177 * Revision 1.8 1995/09/06 16:11:18 adam
178 * Option: only one word key per file.
180 * Revision 1.7 1995/09/05 15:28:39 adam
181 * More work on search engine.
183 * Revision 1.6 1995/09/04 12:33:43 adam
184 * Various cleanup. YAZ util used instead.
186 * Revision 1.5 1995/09/04 09:10:39 adam
187 * More work on index add/del/update.
188 * Merge sort implemented.
189 * Initial work on z39 server.
191 * Revision 1.4 1995/09/01 14:06:36 adam
192 * Split of work into more files.
194 * Revision 1.3 1995/09/01 10:57:07 adam
197 * Revision 1.2 1995/09/01 10:30:24 adam
198 * More work on indexing. Not working yet.
200 * Revision 1.1 1995/08/31 14:50:24 adam
201 * New simple file index tool.
214 #include "recindex.h"
218 Res common_resource = 0;
220 int main (int argc, char **argv)
225 char *configName = NULL;
227 int disableCommit = 0;
230 struct recordGroup rGroupDef;
234 rGroupDef.groupName = NULL;
235 rGroupDef.databaseName = NULL;
236 rGroupDef.path = NULL;
237 rGroupDef.recordId = NULL;
238 rGroupDef.recordType = NULL;
239 rGroupDef.flagStoreData = -1;
240 rGroupDef.flagStoreKeys = -1;
241 rGroupDef.flagRw = 1;
242 rGroupDef.fileVerboseLimit = 100000;
243 rGroupDef.zebra_maps = NULL;
244 rGroupDef.dh = data1_create ();
249 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
251 " update <dir> Update index with files below <dir>.\n"
252 " If <dir> is empty filenames are read from stdin.\n"
253 " delete <dir> Delete index with files below <dir>.\n"
254 " commit Commit changes\n"
255 " clean Clean shadow files\n"
257 " -t <type> Index files as <type> (grs or text).\n"
258 " -c <config> Read configuration file <config>.\n"
259 " -g <group> Index files according to group settings.\n"
260 " -d <database> Records belong to Z39.50 database <database>.\n"
261 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
262 " -n Don't use shadow system.\n"
263 " -s Show analysis on stdout, but do no work.\n"
264 " -v <level> Set logging to <level>.\n"
265 " -f <n> Display information for the first <n> records.\n"
266 " -V Show version.\n"
270 while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2)
275 if(cmd == 0) /* command */
277 if (!common_resource)
279 logf (LOG_LOG, "zebra version %s %s",
280 ZEBRAVER, ZEBRADATE);
281 common_resource = res_open (configName ?
282 configName : FNAME_CONFIG);
283 if (!common_resource)
285 logf (LOG_FATAL, "cannot configuration file `%s'",
289 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
293 bfs_create (res_get (common_resource, "register"));
295 bf_lockDir (rGroupDef.bfs,
296 res_get (common_resource, "lockDir"));
297 rGroupDef.zebra_maps = zebra_maps_open (res_get(
298 common_resource, "profilePath"), common_resource);
300 if (!strcmp (arg, "update"))
302 else if (!strcmp (arg, "update1"))
304 else if (!strcmp (arg, "update2"))
306 else if (!strcmp (arg, "dump"))
308 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
310 else if (!strcmp (arg, "commit"))
312 rval = res_get (common_resource, "shadow");
313 zebraIndexLock (rGroupDef.bfs, 1, rval);
315 bf_cache (rGroupDef.bfs, rval);
318 logf (LOG_FATAL, "Cannot perform commit");
319 logf (LOG_FATAL, "No shadow area defined");
322 if (bf_commitExists (rGroupDef.bfs))
324 logf (LOG_LOG, "commit start");
325 zebraIndexLockMsg ("c");
327 logf (LOG_LOG, "commit execute");
328 bf_commitExec (rGroupDef.bfs);
332 zebraIndexLockMsg ("d");
334 logf (LOG_LOG, "commit clean");
335 bf_commitClean (rGroupDef.bfs, rval);
338 logf (LOG_LOG, "cothing to commit");
340 else if (!strcmp (arg, "clean"))
342 rval = res_get (common_resource, "shadow");
343 zebraIndexLock (rGroupDef.bfs, 1, rval);
344 if (bf_commitExists (rGroupDef.bfs))
346 zebraIndexLockMsg ("d");
348 logf (LOG_LOG, "commit clean");
349 bf_commitClean (rGroupDef.bfs, rval);
352 logf (LOG_LOG, "nothing to clean");
354 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
357 rval = res_get (common_resource, "shadow");
358 zebraIndexLock (rGroupDef.bfs, 0, rval);
361 bf_cache (rGroupDef.bfs, rval);
362 zebraIndexLockMsg ("r");
364 records = rec_open (rGroupDef.bfs, 0);
365 rec_prstat (records);
366 rec_close (&records);
367 inv_prstat (rGroupDef.bfs);
371 logf (LOG_FATAL, "unknown command: %s", arg);
377 struct recordGroup rGroup;
379 log_event_end (abort_func, NULL);
380 rval = res_get (common_resource, "shadow");
381 zebraIndexLock (rGroupDef.bfs, 0, rval);
382 if (rGroupDef.flagRw)
384 if (rval && *rval && !disableCommit)
386 bf_cache (rGroupDef.bfs, rval);
387 zebraIndexLockMsg ("r");
391 bf_cache (rGroupDef.bfs, 0);
392 zebraIndexLockMsg ("w");
396 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
401 if (!key_open (rGroup.bfs, mem_max, rGroup.flagRw))
403 logf (LOG_LOG, "updating %s", rGroup.path);
404 repositoryUpdate (&rGroup);
405 nsections = key_close ();
409 if (!key_open (rGroup.bfs,mem_max, rGroup.flagRw))
411 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
412 repositoryUpdate (&rGroup);
418 if (!key_open (rGroup.bfs,mem_max, rGroup.flagRw))
420 logf (LOG_LOG, "deleting %s", rGroup.path);
421 repositoryDelete (&rGroup);
422 nsections = key_close ();
426 logf (LOG_LOG, "dumping %s", rGroup.path);
427 repositoryShow (&rGroup);
439 logf (LOG_LOG, "merging with index");
440 key_input (rGroup.bfs, nsections, 60);
445 log_event_end (NULL, NULL);
450 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
453 log_init (log_mask_str(arg), prog, NULL);
455 mem_max = 1024*1024*atoi(arg);
457 rGroupDef.databaseName = arg;
459 rGroupDef.flagRw = 0;
461 rGroupDef.groupName = arg;
463 rGroupDef.fileVerboseLimit = atoi(arg);
467 rGroupDef.recordType = arg;
471 logf (LOG_WARN, "unknown option '-%s'", arg);
476 bfs_destroy (rGroupDef.bfs);
478 data1_destroy (rGroupDef.dh);