| 1 |
/* back-mdb.h - mdb back-end header file */ |
| 2 |
/* $OpenLDAP$ */ |
| 3 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
* |
| 5 |
* Copyright 2000-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 |
|
| 17 |
#ifndef _BACK_MDB_H_ |
| 18 |
#define _BACK_MDB_H_ |
| 19 |
|
| 20 |
#include <portable.h> |
| 21 |
#include "slap.h" |
| 22 |
#include "lmdb.h" |
| 23 |
|
| 24 |
LDAP_BEGIN_DECL |
| 25 |
|
| 26 |
#undef MDB_TOOL_IDL_CACHING /* currently no perf gain */ |
| 27 |
|
| 28 |
#define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX |
| 29 |
#define DN_ONE_PREFIX '%' |
| 30 |
#define DN_SUBTREE_PREFIX '@' |
| 31 |
|
| 32 |
#define MDB_AD2ID 0 |
| 33 |
#define MDB_DN2ID 1 |
| 34 |
#define MDB_ID2ENTRY 2 |
| 35 |
#define MDB_ID2VAL 3 |
| 36 |
#define MDB_IDXCKP 4 |
| 37 |
#define MDB_NDB 5 |
| 38 |
|
| 39 |
/* The default search IDL stack cache depth */ |
| 40 |
#define DEFAULT_SEARCH_STACK_DEPTH 16 |
| 41 |
|
| 42 |
/* The minimum we can function with */ |
| 43 |
#define MINIMUM_SEARCH_STACK_DEPTH 8 |
| 44 |
|
| 45 |
#define MDB_INDICES 256 |
| 46 |
|
| 47 |
#define MDB_MAXADS 65536 |
| 48 |
|
| 49 |
/* Default to 10MB max */ |
| 50 |
#define DEFAULT_MAPSIZE (10*1048576) |
| 51 |
|
| 52 |
/* Most users will never see this */ |
| 53 |
#define DEFAULT_RTXN_SIZE 10000 |
| 54 |
|
| 55 |
#ifdef LDAP_DEVEL |
| 56 |
#define MDB_MONITOR_IDX |
| 57 |
#endif |
| 58 |
|
| 59 |
typedef struct mdb_monitor_t { |
| 60 |
void *mdm_cb; |
| 61 |
struct berval mdm_ndn; |
| 62 |
} mdb_monitor_t; |
| 63 |
|
| 64 |
/* From ldap_rq.h */ |
| 65 |
struct re_s; |
| 66 |
|
| 67 |
struct mdb_info { |
| 68 |
MDB_env *mi_dbenv; |
| 69 |
|
| 70 |
/* DB_ENV parameters */ |
| 71 |
char *mi_dbenv_home; |
| 72 |
unsigned mi_dbenv_flags; |
| 73 |
int mi_dbenv_mode; |
| 74 |
|
| 75 |
size_t mi_mapsize; |
| 76 |
ID mi_nextid; |
| 77 |
size_t mi_maxentrysize; |
| 78 |
|
| 79 |
slap_mask_t mi_defaultmask; |
| 80 |
int mi_nattrs; |
| 81 |
struct mdb_attrinfo **mi_attrs; |
| 82 |
void *mi_search_stack; |
| 83 |
int mi_search_stack_depth; |
| 84 |
int mi_readers; |
| 85 |
|
| 86 |
unsigned mi_rtxn_size; |
| 87 |
int mi_txn_cp; |
| 88 |
unsigned mi_txn_cp_min; |
| 89 |
unsigned mi_txn_cp_kbyte; |
| 90 |
|
| 91 |
struct re_s *mi_txn_cp_task; |
| 92 |
struct re_s *mi_index_task; |
| 93 |
|
| 94 |
mdb_monitor_t mi_monitor; |
| 95 |
|
| 96 |
#ifdef MDB_MONITOR_IDX |
| 97 |
ldap_pvt_thread_mutex_t mi_idx_mutex; |
| 98 |
Avlnode *mi_idx; |
| 99 |
#endif /* MDB_MONITOR_IDX */ |
| 100 |
|
| 101 |
int mi_flags; |
| 102 |
#define MDB_IS_OPEN 0x01 |
| 103 |
#define MDB_OPEN_INDEX 0x02 |
| 104 |
#define MDB_DEL_INDEX 0x08 |
| 105 |
#define MDB_RE_OPEN 0x10 |
| 106 |
#define MDB_NEED_UPGRADE 0x20 |
| 107 |
|
| 108 |
int mi_numads; |
| 109 |
|
| 110 |
unsigned mi_multi_hi; |
| 111 |
/* more than this many values in an attr goes |
| 112 |
* into a separate DB */ |
| 113 |
unsigned mi_multi_lo; |
| 114 |
/* less than this many values in an attr goes |
| 115 |
* back into main blob */ |
| 116 |
|
| 117 |
MDB_dbi mi_dbis[MDB_NDB]; |
| 118 |
AttributeDescription *mi_ads[MDB_MAXADS]; |
| 119 |
int mi_adxs[MDB_MAXADS]; |
| 120 |
}; |
| 121 |
|
| 122 |
#define mi_id2entry mi_dbis[MDB_ID2ENTRY] |
| 123 |
#define mi_dn2id mi_dbis[MDB_DN2ID] |
| 124 |
#define mi_ad2id mi_dbis[MDB_AD2ID] |
| 125 |
#define mi_id2val mi_dbis[MDB_ID2VAL] |
| 126 |
#define mi_idxckp mi_dbis[MDB_IDXCKP] |
| 127 |
|
| 128 |
typedef struct mdb_op_info { |
| 129 |
OpExtra moi_oe; |
| 130 |
MDB_txn* moi_txn; |
| 131 |
int moi_ref; |
| 132 |
char moi_flag; |
| 133 |
} mdb_op_info; |
| 134 |
#define MOI_READER 0x01 |
| 135 |
#define MOI_FREEIT 0x02 |
| 136 |
#define MOI_KEEPER 0x04 |
| 137 |
|
| 138 |
LDAP_END_DECL |
| 139 |
|
| 140 |
/* for the cache of attribute information (which are indexed, etc.) */ |
| 141 |
typedef struct mdb_attrinfo { |
| 142 |
AttributeDescription *ai_desc; /* attribute description cn;lang-en */ |
| 143 |
slap_mask_t ai_indexmask; /* how the attr is indexed */ |
| 144 |
slap_mask_t ai_newmask; /* new settings to replace old mask */ |
| 145 |
#ifdef LDAP_COMP_MATCH |
| 146 |
ComponentReference* ai_cr; /*component indexing*/ |
| 147 |
#endif |
| 148 |
TAvlnode *ai_root; /* for tools */ |
| 149 |
MDB_cursor *ai_cursor; /* for tools */ |
| 150 |
int ai_idx; /* position in AI array */ |
| 151 |
MDB_dbi ai_dbi; |
| 152 |
unsigned ai_multi_hi; |
| 153 |
unsigned ai_multi_lo; |
| 154 |
} AttrInfo; |
| 155 |
|
| 156 |
/* tool threaded indexer state */ |
| 157 |
typedef struct mdb_attrixinfo { |
| 158 |
OpExtra ai_oe; |
| 159 |
void *ai_flist; |
| 160 |
void *ai_clist; |
| 161 |
AttrInfo *ai_ai; |
| 162 |
} AttrIxInfo; |
| 163 |
|
| 164 |
/* These flags must not clash with SLAP_INDEX flags or ops in slap.h! */ |
| 165 |
#define MDB_INDEX_DELETING 0x8000U /* index is being modified */ |
| 166 |
#define MDB_INDEX_UPDATE_OP 0x03 /* performing an index update */ |
| 167 |
|
| 168 |
/* For slapindex to record which attrs in an entry belong to which |
| 169 |
* index database |
| 170 |
*/ |
| 171 |
typedef struct AttrList { |
| 172 |
struct AttrList *next; |
| 173 |
Attribute *attr; |
| 174 |
} AttrList; |
| 175 |
|
| 176 |
#ifndef CACHELINE |
| 177 |
#define CACHELINE 64 |
| 178 |
#endif |
| 179 |
|
| 180 |
#if defined(__i386) || defined(__x86_64) |
| 181 |
#define MISALIGNED_OK 1 |
| 182 |
#else |
| 183 |
#define ALIGNER (sizeof(size_t)-1) |
| 184 |
#endif |
| 185 |
|
| 186 |
typedef struct IndexRbody { |
| 187 |
AttrInfo *ai; |
| 188 |
AttrList *attrs; |
| 189 |
void *tptr; |
| 190 |
int i; |
| 191 |
} IndexRbody; |
| 192 |
|
| 193 |
typedef struct IndexRec { |
| 194 |
union { |
| 195 |
IndexRbody irb; |
| 196 |
#define ir_ai iru.irb.ai |
| 197 |
#define ir_attrs iru.irb.attrs |
| 198 |
#define ir_tptr iru.irb.tptr |
| 199 |
#define ir_i iru.irb.i |
| 200 |
/* cache line alignment */ |
| 201 |
char pad[(sizeof(IndexRbody)+CACHELINE-1) & (!CACHELINE-1)]; |
| 202 |
} iru; |
| 203 |
} IndexRec; |
| 204 |
|
| 205 |
#define MAXRDNS SLAP_LDAPDN_MAXLEN/4 |
| 206 |
|
| 207 |
#include "proto-mdb.h" |
| 208 |
|
| 209 |
#endif /* _BACK_MDB_H_ */ |