nextid.c revision 1.1.1.2 1 /* $NetBSD: nextid.c,v 1.1.1.2 2025/09/05 21:09:50 christos Exp $ */
2
3 /* OpenLDAP WiredTiger backend */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2002-2024 The OpenLDAP Foundation.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
12 * Public License.
13 *
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
17 */
18 /* ACKNOWLEDGEMENTS:
19 * This work was developed by HAMANO Tsukasa <hamano (at) osstech.co.jp>
20 * based on back-bdb for inclusion in OpenLDAP Software.
21 * WiredTiger is a product of MongoDB Inc.
22 */
23
24 #include <sys/cdefs.h>
25 __RCSID("$NetBSD: nextid.c,v 1.1.1.2 2025/09/05 21:09:50 christos Exp $");
26
27 #include "portable.h"
28
29 #include <stdio.h>
30 #include <ac/string.h>
31 #include "back-wt.h"
32 #include "slap-config.h"
33
34 int wt_next_id(BackendDB *be, ID *out){
35 struct wt_info *wi = (struct wt_info *) be->be_private;
36 *out = __sync_add_and_fetch(&wi->wi_lastid, 1);
37 return 0;
38 }
39
40 int wt_last_id( BackendDB *be, WT_SESSION *session, ID *out )
41 {
42 WT_CURSOR *cursor;
43 int rc;
44 uint64_t id;
45
46 rc = session->open_cursor(session, WT_TABLE_ID2ENTRY, NULL, NULL, &cursor);
47 if(rc){
48 Debug( LDAP_DEBUG_ANY,
49 "wt_last_id: open_cursor failed: %s (%d)\n",
50 wiredtiger_strerror(rc), rc );
51 return rc;
52 }
53
54 rc = cursor->prev(cursor);
55 switch(rc) {
56 case 0:
57 rc = cursor->get_key(cursor, &id);
58 if ( rc ) {
59 Debug( LDAP_DEBUG_ANY,
60 "wt_last_id: get_key failed: %s (%d)\n",
61 wiredtiger_strerror(rc), rc );
62 return rc;
63 }
64 *out = id;
65 break;
66 case WT_NOTFOUND:
67 /* no entry */
68 *out = 0;
69 break;
70 default:
71 Debug( LDAP_DEBUG_ANY,
72 "wt_last_id: prev failed: %s (%d)\n",
73 wiredtiger_strerror(rc), rc );
74 }
75
76 rc = cursor->close(cursor);
77 if ( rc ) {
78 Debug( LDAP_DEBUG_ANY,
79 "wt_last_id: close failed: %s (%d)\n",
80 wiredtiger_strerror(rc), rc );
81 return rc;
82 }
83
84 return 0;
85 }
86
87 /*
88 * Local variables:
89 * indent-tabs-mode: t
90 * tab-width: 4
91 * c-basic-offset: 4
92 * End:
93 */
94