2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.34 1996-02-07 14:06:39 adam
8 * Better progress report during register merge.
9 * New command: clean - removes temporary shadow files.
11 * Revision 1.33 1996/02/06 17:11:18 adam
14 * Revision 1.32 1996/02/01 20:50:04 adam
15 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
16 * was never called - happens when no commands are specified.
18 * Revision 1.31 1996/01/08 19:15:46 adam
19 * New input filter that works!
21 * Revision 1.30 1995/12/12 16:00:59 adam
22 * System call sync(2) used after update/commit.
23 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
26 * Revision 1.29 1995/12/11 11:43:30 adam
27 * Locking based on fcntl instead of flock.
28 * Setting commitEnable removed. Command line option -n can be used to
29 * prevent commit if commit setting is defined in the configuration file.
31 * Revision 1.28 1995/12/08 16:22:56 adam
32 * Work on update while servers are running. Three lock files introduced.
33 * The servers reload their registers when necessary, but they don't
34 * reestablish result sets yet.
36 * Revision 1.27 1995/12/07 17:38:47 adam
37 * Work locking mechanisms for concurrent updates/commit.
39 * Revision 1.26 1995/12/06 12:41:23 adam
40 * New command 'stat' for the index program.
41 * Filenames can be read from stdin by specifying '-'.
42 * Bug fix/enhancement of the transformation from terms to regular
43 * expressons in the search engine.
45 * Revision 1.25 1995/12/01 16:24:39 adam
46 * Commit files use separate meta file area.
48 * Revision 1.24 1995/11/30 17:01:38 adam
49 * New setting commitCache: points to commit directories/files.
50 * New command commit: commits at the end of a zebraidx run.
52 * Revision 1.23 1995/11/30 08:34:31 adam
53 * Started work on commit facility.
54 * Changed a few malloc/free to xmalloc/xfree.
56 * Revision 1.22 1995/11/28 09:09:42 adam
57 * Zebra config renamed.
58 * Use setting 'recordId' to identify record now.
59 * Bug fix in recindex.c: rec_release_blocks was invokeded even
60 * though the blocks were already released.
61 * File traversal properly deletes records when needed.
63 * Revision 1.21 1995/11/27 14:27:39 adam
64 * Renamed 'update' command to 'dir'.
66 * Revision 1.20 1995/11/27 13:58:53 adam
67 * New option -t. storeStore data implemented in server.
69 * Revision 1.19 1995/11/25 10:24:06 adam
70 * More record fields - they are enumerated now.
71 * New options: flagStoreData flagStoreKey.
73 * Revision 1.18 1995/11/22 17:19:17 adam
74 * Record management uses the bfile system.
76 * Revision 1.17 1995/11/21 15:01:16 adam
77 * New general match criteria implemented.
78 * New feature: document groups.
80 * Revision 1.16 1995/11/20 11:56:27 adam
81 * Work on new traversal.
83 * Revision 1.15 1995/11/01 16:25:51 quinn
84 * *** empty log message ***
86 * Revision 1.14 1995/10/17 18:02:09 adam
87 * New feature: databases. Implemented as prefix to words in dictionary.
89 * Revision 1.13 1995/10/10 12:24:39 adam
90 * Temporary sort files are compressed.
92 * Revision 1.12 1995/10/04 16:57:20 adam
93 * Key input and merge sort in one pass.
95 * Revision 1.11 1995/09/29 14:01:45 adam
98 * Revision 1.10 1995/09/28 14:22:57 adam
99 * Sort uses smaller temporary files.
101 * Revision 1.9 1995/09/14 07:48:24 adam
102 * Record control management.
104 * Revision 1.8 1995/09/06 16:11:18 adam
105 * Option: only one word key per file.
107 * Revision 1.7 1995/09/05 15:28:39 adam
108 * More work on search engine.
110 * Revision 1.6 1995/09/04 12:33:43 adam
111 * Various cleanup. YAZ util used instead.
113 * Revision 1.5 1995/09/04 09:10:39 adam
114 * More work on index add/del/update.
115 * Merge sort implemented.
116 * Initial work on z39 server.
118 * Revision 1.4 1995/09/01 14:06:36 adam
119 * Split of work into more files.
121 * Revision 1.3 1995/09/01 10:57:07 adam
124 * Revision 1.2 1995/09/01 10:30:24 adam
125 * More work on indexing. Not working yet.
127 * Revision 1.1 1995/08/31 14:50:24 adam
128 * New simple file index tool.
135 #include <alexutil.h>
140 size_t mem_max = 4*1024*1024;
141 extern char *data1_tabpath;
143 static void abort_func (int level, const char *msg, void *info)
145 if (level & LOG_FATAL)
149 int main (int argc, char **argv)
154 char *configName = NULL;
156 int disableCommit = 0;
158 struct recordGroup rGroupDef;
160 rGroupDef.groupName = NULL;
161 rGroupDef.databaseName = NULL;
162 rGroupDef.path = NULL;
163 rGroupDef.recordId = NULL;
164 rGroupDef.recordType = NULL;
165 rGroupDef.flagStoreData = -1;
166 rGroupDef.flagStoreKeys = -1;
171 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
173 " update <dir> Update index with files below <dir>.\n"
174 " If <dir> is empty filenames are read from stdin.\n"
175 " delete <dir> Delete index with files below <dir>.\n"
176 " commit Commit changes\n"
177 " clean Clean shadow files\n"
179 " -t <type> Index files as <type> (grs or text).\n"
180 " -c <config> Read configuration file <config>.\n"
181 " -g <group> Index files according to group settings.\n"
182 " -d <database> Records belong to Z39.50 database <database>.\n"
183 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
184 " -n Don't use shadow system\n"
185 " -v <level> Set logging to <level>.\n");
188 log_event_end (abort_func, NULL);
189 while ((ret = options ("t:c:g:d:m:v:n", argv, argc, &arg)) != -2)
194 if(cmd == 0) /* command */
196 if (!common_resource)
198 common_resource = res_open (configName ?
199 configName : FNAME_CONFIG);
200 if (!common_resource)
202 logf (LOG_FATAL, "Cannot open resource `%s'",
206 data1_tabpath = res_get (common_resource, "profilePath");
208 if (!strcmp (arg, "update"))
210 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
212 else if (!strcmp (arg, "commit"))
215 rval = res_get (common_resource, "shadow");
220 logf (LOG_FATAL, "Cannot perform commit");
221 logf (LOG_FATAL, "No shadow area defined");
224 if (bf_commitExists ())
226 logf (LOG_LOG, "Commit start");
227 zebraIndexLockMsg ("c");
229 logf (LOG_LOG, "Commit execute");
232 zebraIndexLockMsg ("d");
234 logf (LOG_LOG, "Commit clean");
238 logf (LOG_LOG, "Nothing to commit");
240 else if (!strcmp (arg, "clean"))
243 if (bf_commitExists ())
245 zebraIndexLockMsg ("d");
247 logf (LOG_LOG, "Commit clean");
251 logf (LOG_LOG, "Nothing to clean");
253 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
256 rval = res_get (common_resource, "shadow");
260 zebraIndexLockMsg ("r");
266 logf (LOG_FATAL, "Unknown command: %s", arg);
272 struct recordGroup rGroup;
275 rval = res_get (common_resource, "shadow");
276 if (rval && *rval && !disableCommit)
279 zebraIndexLockMsg ("r");
284 zebraIndexLockMsg ("w");
288 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
293 logf (LOG_LOG, "Updating %s", rGroup.path);
294 repositoryUpdate (&rGroup);
298 logf (LOG_LOG, "Deleting %s", rGroup.path);
299 repositoryDelete (&rGroup);
302 nsections = key_close ();
305 logf (LOG_LOG, "Merging with index");
306 key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections,
314 log_init (log_mask_str(arg), prog, NULL);
318 mem_max = 1024*1024*atoi(arg);
322 rGroupDef.databaseName = arg;
326 rGroupDef.groupName = arg;
331 rGroupDef.recordType = arg;
336 logf (LOG_FATAL, "Unknown option '-%s'", arg);