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