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