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