]> git.sur5r.net Git - openldap/blob - servers/slapd/back-mdb/nextid.c
More for indexing, drop dbcache
[openldap] / servers / slapd / back-mdb / nextid.c
1 /* init.c - initialize mdb backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2011 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21
22 #include "back-mdb.h"
23
24 int mdb_next_id( BackendDB *be, MDB_txn *tid, ID *out )
25 {
26         struct mdb_info *mdb = (struct mdb_info *) be->be_private;
27         int rc;
28         ID id = 0;
29         MDB_val key;
30         MDB_cursor *cursor;
31
32         /* Get a read cursor */
33         rc = mdb_cursor_open( tid, mdb->mi_id2entry, &cursor );
34
35         if (rc == 0) {
36                 rc = mdb_cursor_get(cursor, &key, NULL, MDB_LAST);
37                 mdb_cursor_close(cursor);
38         }
39
40         switch(rc) {
41         case MDB_NOTFOUND:
42                 rc = 0;
43                 *out = 1;
44                 break;
45         case 0:
46                 memcpy( &id, key.mv_data, sizeof( id ));
47                 *out = ++id;
48                 break;
49
50         default:
51                 Debug( LDAP_DEBUG_ANY,
52                         "=> mdb_next_id: get failed: %s (%d)\n",
53                         mdb_strerror(rc), rc, 0 );
54                 goto done;
55         }
56
57 done:
58         return rc;
59 }