]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/nextid.c
Move the input data exhaustion loop to connection.c from daemon.c
[openldap] / servers / slapd / back-bdb2 / nextid.c
1 /* id.c - keep track of the next id to be given out */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8
9 #ifdef HAVE_SYS_PARAM_H
10 #include <sys/param.h>
11 #endif
12
13 #include "slap.h"
14 #include "back-bdb2.h"
15
16 /*  reading and writing NEXTID is handled in txn.c  */
17 #define next_id_read(be)  bdb2i_get_nextid( (be) )
18 #define next_id_write(be,id)  bdb2i_put_nextid( (be), (id) )
19
20
21 int
22 bdb2i_next_id_save( BackendDB *be )
23 {
24         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
25         ID id = bdb2i_next_id_get( be );
26         int rc;
27
28         rc = next_id_write( be, id );
29         if (rc == 0) {
30                 li->li_nextid_wrote = id;
31         }
32
33         return rc;
34 }
35
36 ID
37 bdb2i_next_id( BackendDB *be )
38 {
39         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
40         ID              id;
41
42         /* first time in here since startup - try to read the nexid */
43         if ( li->li_nextid == NOID ) {
44                 li->li_nextid = next_id_read( be );
45
46                 if ( li->li_nextid == NOID ) {
47                         li->li_nextid = 1;
48                 }
49
50 #if SLAPD_NEXTID_CHUNK > 1
51                 li->li_nextid_wrote = li->li_nextid;
52 #endif
53         }
54
55         id = li->li_nextid++;
56
57 #if SLAPD_NEXTID_CHUNK > 1
58         if ( li->li_nextid > li->li_nextid_wrote ) {
59                 li->li_nextid_wrote += SLAPD_NEXTID_CHUNK;
60                 (void) next_id_write( be, li->li_nextid_wrote );
61         }
62 #else
63         (void) next_id_write( be, li->li_nextid );
64 #endif
65
66         return( id );
67 }
68
69 void
70 bdb2i_next_id_return( BackendDB *be, ID id )
71 {
72 #ifdef SLAPD_NEXTID_RETURN
73         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
74
75         if ( id != li->li_nextid - 1 ) {
76                 return;
77         }
78
79         li->li_nextid--;
80
81 #if !( SLAPD_NEXTID_CHUNK > 1 )
82         (void) next_id_write( be, li->li_nextid );
83 #endif
84 #endif
85 }
86
87 ID
88 bdb2i_next_id_get( BackendDB *be )
89 {
90         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
91         ID              id;
92
93         /* first time in here since startup - try to read the nexid */
94         if ( li->li_nextid == NOID ) {
95                 li->li_nextid = next_id_read( be );
96
97                 if ( li->li_nextid == NOID ) {
98                         li->li_nextid = 1;
99                 }
100
101 #if SLAPD_NEXTID_CHUNK > 1
102                 li->li_nextid_wrote = li->li_nextid;
103 #endif
104         }
105
106         id = li->li_nextid;
107
108         return( id );
109 }