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