2b25cdf4216702e3c318192a542361965716fa63
[idzebra-moved-to-github.git] / index / zserver.h
1 /*
2  * Copyright (C) 1994-1997, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: zserver.h,v $
7  * Revision 1.27  1997-10-27 14:33:06  adam
8  * Moved towards generic character mapping depending on "structure"
9  * field in abstract syntax file. Fixed a few memory leaks. Fixed
10  * bug with negative integers when doing searches with relational
11  * operators.
12  *
13  * Revision 1.26  1997/09/29 12:41:35  adam
14  * Fixed bug regarding USE_TIMES var.
15  *
16  * Revision 1.25  1997/09/29 09:08:36  adam
17  * Revised locking system to be thread safe for the server.
18  *
19  * Revision 1.24  1997/09/17 12:19:19  adam
20  * Zebra version corresponds to YAZ version 1.4.
21  * Changed Zebra server so that it doesn't depend on global common_resource.
22  *
23  * Revision 1.23  1996/12/23 15:30:46  adam
24  * Work on truncation.
25  * Bug fix: result sets weren't deleted after server shut down.
26  *
27  * Revision 1.22  1996/11/04 14:07:49  adam
28  * Moved truncation code to trunc.c.
29  *
30  * Revision 1.21  1996/10/29 14:09:58  adam
31  * Use of cisam system - enabled if setting isamc is 1.
32  *
33  * Revision 1.20  1996/06/04 10:19:02  adam
34  * Minor changes - removed include of ctype.h.
35  *
36  * Revision 1.19  1996/05/14  11:34:01  adam
37  * Scan support in multiple registers/databases.
38  *
39  * Revision 1.18  1996/05/14  06:16:50  adam
40  * Compact use/set bytes used in search service.
41  *
42  * Revision 1.17  1995/12/08 16:22:57  adam
43  * Work on update while servers are running. Three lock files introduced.
44  * The servers reload their registers when necessary, but they don't
45  * reestablish result sets yet.
46  *
47  * Revision 1.16  1995/12/07  17:38:48  adam
48  * Work locking mechanisms for concurrent updates/commit.
49  *
50  * Revision 1.15  1995/11/21  15:29:13  adam
51  * Config file 'base' read by default by both indexer and server.
52  *
53  * Revision 1.14  1995/11/16  17:00:57  adam
54  * Better logging of rpn query.
55  *
56  * Revision 1.13  1995/11/16  15:34:56  adam
57  * Uses new record management system in both indexer and server.
58  *
59  * Revision 1.12  1995/10/27  14:00:12  adam
60  * Implemented detection of database availability.
61  *
62  * Revision 1.11  1995/10/17  18:02:12  adam
63  * New feature: databases. Implemented as prefix to words in dictionary.
64  *
65  * Revision 1.10  1995/10/09  16:18:38  adam
66  * Function dict_lookup_grep got extra client data parameter.
67  *
68  * Revision 1.9  1995/10/06  14:38:01  adam
69  * New result set method: r_score.
70  * Local no (sysno) and score is transferred to retrieveCtrl.
71  *
72  * Revision 1.8  1995/10/06  13:52:06  adam
73  * Bug fixes. Handler may abort further scanning.
74  *
75  * Revision 1.7  1995/10/06  10:43:57  adam
76  * Scan added. 'occurrences' in scan entries not set yet.
77  *
78  * Revision 1.6  1995/09/28  09:19:48  adam
79  * xfree/xmalloc used everywhere.
80  * Extract/retrieve method seems to work for text records.
81  *
82  * Revision 1.5  1995/09/27  16:17:32  adam
83  * More work on retrieve.
84  *
85  * Revision 1.4  1995/09/14  11:53:28  adam
86  * First work on regular expressions/truncations.
87  *
88  * Revision 1.3  1995/09/08  08:53:23  adam
89  * Record buffer maintained in server_info.
90  *
91  * Revision 1.2  1995/09/06  16:11:19  adam
92  * Option: only one word key per file.
93  *
94  * Revision 1.1  1995/09/05  15:28:40  adam
95  * More work on search engine.
96  *
97  */
98
99
100 #ifndef USE_TIMES
101 #ifdef __linux__
102 #define USE_TIMES 1
103 #else
104 #define USE_TIMES 0
105 #endif
106 #endif
107
108 #if USE_TIMES
109 #include <sys/times.h>
110 #endif
111
112 #include <backend.h>
113 #include <rset.h>
114
115 #include "index.h"
116 #include "zinfo.h"
117
118 typedef struct {
119     int sysno;
120     int score;
121 } ZServerSetSysno;
122
123 typedef struct ZServerSet_ {
124     char *name;
125     RSET rset;
126     int size;
127     struct ZServerSet_ *next;
128 } ZServerSet;
129    
130 typedef struct {
131     int registerState; /* 0 (no commit pages), 1 (use commit pages) */
132     time_t registerChange;
133     ZServerSet *sets;
134     Dict dict;
135     ISAM isam;
136     ISAMC isamc;
137     Records records;
138     int errCode;
139     char *errString;
140     ODR odr;
141     ZebTargetInfo *zti;
142     data1_handle dh;
143     data1_attset *registered_sets;
144     BFiles bfs;
145     Res res;
146
147     ZebraLockHandle server_lock_cmt;
148     ZebraLockHandle server_lock_org;
149     char *server_path_prefix;
150 #if USE_TIMES
151     struct tms tms1;
152     struct tms tms2;    
153 #endif
154     ZebraMaps zebra_maps;
155 } ZServerInfo;
156
157 int rpn_search (ZServerInfo *zi, 
158                 Z_RPNQuery *rpn, int num_bases, char **basenames, 
159                 const char *setname, int *hits);
160
161 int rpn_scan (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
162               oid_value attributeset,
163               int num_bases, char **basenames,
164               int *position, int *num_entries, struct scan_entry **list,
165               int *status);
166
167 RSET rset_trunc (ZServerInfo *zi, ISAM_P *isam_p, int no);
168
169 ZServerSet *resultSetAdd (ZServerInfo *zi, const char *name,
170                           int ov, RSET rset);
171 ZServerSet *resultSetGet (ZServerInfo *zi, const char *name);
172 void resultSetDestroy (ZServerInfo *zi);
173
174 ZServerSetSysno *resultSetSysnoGet (ZServerInfo *zi, const char *name,
175                                     int num, int *positions);
176 void resultSetSysnoDel (ZServerInfo *zi, ZServerSetSysno *records, int num);
177 void zlog_rpn (Z_RPNQuery *rpn);
178
179 int zebra_server_lock_init (ZServerInfo *zi);
180 int zebra_server_lock_destroy (ZServerInfo *zi);
181 int zebra_server_lock (ZServerInfo *zi, int lockCommit);
182 void zebra_server_unlock (ZServerInfo *zi, int commitPhase);
183 int zebra_server_lock_get_state (ZServerInfo *zi, time_t *timep);
184
185 typedef struct attent
186 {
187     int attset_ordinal;
188     data1_local_attribute *local_attributes;
189 } attent;
190
191 int att_getentbyatt(ZServerInfo *zi, attent *res, oid_value set, int att);