| 1 |
/* OpenLDAP WiredTiger backend */ |
| 2 |
/* $OpenLDAP$ */ |
| 3 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
* |
| 5 |
* Copyright 2002-2024 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 |
/* ACKNOWLEDGEMENTS: |
| 17 |
* This work was developed by HAMANO Tsukasa <[email protected]> |
| 18 |
* based on back-bdb for inclusion in OpenLDAP Software. |
| 19 |
* WiredTiger is a product of MongoDB Inc. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "portable.h" |
| 23 |
|
| 24 |
#include <stdio.h> |
| 25 |
#include <ac/string.h> |
| 26 |
#include "back-wt.h" |
| 27 |
#include "slap-config.h" |
| 28 |
|
| 29 |
int wt_next_id(BackendDB *be, ID *out){ |
| 30 |
struct wt_info *wi = (struct wt_info *) be->be_private; |
| 31 |
*out = __sync_add_and_fetch(&wi->wi_lastid, 1); |
| 32 |
return 0; |
| 33 |
} |
| 34 |
|
| 35 |
int wt_last_id( BackendDB *be, WT_SESSION *session, ID *out ) |
| 36 |
{ |
| 37 |
WT_CURSOR *cursor; |
| 38 |
int rc; |
| 39 |
uint64_t id; |
| 40 |
|
| 41 |
rc = session->open_cursor(session, WT_TABLE_ID2ENTRY, NULL, NULL, &cursor); |
| 42 |
if(rc){ |
| 43 |
Debug( LDAP_DEBUG_ANY, |
| 44 |
"wt_last_id: open_cursor failed: %s (%d)\n", |
| 45 |
wiredtiger_strerror(rc), rc ); |
| 46 |
return rc; |
| 47 |
} |
| 48 |
|
| 49 |
rc = cursor->prev(cursor); |
| 50 |
switch(rc) { |
| 51 |
case 0: |
| 52 |
rc = cursor->get_key(cursor, &id); |
| 53 |
if ( rc ) { |
| 54 |
Debug( LDAP_DEBUG_ANY, |
| 55 |
"wt_last_id: get_key failed: %s (%d)\n", |
| 56 |
wiredtiger_strerror(rc), rc ); |
| 57 |
return rc; |
| 58 |
} |
| 59 |
*out = id; |
| 60 |
break; |
| 61 |
case WT_NOTFOUND: |
| 62 |
/* no entry */ |
| 63 |
*out = 0; |
| 64 |
break; |
| 65 |
default: |
| 66 |
Debug( LDAP_DEBUG_ANY, |
| 67 |
"wt_last_id: prev failed: %s (%d)\n", |
| 68 |
wiredtiger_strerror(rc), rc ); |
| 69 |
} |
| 70 |
|
| 71 |
rc = cursor->close(cursor); |
| 72 |
if ( rc ) { |
| 73 |
Debug( LDAP_DEBUG_ANY, |
| 74 |
"wt_last_id: close failed: %s (%d)\n", |
| 75 |
wiredtiger_strerror(rc), rc ); |
| 76 |
return rc; |
| 77 |
} |
| 78 |
|
| 79 |
return 0; |
| 80 |
} |
| 81 |
|
| 82 |
/* |
| 83 |
* Local variables: |
| 84 |
* indent-tabs-mode: t |
| 85 |
* tab-width: 4 |
| 86 |
* c-basic-offset: 4 |
| 87 |
* End: |
| 88 |
*/ |