Fixed bug: indexer would run forever when lock dir was non-existant.
[idzebra-moved-to-github.git] / index / index.h
1 /*
2  * Copyright (C) 1995-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
5  * (log at the end)
6  */
7 #include <time.h>
8 #include <zebraver.h>
9 #include <zebrautl.h>
10 #include <zebramap.h>
11
12 #include <dict.h>
13 #include <isams.h>
14 #if ZMBOL
15 #include <isam.h>
16 #include <isamc.h>
17 #include <isamd.h>
18 #define ISAM_DEFAULT "c"
19 #else
20 #define ISAM_DEFAULT "s"
21 #endif
22 #include <yaz/data1.h>
23 #include <recctrl.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define IT_MAX_WORD 256
30 #define IT_KEY_HAVE_SEQNO 1
31 #define IT_KEY_HAVE_FIELD 0
32
33 typedef int SYSNO;
34
35 struct it_key {
36     int  sysno;
37     int  seqno;
38 };
39
40 enum dirsKind { dirs_dir, dirs_file };
41
42 struct dir_entry {
43     enum dirsKind kind;
44     char *name;
45     time_t mtime;
46 };
47
48 struct dirs_entry {
49     enum dirsKind kind;
50     char path[256];
51     SYSNO sysno;
52     time_t mtime;
53 };
54
55 struct recordGroup {
56     char         *groupName;
57     char         *databaseName;
58     char         *path;
59     char         *recordId;
60     char         *recordType;
61     int          flagStoreData;
62     int          flagStoreKeys;
63     int          flagRw;
64     int          fileVerboseLimit;
65     int          databaseNamePath;
66     int          explainDatabase;
67 #if ZEBRASDR
68     int          useSDR;
69 #endif
70     data1_handle dh;
71     BFiles       bfs;
72     ZebraMaps    zebra_maps;
73     RecTypes     recTypes;
74 };
75
76 void getFnameTmp (char *fname, int no);
77         
78 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
79 struct dirs_info *dirs_fopen (Dict dict, const char *path);
80 struct dirs_entry *dirs_read (struct dirs_info *p);
81 struct dirs_entry *dirs_last (struct dirs_info *p);
82 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
83 void dirs_rmdir (struct dirs_info *p, const char *src);
84 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime);
85 void dirs_del (struct dirs_info *p, const char *src);
86 void dirs_free (struct dirs_info **pp);
87
88 struct dir_entry *dir_open (const char *rep);
89 void dir_sort (struct dir_entry *e);
90 void dir_free (struct dir_entry **e_p);
91
92 void repositoryUpdate (struct recordGroup *rGroup);
93 void repositoryAdd (struct recordGroup *rGroup);
94 void repositoryDelete (struct recordGroup *rGroup);
95 void repositoryShow (struct recordGroup *rGroup);
96
97 int key_open (struct recordGroup *rGroup, int mem);
98 int key_close (struct recordGroup *group);
99 int key_compare (const void *p1, const void *p2);
100 int key_get_pos (const void *p);
101 int key_compare_it (const void *p1, const void *p2);
102 int key_qsort_compare (const void *p1, const void *p2);
103 void key_logdump (int mask, const void *p);
104 void inv_prstat (BFiles bfs);
105 void inv_compact (BFiles bfs);
106 void key_input (BFiles bfs, int nkeys, int cache);
107 ISAMS_M key_isams_m (Res res, ISAMS_M me);
108 #if ZMBOL
109 ISAMC_M key_isamc_m (Res res, ISAMC_M me);
110 ISAMD_M key_isamd_m (Res res, ISAMD_M me);
111 #endif
112 int merge_sort (char **buf, int from, int to);
113 int key_SU_code (int ch, char *out);
114
115 #define FNAME_DICT "dict"
116 #define FNAME_ISAM "isam"
117 #define FNAME_ISAMC "isamc"
118 #define FNAME_ISAMS "isams"
119 #define FNAME_ISAMH "isamh"
120 #define FNAME_ISAMD "isamd"
121 #define FNAME_CONFIG "zebra.cfg"
122
123 #define GMATCH_DICT "gmatch"
124 #define FMATCH_DICT "fmatch"
125
126 struct strtab *strtab_mk (void);
127 int strtab_src (struct strtab *t, const char *name, void ***infop);
128 void strtab_del (struct strtab *t,
129                  void (*func)(const char *name, void *info, void *data),
130                  void *data);
131 int index_char_cvt (int c);
132 int index_word_prefix (char *string, int attset_ordinal,
133                        int local_attribute, const char *databaseName);
134
135 int fileExtract (SYSNO *sysno, const char *fname,
136                  const struct recordGroup *rGroup, int deleteFlag);
137
138 void zebraIndexLockMsg (const char *str);
139 void zebraIndexUnlock (void);
140 int zebraIndexLock (BFiles bfs, int commitNow, const char *rval);
141 int zebraIndexWait (int commitPhase);
142
143 #define FNAME_MAIN_LOCK   "zebraidx.LCK"
144 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
145 #define FNAME_ORG_LOCK    "zebraorg.LCK"
146 #define FNAME_TOUCH_TIME  "zebraidx.time"
147
148 typedef struct zebra_lock_info *ZebraLockHandle;
149 ZebraLockHandle zebra_lock_create(const char *file, int excl_flag);
150 void zebra_lock_destroy (ZebraLockHandle h);
151 int zebra_lock (ZebraLockHandle h);
152 int zebra_lock_nb (ZebraLockHandle h);
153 int zebra_unlock (ZebraLockHandle h);
154 int zebra_lock_fd (ZebraLockHandle h);
155 void zebra_lock_prefix (Res res, char *dst);
156
157 void zebra_load_atts (data1_handle dh, Res res);
158
159 extern Res common_resource;
160
161 #ifdef __cplusplus
162 }
163 #endif
164
165
166
167 /*
168  * $Log: index.h,v $
169  * Revision 1.68  2000-02-24 11:00:07  adam
170  * Fixed bug: indexer would run forever when lock dir was non-existant.
171  *
172  * Revision 1.67  1999/11/30 13:48:03  adam
173  * Improved installation. Updated for inclusion of YAZ header files.
174  *
175  * Revision 1.66  1999/07/14 13:21:34  heikki
176  * Added isam-d files. Compiles (almost) clean. Doesn't work at all
177  *
178  * Revision 1.65  1999/07/14 10:59:26  adam
179  * Changed functions isc_getmethod, isams_getmethod.
180  * Improved fatal error handling (such as missing EXPLAIN schema).
181  *
182  * Revision 1.64  1999/06/30 15:07:23  heikki
183  * Adding isamh stuff
184  *
185  * Revision 1.63  1999/05/26 07:49:13  adam
186  * C++ compilation.
187  *
188  * Revision 1.62  1999/05/12 13:08:06  adam
189  * First version of ISAMS.
190  *
191  * Revision 1.61  1999/03/09 16:27:49  adam
192  * More work on SDRKit integration.
193  *
194  * Revision 1.60  1998/10/16 08:14:31  adam
195  * Updated record control system.
196  *
197  * Revision 1.59  1998/06/08 14:43:11  adam
198  * Added suport for EXPLAIN Proxy servers - added settings databasePath
199  * and explainDatabase to facilitate this. Increased maximum number
200  * of databases and attributes in one register.
201  *
202  * Revision 1.58  1998/05/20 10:12:16  adam
203  * Implemented automatic EXPLAIN database maintenance.
204  * Modified Zebra to work with ASN.1 compiled version of YAZ.
205  *
206  * Revision 1.57  1998/03/05 08:45:12  adam
207  * New result set model and modular ranking system. Moved towards
208  * descent server API. System information stored as "SGML" records.
209  *
210  * Revision 1.56  1998/01/12 15:04:08  adam
211  * The test option (-s) only uses read-lock (and not write lock).
212  *
213  * Revision 1.55  1997/10/27 14:33:04  adam
214  * Moved towards generic character mapping depending on "structure"
215  * field in abstract syntax file. Fixed a few memory leaks. Fixed
216  * bug with negative integers when doing searches with relational
217  * operators.
218  *
219  * Revision 1.54  1997/09/29 09:08:36  adam
220  * Revised locking system to be thread safe for the server.
221  *
222  * Revision 1.53  1997/09/25 14:54:43  adam
223  * WIN32 files lock support.
224  *
225  * Revision 1.52  1997/09/22 12:39:06  adam
226  * Added get_pos method for the ranked result sets.
227  *
228  * Revision 1.51  1997/09/18 08:59:19  adam
229  * Extra generic handle for the character mapping routines.
230  *
231  * Revision 1.50  1997/09/17 12:19:13  adam
232  * Zebra version corresponds to YAZ version 1.4.
233  * Changed Zebra server so that it doesn't depend on global common_resource.
234  *
235  * Revision 1.49  1997/09/05 15:30:08  adam
236  * Changed prototype for chr_map_input - added const.
237  * Added support for C++, headers uses extern "C" for public definitions.
238  *
239  * Revision 1.48  1997/02/12 20:39:45  adam
240  * Implemented options -f <n> that limits the log to the first <n>
241  * records.
242  * Changed some log messages also.
243  *
244  * Revision 1.47  1996/12/23 15:30:44  adam
245  * Work on truncation.
246  * Bug fix: result sets weren't deleted after server shut down.
247  *
248  * Revision 1.46  1996/11/08 11:10:19  adam
249  * Buffers used during file match got bigger.
250  * Compressed ISAM support everywhere.
251  * Bug fixes regarding masking characters in queries.
252  * Redesigned Regexp-2 queries.
253  *
254  * Revision 1.45  1996/10/29 14:09:42  adam
255  * Use of cisam system - enabled if setting isamc is 1.
256  *
257  * Revision 1.44  1996/06/06 12:08:40  quinn
258  * Added showRecord function
259  *
260  * Revision 1.43  1996/06/04  10:18:12  adam
261  * Search/scan uses character mapping module.
262  *
263  * Revision 1.42  1996/06/04  08:20:16  quinn
264  * Smallish
265  *
266  * Revision 1.41  1996/06/04  07:54:55  quinn
267  * Added output-map.
268  *
269  * Revision 1.40  1996/05/31  09:06:58  quinn
270  * Work on character-set handling
271  *
272  * Revision 1.39  1996/05/14  14:04:33  adam
273  * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
274  * is collected.
275  *
276  * Revision 1.38  1996/04/12  07:02:23  adam
277  * File update of single files.
278  *
279  * Revision 1.37  1996/03/26 16:01:13  adam
280  * New setting lockPath: directory of various lock files.
281  *
282  * Revision 1.36  1996/03/21  14:50:09  adam
283  * File update uses modify-time instead of change-time.
284  *
285  * Revision 1.35  1996/02/12  18:45:36  adam
286  * New fileVerboseFlag in record group control.
287  *
288  * Revision 1.34  1995/12/11  11:43:29  adam
289  * Locking based on fcntl instead of flock.
290  * Setting commitEnable removed. Command line option -n can be used to
291  * prevent commit if commit setting is defined in the configuration file.
292  *
293  * Revision 1.33  1995/12/08  16:22:53  adam
294  * Work on update while servers are running. Three lock files introduced.
295  * The servers reload their registers when necessary, but they don't
296  * reestablish result sets yet.
297  *
298  * Revision 1.32  1995/12/07  17:38:46  adam
299  * Work locking mechanisms for concurrent updates/commit.
300  *
301  * Revision 1.31  1995/12/06  12:41:22  adam
302  * New command 'stat' for the index program.
303  * Filenames can be read from stdin by specifying '-'.
304  * Bug fix/enhancement of the transformation from terms to regular
305  * expressons in the search engine.
306  *
307  * Revision 1.30  1995/12/05  11:25:02  adam
308  * Include of zebraver.h.
309  *
310  * Revision 1.29  1995/11/28  09:09:40  adam
311  * Zebra config renamed.
312  * Use setting 'recordId' to identify record now.
313  * Bug fix in recindex.c: rec_release_blocks was invokeded even
314  * though the blocks were already released.
315  * File traversal properly deletes records when needed.
316  *
317  * Revision 1.28  1995/11/27  13:58:53  adam
318  * New option -t. storeStore data implemented in server.
319  *
320  * Revision 1.27  1995/11/25  10:24:06  adam
321  * More record fields - they are enumerated now.
322  * New options: flagStoreData flagStoreKey.
323  *
324  * Revision 1.26  1995/11/22  17:19:17  adam
325  * Record management uses the bfile system.
326  *
327  * Revision 1.25  1995/11/21  15:29:12  adam
328  * Config file 'base' read by default by both indexer and server.
329  *
330  * Revision 1.24  1995/11/21  15:01:15  adam
331  * New general match criteria implemented.
332  * New feature: document groups.
333  *
334  * Revision 1.23  1995/11/20  16:59:45  adam
335  * New update method: the 'old' keys are saved for each records.
336  *
337  * Revision 1.22  1995/11/20  11:56:26  adam
338  * Work on new traversal.
339  *
340  * Revision 1.21  1995/11/16  15:34:55  adam
341  * Uses new record management system in both indexer and server.
342  *
343  * Revision 1.20  1995/11/15  14:46:18  adam
344  * Started work on better record management system.
345  *
346  * Revision 1.19  1995/10/27  14:00:11  adam
347  * Implemented detection of database availability.
348  *
349  * Revision 1.18  1995/10/17  18:02:08  adam
350  * New feature: databases. Implemented as prefix to words in dictionary.
351  *
352  * Revision 1.17  1995/10/13  16:01:49  adam
353  * Work on relations.
354  *
355  * Revision 1.16  1995/10/10  12:24:38  adam
356  * Temporary sort files are compressed.
357  *
358  * Revision 1.15  1995/10/04  16:57:19  adam
359  * Key input and merge sort in one pass.
360  *
361  * Revision 1.14  1995/09/29  14:01:40  adam
362  * Bug fixes.
363  *
364  * Revision 1.13  1995/09/28  14:22:56  adam
365  * Sort uses smaller temporary files.
366  *
367  * Revision 1.12  1995/09/28  12:10:32  adam
368  * Bug fixes. Field prefix used in queries.
369  *
370  * Revision 1.11  1995/09/27  12:22:28  adam
371  * More work on extract in record control.
372  * Field name is not in isam keys but in prefix in dictionary words.
373  *
374  * Revision 1.10  1995/09/14  07:48:23  adam
375  * Record control management.
376  *
377  * Revision 1.9  1995/09/11  13:09:33  adam
378  * More work on relevance feedback.
379  *
380  * Revision 1.8  1995/09/08  14:52:27  adam
381  * Minor changes. Dictionary is lower case now.
382  *
383  * Revision 1.7  1995/09/06  16:11:16  adam
384  * Option: only one word key per file.
385  *
386  * Revision 1.6  1995/09/05  15:28:39  adam
387  * More work on search engine.
388  *
389  * Revision 1.5  1995/09/04  12:33:42  adam
390  * Various cleanup. YAZ util used instead.
391  *
392  * Revision 1.4  1995/09/04  09:10:35  adam
393  * More work on index add/del/update.
394  * Merge sort implemented.
395  * Initial work on z39 server.
396  *
397  * Revision 1.3  1995/09/01  14:06:35  adam
398  * Split of work into more files.
399  *
400  * Revision 1.2  1995/09/01  10:30:24  adam
401  * More work on indexing. Not working yet.
402  *
403  * Revision 1.1  1995/08/31  14:50:24  adam
404  * New simple file index tool.
405  *
406  */