1libinnhist(3) InterNetNews Documentation libinnhist(3)
2
3
4
6 his - routines for managing INN history
7
9 #include <inn/history.h>
10
11 struct history;
12
13 struct histstats { int hitpos; int hitneg; int misses;
14 int dne; };
15
16 #define HIS_RDONLY ... #define HIS_RDWR ... #define HIS_CREAT ...
17 #define HIS_ONDISK ... #define HIS_INCORE ... #define HIS_MMAP ...
18
19 enum { HISCTLG_PATH, HISCTLS_PATH, HISCTLS_SYNCCOUNT,
20 HISCTLS_NPAIRS, HISCTLS_IGNOREOLD, HISCTLS_STATINTERVAL };
21
22 struct history *HISopen(const char *path, const char *method, int
23 flags);
24
25 bool HISclose(struct history *history);
26
27 bool HISsync(struct history *history);
28
29 void HISsetcache(struct history *history, size_t size);
30
31 bool HISlookup(struct history *history, const char *key, time_t
32 *arrived, time_t *posted, time_t *expires, TOKEN *token);
33
34 bool HIScheck(struct history *history, const char *key);
35
36 bool HISwrite(struct history *history, const char *key, time_t arrived,
37 time_t posted, time_t expires, const TOKEN *token);
38
39 bool HISremember(struct history *history, const char *key, time_t
40 arrived, time_t posted);
41
42 bool HISreplace(struct history *history, const char *key, time_t
43 arrived, time_t posted, time_t expires, const TOKEN *token);
44
45 bool HISexpire(struct history *history, const char *path, const char
46 *reason, bool writing, void *cookie, time_t threshold, bool
47 (*exists)(void *cookie, time_t arrived, time_t posted, time_t expires,
48 const TOKEN *token));
49
50 bool HISwalk(struct history *history, const char *reason, void *cookie,
51 bool (*callback)(void *cookie, time_t arrived, time_t posted, time_t
52 expires, const TOKEN *token));
53
54 struct histstats HISstats(struct history *history);
55
56 const char *HISerror(struct history *history);
57
58 bool HISctl(struct history *history, int request, void *val);
59
61 These functions provide access to the INN history database. They
62 maintain key/value pairs in an opaque database whilst providing for
63 expiry of outdated information.
64
65 The history structure is an opaque handle returned from HISopen.
66
67 The HISopen function opens the history file designated by path using
68 the mode flags using the specified method. flags may be HIS_RDONLY to
69 indicate that read-only access to the history database is desired, or
70 HIS_RDWR for read/write access. History methods are defined at build
71 time; the history method currently available is "hisv6". On success a
72 newly initialised history handle is returned, or NULL on failure.
73
74 HIS_ONDISK, HIS_INCORE and HIS_MMAP may be logically ORed into flags to
75 provide a hint to the underlying history manager as to how it should
76 handle its data files; HIS_ONDISK indicates that the caller would like
77 as much of the data to be kept on disk (and out of memory), HIS_INCORE
78 indicates that the data files should be kept in main memory where
79 possible and HIS_MMAP that the files should be mmap()ed into the
80 processes address space. HIS_INCORE is typically used where a mass
81 rebuild of the history database is being performed; the underlying
82 history manager may assume that the caller will call HISsync() to sync
83 the data files to disk.
84
85 The HIS_CREAT flag indicates that the history database should be
86 initialised as new; if any options which affect creation of the
87 database need to be set an anonymous history handle should be created
88 by calling HISopen with path set to NULL, any options set using HISctl,
89 then the database opened by calling HISctl with HISCTLS_PATH.
90
91 The HISclose function closes the handle history and deallocates any
92 resources associated with it. It returns false on failure or true on
93 success.
94
95 The HISsync function synchronises any outstanding transactions
96 associated with history to disk.
97
98 HISsetcache associates a cache used for speeding up HIScheck with
99 history. The cache will occupy approximately size bytes.
100
101 HISlookup retrieves a token from history based on the passed key
102 (normally the Message-ID). If no entry with an associated token can be
103 found, HISlookup will return false. If a token is found arrived,
104 expires, and posted are filled in with the message arrival, expiry, and
105 posting times respectively (or zero, if the time component is not
106 available), in addition to token being set to the retrieved token and a
107 function return value of true. Any of arrived, expires, posted, or
108 token may be NULL in which case that component is not returned to the
109 caller, without affecting the return value.
110
111 HIScheck checks the database history for key (normally the Message-ID);
112 if key has previously been set via HISwrite, HIScheck returns true,
113 else false.
114
115 HISwrite writes a new entry to the database history associated with
116 key. arrived, posted, and expired specify the arrival, posting, and
117 expiry time respectively; posted and expired may be specifed as <= 0 in
118 which case that component shall be treated as absent in the database.
119 token is associated with the specified key. HISwrite returns true on
120 success, or false on failure. The behaviour when key is not unique with
121 respect to the existing entries in history is unspecified.
122
123 HISremember writes a new entry to the database history associated with
124 key, merely remembering that this key has been seen, together with its
125 arrival time arrived and also its posting time posted, if known.
126 (Otherwise, its posting time may be specified as <= 0 in case it is
127 absent.) HISremember returns true on success, or false on failure.
128 The behaviour when key is not unique with respect to the existing
129 entries in history is unspecified.
130
131 HISreplace replaces an existing entry in the database history,
132 associated with key. arrived, posted, expired specify the arrival,
133 posting and expiry time respectively; posted and expired may be
134 specifed as <= 0 in which case that component shall be treated as
135 absent in the database. token is associated with the specified key; if
136 NULL then the history database merely remembers that this key has been
137 seen, together with its arrival time. HISreplace returns true on
138 success, or false on failure.
139
140 HISexpire expires the history database associated with history,
141 creating a new, replacement, database in the same location if path is
142 NULL, or in path if not NULL; if path is not NULL then the replacement
143 of the old history database with the new one is assumed to be performed
144 out of band by the caller. The writing flag is normally passed as true,
145 if you wish to inhibit writing of the new database (and so merely see
146 the callbacks), writing may be set false.
147
148 If the underlying history mechanism needs to pause the server, the
149 reason string is used as the argument to the `ctlinnd pause' command,
150 and as such the server should be reserved by the caller prior to
151 calling HISexpire; if the caller wishes to inhibit pausing of the
152 server, passing NULL will achieve this. If reason is not NULL, then on
153 successful return from HISexpire the server will be left paused and the
154 caller should unpause it.
155
156 The history database is scanned and entries with an associated storage
157 token are passed to the discrimination function exists.
158
159 If exists() returns false it indicates that stored entity associated
160 with token is no longer available (or no longer required), and
161 therefore the associated history entry may be expired once it meets the
162 threshold constraint. If exists() returns true the entry is kept as-is
163 in the newly expired history database.
164
165 The exists function is passed the arrival, posting and expiry times, in
166 addition to the token associated with the entry. Note that posting
167 and/or expiry may be zero, but that the token will never be NULL (such
168 entries are handled solely via the threshold mechanism). The storage
169 token passed to the discrimination function may be updated if required
170 (for example, as might be needed by a hierachical storage management
171 implementation).
172
173 Entries in the database with a posting time less than threshold with no
174 token associated with them are deleted from the database. In case the
175 posting time is unknown, the arrival time is used instead.
176
177 The parameter cookie is passed to the discrimination function, and may
178 be used for any purpose required by the caller.
179
180 If the discrimination function attempts to access the underlying
181 database (for read or write) during the callback, the behaviour is
182 unspecified.
183
184 HISwalk provides an iteration function for the specified history
185 database. For every entry in the history database, callback is invoked,
186 passing the cookie, arrival, posting, and expiry times, in addition to
187 the token associated with the entry. If the callback() returns false
188 the iteration is aborted and HISwalk returns false to the caller.
189
190 To process the entire database in the presence of a running server,
191 reason may be passed; if this argument is not NULL, it is used as an an
192 argument to the `ctlinnd (reserve|pause|go)' commands. If reason is
193 NULL and the server is running, the behaviour of HISwalk is undefined.
194
195 If the callback function attempts to access the underlying database
196 during the callback, the behaviour is unspecified.
197
198 HISstats returns statistics on the history cache mechanism; given a
199 handle history, the return value is a struct histstats detailing:
200
201 "hitpos"
202 The number of times an item was found directly in the cache and
203 known to exist in the underlying history manager.
204
205 "hitneg"
206 The number of times an item was found directly in the cache and
207 known not to exist in the underlying history manager.
208
209 "misses"
210 The number of times an item was not found directly in the cache,
211 but on retrieval from the underlying history manager was found to
212 exist.
213
214 "dne"
215 The number of times an item was not found directly in the cache,
216 but on retrieval from the underlying history manager was found not
217 to exist.
218
219 Note that the history cache is only checked by HIScheck and only
220 affected by HIScheck, HISwrite, HISremember and HISreplace. Following a
221 call to HISstats the history statistics associated with history are
222 cleared.
223
224 HISerror returns a string describing the most recent error associated
225 with history; the format and content of these strings is history
226 manager dependent. Note that on setting an error, the history API will
227 call the warn function from libinn(3).
228
229 HISctl provides a control interface to the underlying history manager.
230 The request argument determines the type of the request and the meaning
231 of the val argument. The values for request are:
232
233 "HISCTLG_PATH" (const char **)
234 Get the base file path which the history handle represents. val
235 should be a pointer to a location of type const char *. The result
236 must not later be passed to free(3).
237
238 "HISCTLS_PATH" (const char *)
239 Set the base file path which this history handle should use;
240 typically this is used after an anonymous handle has been created
241 using HISopen(NULL, ...). val should be a value of type const char
242 * and will be copied before being stored internally.
243
244 "HISCTLS_SYNCCOUNT" (size_t *)
245 Set an upper bound on how many history operations may be pending in
246 core before being synced to permanent storage; 0 indicates
247 unlimited. val should be a pointer to a value of type size_t and
248 will not be modified by the call.
249
250 "HISCTLS_NPAIRS" (size_t *)
251 Set a hint to the to the underlying history manager as to how many
252 entries there are expected to be in the history database; 0
253 indicates that an automatic or default sizing should be made. val
254 should be a pointer to a value of type size_t and will not be
255 modified by the call.
256
257 "HISCTLS_IGNOREOLD" (bool *)
258 Instruct the underlying history manager to ignore existing database
259 when creating new ones; typically this option may be set to true if
260 the administrator believes that the existing history database is
261 corrupt and that ignoring it may help. val should be a pointer to a
262 value of type bool and will not be modified by the call.
263
264 "HISCTLS_STATINTERVAL" (time_t *)
265 For the history v6 and tagged hash managers, set the interval, in
266 seconds, between stat(2)s of the history files checking for
267 replaced files (as happens during expire); this option is typically
268 used by nnrpd(8) like applications. val should be a pointer to a
269 value of type time_t and will not be modified by the call.
270
272 Written by Alex Kiernan <alexk@demon.net> for InterNetNews 2.4.0.
273
274 $Id: libinnhist.pod 8575 2009-08-18 13:53:54Z iulius $
275
276
277
278INN 2.5.2 2010-08-11 libinnhist(3)