Work on new API. Locking system re-implemented
[idzebra-moved-to-github.git] / index / zserver.h
1 /*
2  * Copyright (C) 1994-2002, Index Data 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: zserver.h,v 1.52 2002-02-20 17:30:01 adam Exp $
7  */
8
9 #if HAVE_SYS_TIMES_H
10 #include <sys/times.h>
11 #endif
12
13 #include <yaz/backend.h>
14 #include <rset.h>
15
16 #include <sortidx.h>
17 #include <passwddb.h>
18 #include "index.h"
19 #include "zebraapi.h"
20 #include "zinfo.h"
21
22 YAZ_BEGIN_CDECL
23
24 typedef struct {
25     char *term;
26     char *db;
27     int sysno;
28     int score;
29 } *ZebraPosSet;
30
31 typedef struct zebra_set *ZebraSet;
32
33 typedef struct zebra_rank_class {
34     struct rank_control *control;
35     int init_flag;
36     void *class_handle;
37     struct zebra_rank_class *next;
38 } *ZebraRankClass;
39
40 struct zebra_service {
41     char *configName;
42     struct zebra_session *sessions;
43     ISAMS isams;
44 #if ZMBOL
45     ISAM isam;
46     ISAMC isamc;
47     ISAMD isamd;
48 #endif
49     Dict dict;
50     Dict matchDict;
51     SortIdx sortIdx;
52     int registerState; /* 0 (no commit pages), 1 (use commit pages) */
53     time_t registerChange;
54     BFiles bfs;
55     Records records;
56     ZebraExplainInfo zei;
57     Res res;
58     ZebraLockHandle server_lock_cmt;
59     ZebraLockHandle server_lock_org;
60
61     char *server_path_prefix;
62     data1_handle dh;
63     ZebraMaps zebra_maps;
64     ZebraRankClass rank_classes;
65     RecTypes recTypes;
66     Passwd_db passwd_db;
67     Zebra_mutex_cond session_lock;
68     int stop_flag;
69     int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
70 };
71
72 struct recKeys {
73     int buf_used;
74     int buf_max;
75     char *buf;
76     char prevAttrSet;
77     short prevAttrUse;
78     int prevSeqNo;
79 };
80
81 struct sortKey {
82     char *string;
83     int length;
84     int attrSet;
85     int attrUse;
86     struct sortKey *next;
87 };
88
89 struct zebra_session {
90     struct zebra_session *next;
91     struct zebra_service *service;
92
93     struct recKeys keys;
94     struct sortKey *sortKeys;
95
96     char **key_buf;
97     size_t ptr_top;
98     size_t ptr_i;
99     size_t key_buf_used;
100     int key_file_no;
101     char *admin_databaseName;
102
103     ZebraLockHandle lock_normal;
104     ZebraLockHandle lock_shadow;
105
106     int trans_no;
107     int seqno;
108     int last_val;
109     int destroyed;
110     ZebraSet sets;
111     int errCode;
112     int hits;
113     char *errString;
114 #if HAVE_SYS_TIMES_H
115     struct tms tms1;
116     struct tms tms2;    
117 #endif
118     struct recordGroup rGroup;
119 };
120
121 struct rank_control {
122     char *name;
123     void *(*create)(ZebraService zh);
124     void (*destroy)(ZebraService zh, void *class_handle);
125     void *(*begin)(ZebraHandle zh, void *class_handle, RSET rset);
126     void (*end)(ZebraHandle zh, void *set_handle);
127     int (*calc)(void *set_handle, int sysno);
128     void (*add)(void *set_handle, int seqno, int term_index);
129 };
130
131 struct term_set_entry {
132     char *term;
133     struct term_set_entry *next;
134 };
135
136 struct term_set_list {
137     struct term_set_entry *first;
138     struct term_set_entry *last;
139 };
140
141 RSET rpn_search (ZebraHandle zh, NMEM mem,
142                  Z_RPNQuery *rpn, int num_bases, char **basenames, 
143                  const char *setname, ZebraSet sset);
144
145
146 void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
147                oid_value attributeset,
148                int num_bases, char **basenames,
149                int *position, int *num_entries, ZebraScanEntry **list,
150                int *is_partial);
151
152 RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
153                  const char *term, int length_term, const char *flags);
154
155 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
156                        const char *db, int set,
157                        int use, const char *term);
158 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
159 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
160 ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode,
161                           Z_RPNQuery *rpn, int num_bases, char **basenames,
162                           const char *setname);
163 RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
164 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
165                        int *statuses);
166
167 ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
168                                int num, int *positions);
169 void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
170
171 void resultSetSort (ZebraHandle zh, NMEM nmem,
172                     int num_input_setnames, const char **input_setnames,
173                     const char *output_setname,
174                     Z_SortKeySpecList *sort_sequence, int *sort_status);
175 void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
176                           ZebraSet sset, RSET rset,
177                           Z_SortKeySpecList *sort_sequence, int *sort_status);
178 void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
179 void resultSetInvalidate (ZebraHandle zh);
180
181 void zebra_sort (ZebraHandle zh, ODR stream,
182                  int num_input_setnames, const char **input_setnames,
183                  const char *output_setname, Z_SortKeySpecList *sort_sequence,
184                  int *sort_status);
185
186 int zebra_server_lock_init (ZebraService zh);
187 int zebra_server_lock_destroy (ZebraService zh);
188 int zebra_server_lock (ZebraService zh, int lockCommit);
189 void zebra_server_unlock (ZebraService zh, int commitPhase);
190 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
191
192 typedef struct attent
193 {
194     int attset_ordinal;
195     data1_local_attribute *local_attributes;
196 } attent;
197
198 void zebraRankInstall (ZebraService zh, struct rank_control *ctrl);
199 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
200 void zebraRankDestroy (ZebraService zh);
201
202 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
203
204 extern struct rank_control *rank1_class;
205
206 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
207                         oid_value input_format, Z_RecordComposition *comp,
208                         oid_value *output_format, char **rec_bufp,
209                         int *rec_lenp, char **basenamep);
210
211 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
212 void zebra_index_merge (ZebraHandle zh);
213
214
215 int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
216                         const char *buf, size_t buf_size,
217                         const char *databaseName, int delete_flag,
218                         int test_mode, int *sysno,
219                         int store_keys, int store_data,
220                         const char *match_criteria);
221
222 void extract_flushWriteKeys (ZebraHandle zh);
223
224 struct zebra_fetch_control {
225     off_t offset_end;
226     off_t record_offset;
227     off_t record_int_pos;
228     const char *record_int_buf;
229     int record_int_len;
230     int fd;
231 };
232
233 int zebra_record_ext_read (void *fh, char *buf, size_t count);
234 off_t zebra_record_ext_seek (void *fh, off_t offset);
235 off_t zebra_record_ext_tell (void *fh);
236 off_t zebra_record_int_seek (void *fh, off_t offset);
237 off_t zebra_record_int_tell (void *fh);
238 int zebra_record_int_read (void *fh, char *buf, size_t count);
239 void zebra_record_int_end (void *fh, off_t offset);
240
241 void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
242                               int cmd, struct recKeys *reckeys);
243 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
244                             int cmd, struct sortKey **skp);
245 void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
246 void extract_token_add (RecWord *p);
247 int explain_extract (void *handle, Record rec, data1_node *n);
248
249 YAZ_END_CDECL