9397
|
1 |
diff -u -r1.66.2.3 -r1.66.2.9
|
|
2 |
--- servers/slapd/back-ldbm/idl.c 28 Jul 2002 19:16:17 -0000 1.66.2.3
|
|
3 |
+++ servers/slapd/back-ldbm/idl.c 13 Mar 2003 03:35:27 -0000 1.66.2.9
|
|
4 |
@@ -48,17 +48,29 @@
|
|
5 |
#ifdef LDBM_DEBUG_IDL
|
|
6 |
static void idl_check(ID_BLOCK *idl)
|
|
7 |
{
|
|
8 |
- int i;
|
|
9 |
+ int i, max;
|
|
10 |
ID_BLOCK last;
|
|
11 |
|
|
12 |
- if( ID_BLOCK_INDIRECT(idl) || ID_BLOCK_ALLIDS(idl)
|
|
13 |
- || ID_BLOCK_NIDS(idl) <= 1 )
|
|
14 |
+ if( ID_BLOCK_ALLIDS(idl) )
|
|
15 |
+ {
|
|
16 |
+ return;
|
|
17 |
+ }
|
|
18 |
+#ifndef USE_INDIRECT_NIDS
|
|
19 |
+ if( ID_BLOCK_INDIRECT(idl) )
|
|
20 |
+ {
|
|
21 |
+ for ( max = 0; !ID_BLOCK_NOID(idl, max); max++ ) ;
|
|
22 |
+ } else
|
|
23 |
+#endif
|
|
24 |
+ {
|
|
25 |
+ max = ID_BLOCK_NIDS(idl);
|
|
26 |
+ }
|
|
27 |
+ if ( max <= 1 )
|
|
28 |
{
|
|
29 |
return;
|
|
30 |
}
|
|
31 |
|
|
32 |
for( last = ID_BLOCK_ID(idl, 0), i = 1;
|
|
33 |
- i < ID_BLOCK_NIDS(idl);
|
|
34 |
+ i < max;
|
|
35 |
last = ID_BLOCK_ID(idl, i), i++ )
|
|
36 |
{
|
|
37 |
assert (last < ID_BLOCK_ID(idl, i) );
|
|
38 |
@@ -170,8 +182,7 @@
|
|
39 |
Datum data;
|
|
40 |
ID_BLOCK *idl;
|
|
41 |
ID_BLOCK **tmp;
|
|
42 |
- int nids;
|
|
43 |
- unsigned i;
|
|
44 |
+ unsigned i, nids, nblocks;
|
|
45 |
|
|
46 |
idl = idl_fetch_one( be, db, key );
|
|
47 |
|
|
48 |
@@ -197,21 +208,17 @@
|
|
49 |
|
|
50 |
#ifndef USE_INDIRECT_NIDS
|
|
51 |
/* count the number of blocks & allocate space for pointers to them */
|
|
52 |
- for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ )
|
|
53 |
+ for ( nblocks = 0; !ID_BLOCK_NOID(idl, nblocks); nblocks++ )
|
|
54 |
; /* NULL */
|
|
55 |
#else
|
|
56 |
- i = ID_BLOCK_NIDS(idl);
|
|
57 |
+ nblocks = ID_BLOCK_NIDS(idl);
|
|
58 |
#endif
|
|
59 |
- tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) );
|
|
60 |
+ tmp = (ID_BLOCK **) ch_malloc( nblocks * sizeof(ID_BLOCK *) );
|
|
61 |
|
|
62 |
/* read in all the blocks */
|
|
63 |
cont_alloc( &data, &key );
|
|
64 |
nids = 0;
|
|
65 |
-#ifndef USE_INDIRECT_NIDS
|
|
66 |
- for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
|
|
67 |
-#else
|
|
68 |
- for ( i = 0; i < ID_BLOCK_NIDS(idl); i++ ) {
|
|
69 |
-#endif
|
|
70 |
+ for ( i = 0; i < nblocks; i++ ) {
|
|
71 |
cont_id( &data, ID_BLOCK_ID(idl, i) );
|
|
72 |
|
|
73 |
if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
|
|
74 |
@@ -228,7 +235,6 @@
|
|
75 |
|
|
76 |
nids += ID_BLOCK_NIDS(tmp[i]);
|
|
77 |
}
|
|
78 |
- tmp[i] = NULL;
|
|
79 |
cont_free( &data );
|
|
80 |
idl_free( idl );
|
|
81 |
|
|
82 |
@@ -238,7 +244,7 @@
|
|
83 |
nids = 0;
|
|
84 |
|
|
85 |
/* copy in all the ids from the component blocks */
|
|
86 |
- for ( i = 0; tmp[i] != NULL; i++ ) {
|
|
87 |
+ for ( i = 0; i < nblocks; i++ ) {
|
|
88 |
if ( tmp[i] == NULL ) {
|
|
89 |
continue;
|
|
90 |
}
|
|
91 |
@@ -253,6 +259,8 @@
|
|
92 |
}
|
|
93 |
free( (char *) tmp );
|
|
94 |
|
|
95 |
+ assert( ID_BLOCK_NIDS(idl) == nids );
|
|
96 |
+
|
|
97 |
#ifdef LDBM_DEBUG_IDL
|
|
98 |
idl_check(idl);
|
|
99 |
#endif
|
|
100 |
@@ -296,11 +304,6 @@
|
|
101 |
flags = LDBM_REPLACE;
|
|
102 |
rc = ldbm_cache_store( db, key, data, flags );
|
|
103 |
|
|
104 |
-#ifdef LDBM_DEBUG
|
|
105 |
- Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
|
|
106 |
- rc, 0, 0, 0, 0 );
|
|
107 |
-#endif
|
|
108 |
-
|
|
109 |
/* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */
|
|
110 |
return( rc );
|
|
111 |
}
|
|
112 |
@@ -550,14 +553,13 @@
|
|
113 |
|
|
114 |
#ifndef USE_INDIRECT_NIDS
|
|
115 |
/* select the block to try inserting into *//* XXX linear search XXX */
|
|
116 |
- for ( i = 0; !ID_BLOCK_NOID(idl, i) && id > ID_BLOCK_ID(idl, i); i++ )
|
|
117 |
+ for ( i = 0; !ID_BLOCK_NOID(idl, i) && id >= ID_BLOCK_ID(idl, i); i++ )
|
|
118 |
; /* NULL */
|
|
119 |
#else
|
|
120 |
i = idl_find(idl, id);
|
|
121 |
- if (ID_BLOCK_ID(idl, i) < id)
|
|
122 |
+ if (ID_BLOCK_ID(idl, i) <= id)
|
|
123 |
i++;
|
|
124 |
#endif
|
|
125 |
-
|
|
126 |
if ( i != 0 ) {
|
|
127 |
i--;
|
|
128 |
first = 0;
|
|
129 |
@@ -565,6 +567,11 @@
|
|
130 |
first = 1;
|
|
131 |
}
|
|
132 |
|
|
133 |
+ /* At this point, the following condition must be true:
|
|
134 |
+ * ID_BLOCK_ID(idl, i) <= id && id < ID_BLOCK_ID(idl, i+1)
|
|
135 |
+ * except when i is the first or the last block.
|
|
136 |
+ */
|
|
137 |
+
|
|
138 |
/* get the block */
|
|
139 |
cont_alloc( &k2, &key );
|
|
140 |
cont_id( &k2, ID_BLOCK_ID(idl, i) );
|
|
141 |
@@ -626,10 +633,11 @@
|
|
142 |
#else
|
|
143 |
if ( !first && (unsigned long)(i + 1) < ID_BLOCK_NIDS(idl) ) {
|
|
144 |
#endif
|
|
145 |
+ Datum k3;
|
|
146 |
/* read it in */
|
|
147 |
- cont_alloc( &k2, &key );
|
|
148 |
- cont_id( &k2, ID_BLOCK_ID(idl, i) );
|
|
149 |
- if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
|
|
150 |
+ cont_alloc( &k3, &key );
|
|
151 |
+ cont_id( &k3, ID_BLOCK_ID(idl, i + 1) );
|
|
152 |
+ if ( (tmp2 = idl_fetch_one( be, db, k3 )) == NULL ) {
|
|
153 |
#ifdef NEW_LOGGING
|
|
154 |
LDAP_LOG( INDEX, ERR,
|
|
155 |
"idl_insert_key: idl_fetch_one returned NULL\n", 0, 0, 0);
|
|
156 |
@@ -640,7 +648,7 @@
|
|
157 |
#endif
|
|
158 |
|
|
159 |
/* split the original block */
|
|
160 |
- cont_free( &k2 );
|
|
161 |
+ cont_free( &k3 );
|
|
162 |
goto split;
|
|
163 |
}
|
|
164 |
|
|
165 |
@@ -680,7 +688,7 @@
|
|
166 |
db->dbc_maxids )) ) {
|
|
167 |
case 1: /* id inserted first in block */
|
|
168 |
rc = idl_change_first( be, db, key, idl,
|
|
169 |
- i + 1, k2, tmp2 );
|
|
170 |
+ i + 1, k3, tmp2 );
|
|
171 |
/* FALL */
|
|
172 |
|
|
173 |
case 2: /* id already there - how? */
|
|
174 |
@@ -704,6 +712,8 @@
|
|
175 |
|
|
176 |
idl_free( tmp );
|
|
177 |
idl_free( tmp2 );
|
|
178 |
+ cont_free( &k3 );
|
|
179 |
+ cont_free( &k2 );
|
|
180 |
idl_free( idl );
|
|
181 |
return( 0 );
|
|
182 |
|
|
183 |
@@ -712,6 +722,7 @@
|
|
184 |
}
|
|
185 |
|
|
186 |
idl_free( tmp2 );
|
|
187 |
+ cont_free( &k3 );
|
|
188 |
}
|
|
189 |
|
|
190 |
split:
|