Locking based on fcntl instead of flock.
[idzebra-moved-to-github.git] / index / index.h
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: index.h,v $
7  * Revision 1.34  1995-12-11 11:43:29  adam
8  * Locking based on fcntl instead of flock.
9  * Setting commitEnable removed. Command line option -n can be used to
10  * prevent commit if commit setting is defined in the configuration file.
11  *
12  * Revision 1.33  1995/12/08  16:22:53  adam
13  * Work on update while servers are running. Three lock files introduced.
14  * The servers reload their registers when necessary, but they don't
15  * reestablish result sets yet.
16  *
17  * Revision 1.32  1995/12/07  17:38:46  adam
18  * Work locking mechanisms for concurrent updates/commit.
19  *
20  * Revision 1.31  1995/12/06  12:41:22  adam
21  * New command 'stat' for the index program.
22  * Filenames can be read from stdin by specifying '-'.
23  * Bug fix/enhancement of the transformation from terms to regular
24  * expressons in the search engine.
25  *
26  * Revision 1.30  1995/12/05  11:25:02  adam
27  * Include of zebraver.h.
28  *
29  * Revision 1.29  1995/11/28  09:09:40  adam
30  * Zebra config renamed.
31  * Use setting 'recordId' to identify record now.
32  * Bug fix in recindex.c: rec_release_blocks was invokeded even
33  * though the blocks were already released.
34  * File traversal properly deletes records when needed.
35  *
36  * Revision 1.28  1995/11/27  13:58:53  adam
37  * New option -t. storeStore data implemented in server.
38  *
39  * Revision 1.27  1995/11/25  10:24:06  adam
40  * More record fields - they are enumerated now.
41  * New options: flagStoreData flagStoreKey.
42  *
43  * Revision 1.26  1995/11/22  17:19:17  adam
44  * Record management uses the bfile system.
45  *
46  * Revision 1.25  1995/11/21  15:29:12  adam
47  * Config file 'base' read by default by both indexer and server.
48  *
49  * Revision 1.24  1995/11/21  15:01:15  adam
50  * New general match criteria implemented.
51  * New feature: document groups.
52  *
53  * Revision 1.23  1995/11/20  16:59:45  adam
54  * New update method: the 'old' keys are saved for each records.
55  *
56  * Revision 1.22  1995/11/20  11:56:26  adam
57  * Work on new traversal.
58  *
59  * Revision 1.21  1995/11/16  15:34:55  adam
60  * Uses new record management system in both indexer and server.
61  *
62  * Revision 1.20  1995/11/15  14:46:18  adam
63  * Started work on better record management system.
64  *
65  * Revision 1.19  1995/10/27  14:00:11  adam
66  * Implemented detection of database availability.
67  *
68  * Revision 1.18  1995/10/17  18:02:08  adam
69  * New feature: databases. Implemented as prefix to words in dictionary.
70  *
71  * Revision 1.17  1995/10/13  16:01:49  adam
72  * Work on relations.
73  *
74  * Revision 1.16  1995/10/10  12:24:38  adam
75  * Temporary sort files are compressed.
76  *
77  * Revision 1.15  1995/10/04  16:57:19  adam
78  * Key input and merge sort in one pass.
79  *
80  * Revision 1.14  1995/09/29  14:01:40  adam
81  * Bug fixes.
82  *
83  * Revision 1.13  1995/09/28  14:22:56  adam
84  * Sort uses smaller temporary files.
85  *
86  * Revision 1.12  1995/09/28  12:10:32  adam
87  * Bug fixes. Field prefix used in queries.
88  *
89  * Revision 1.11  1995/09/27  12:22:28  adam
90  * More work on extract in record control.
91  * Field name is not in isam keys but in prefix in dictionary words.
92  *
93  * Revision 1.10  1995/09/14  07:48:23  adam
94  * Record control management.
95  *
96  * Revision 1.9  1995/09/11  13:09:33  adam
97  * More work on relevance feedback.
98  *
99  * Revision 1.8  1995/09/08  14:52:27  adam
100  * Minor changes. Dictionary is lower case now.
101  *
102  * Revision 1.7  1995/09/06  16:11:16  adam
103  * Option: only one word key per file.
104  *
105  * Revision 1.6  1995/09/05  15:28:39  adam
106  * More work on search engine.
107  *
108  * Revision 1.5  1995/09/04  12:33:42  adam
109  * Various cleanup. YAZ util used instead.
110  *
111  * Revision 1.4  1995/09/04  09:10:35  adam
112  * More work on index add/del/update.
113  * Merge sort implemented.
114  * Initial work on z39 server.
115  *
116  * Revision 1.3  1995/09/01  14:06:35  adam
117  * Split of work into more files.
118  *
119  * Revision 1.2  1995/09/01  10:30:24  adam
120  * More work on indexing. Not working yet.
121  *
122  * Revision 1.1  1995/08/31  14:50:24  adam
123  * New simple file index tool.
124  *
125  */
126
127 #include <zebraver.h>
128 #include <alexutil.h>
129 #include <dict.h>
130 #include <isam.h>
131
132 #define IT_MAX_WORD 256
133 #define IT_KEY_HAVE_SEQNO 1
134 #define IT_KEY_HAVE_FIELD 0
135
136 struct it_key {
137     int  sysno;
138     int   seqno;
139 };
140
141 enum dirsKind { dirs_dir, dirs_file };
142
143 struct dir_entry {
144     enum dirsKind kind;
145     char *name;
146     int ctime;
147 };
148
149 struct dirs_entry {
150     enum dirsKind kind;
151     char path[256];
152     SYSNO sysno;
153     int ctime;
154 };
155
156 struct recordGroup {
157     char *groupName;
158     char *databaseName;
159     char *path;
160     char *recordId;
161     char *recordType;
162     int  flagStoreData;
163     int  flagStoreKeys;
164 };
165
166         
167 struct dirs_info *dirs_open (Dict dict, const char *rep);
168 struct dirs_entry *dirs_read (struct dirs_info *p);
169 struct dirs_entry *dirs_last (struct dirs_info *p);
170 void dirs_mkdir (struct dirs_info *p, const char *src, int ctime);
171 void dirs_rmdir (struct dirs_info *p, const char *src);
172 void dirs_add (struct dirs_info *p, const char *src, int sysno, int ctime);
173 void dirs_del (struct dirs_info *p, const char *src);
174 void dirs_free (struct dirs_info **pp);
175
176 struct dir_entry *dir_open (const char *rep);
177 void dir_sort (struct dir_entry *e);
178 void dir_free (struct dir_entry **e_p);
179
180 void repositoryUpdate (struct recordGroup *rGroup);
181 void repositoryAdd (struct recordGroup *rGroup);
182 void repositoryDelete (struct recordGroup *rGroup);
183
184 void key_open (int mem);
185 int key_close (void);
186 void key_write (int cmd, struct it_key *k, const char *str);
187 int key_compare (const void *p1, const void *p2);
188 int key_qsort_compare (const void *p1, const void *p2);
189 void key_logdump (int mask, const void *p);
190 void key_input (const char *dict_fname, const char *isam_fname,
191                  int nkeys, int cache);
192 int merge_sort (char **buf, int from, int to);
193
194 #define TEMP_FNAME  "keys%d.tmp"
195 #define FNAME_WORD_DICT "worddict"
196 #define FNAME_WORD_ISAM "wordisam"
197 #define FNAME_CONFIG "zebra.cfg"
198
199 #define GMATCH_DICT "gmatch"
200 #define FMATCH_DICT "fmatch"
201
202 struct strtab *strtab_mk (void);
203 int strtab_src (struct strtab *t, const char *name, void ***infop);
204 void strtab_del (struct strtab *t,
205                  void (*func)(const char *name, void *info, void *data),
206                  void *data);
207 int index_char_cvt (int c);
208 int index_word_prefix (char *string, int attset_ordinal,
209                        int local_attribute, const char *databaseName);
210
211 int fileExtract (SYSNO *sysno, const char *fname,
212                  const struct recordGroup *rGroup, int deleteFlag);
213
214 void rec_prstat (void);
215
216 void zebraLockPrefix (char *pathPrefix);
217
218 void zebraIndexLockMsg (const char *str);
219 void zebraIndexUnlock (void);
220 void zebraIndexLock (int commitNow);
221 int zebraIndexWait (int commitPhase);
222
223 #define FNAME_MAIN_LOCK   "zebraidx.LCK"
224 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
225 #define FNAME_ORG_LOCK    "zebraorg.LCK"
226 #define FNAME_TOUCH_TIME  "zebraidx.time"
227
228 int zebraLock (int fd, int wr);
229 int zebraLockNB (int fd, int wr);
230 int zebraUnlock (int fd);