Back to index

openldap  2.4.31
back-mdb.h
Go to the documentation of this file.
00001 /* back-mdb.h - mdb back-end header file */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2000-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #ifndef _BACK_MDB_H_
00018 #define _BACK_MDB_H_
00019 
00020 #include <portable.h>
00021 #include "slap.h"
00022 #include "mdb.h"
00023 
00024 LDAP_BEGIN_DECL
00025 
00026 #define MDB_TOOL_IDL_CACHING       1
00027 
00028 #define DN_BASE_PREFIX             SLAP_INDEX_EQUALITY_PREFIX
00029 #define DN_ONE_PREFIX              '%'
00030 #define DN_SUBTREE_PREFIX   '@'
00031 
00032 #define MDB_AD2ID           0
00033 #define MDB_DN2ID           1
00034 #define MDB_ID2ENTRY 2
00035 #define MDB_NDB                    3
00036 
00037 /* The default search IDL stack cache depth */
00038 #define DEFAULT_SEARCH_STACK_DEPTH 16
00039 
00040 /* The minimum we can function with */
00041 #define MINIMUM_SEARCH_STACK_DEPTH 8
00042 
00043 #define MDB_INDICES         128
00044 
00045 #define       MDB_MAXADS    65536
00046 
00047 /* Default to 10MB max */
00048 #define DEFAULT_MAPSIZE     (10*1048576)
00049 
00050 #ifdef LDAP_DEVEL
00051 #define MDB_MONITOR_IDX
00052 #endif /* LDAP_DEVEL */
00053 
00054 typedef struct mdb_monitor_t {
00055        void          *mdm_cb;
00056        struct berval mdm_ndn;
00057 } mdb_monitor_t;
00058 
00059 /* From ldap_rq.h */
00060 struct re_s;
00061 
00062 struct mdb_info {
00063        MDB_env              *mi_dbenv;
00064 
00065        /* DB_ENV parameters */
00066        /* The DB_ENV can be tuned via DB_CONFIG */
00067        char          *mi_dbenv_home;
00068        uint32_t      mi_dbenv_flags;
00069        int                  mi_dbenv_mode;
00070 
00071        size_t        mi_mapsize;
00072 
00073        slap_mask_t   mi_defaultmask;
00074        int                  mi_nattrs;
00075        struct mdb_attrinfo         **mi_attrs;
00076        void          *mi_search_stack;
00077        int                  mi_search_stack_depth;
00078        int                  mi_readers;
00079 
00080        int                  mi_txn_cp;
00081        uint32_t      mi_txn_cp_min;
00082        uint32_t      mi_txn_cp_kbyte;
00083        struct re_s          *mi_txn_cp_task;
00084        struct re_s          *mi_index_task;
00085 
00086        mdb_monitor_t mi_monitor;
00087 
00088 #ifdef MDB_MONITOR_IDX
00089        ldap_pvt_thread_mutex_t     mi_idx_mutex;
00090        Avlnode              *mi_idx;
00091 #endif /* MDB_MONITOR_IDX */
00092 
00093        int           mi_flags;
00094 #define       MDB_IS_OPEN          0x01
00095 #define       MDB_OPEN_INDEX       0x02
00096 #define       MDB_DEL_INDEX 0x08
00097 #define       MDB_RE_OPEN          0x10
00098 
00099        int mi_numads;
00100 
00101        MDB_dbi       mi_dbis[MDB_NDB];
00102        AttributeDescription *mi_ads[MDB_MAXADS];
00103        int mi_adxs[MDB_MAXADS];
00104 };
00105 
00106 #define mi_id2entry  mi_dbis[MDB_ID2ENTRY]
00107 #define mi_dn2id     mi_dbis[MDB_DN2ID]
00108 #define mi_ad2id     mi_dbis[MDB_AD2ID]
00109 
00110 typedef struct mdb_op_info {
00111        OpExtra              moi_oe;
00112        MDB_txn*      moi_txn;
00113        int                  moi_ref;
00114        char          moi_flag;
00115 } mdb_op_info;
00116 #define MOI_READER   0x01
00117 #define MOI_FREEIT   0x02
00118 
00119 /* Copy an ID "src" to pointer "dst" in big-endian byte order */
00120 #define MDB_ID2DISK( src, dst )    \
00121        do { int i0; ID tmp; unsigned char *_p;   \
00122               tmp = (src); _p = (unsigned char *)(dst); \
00123               for ( i0=sizeof(ID)-1; i0>=0; i0-- ) {    \
00124                      _p[i0] = tmp & 0xff; tmp >>= 8;    \
00125               } \
00126        } while(0)
00127 
00128 /* Copy a pointer "src" to a pointer "dst" from big-endian to native order */
00129 #define MDB_DISK2ID( src, dst ) \
00130        do { unsigned i0; ID tmp = 0; unsigned char *_p; \
00131               _p = (unsigned char *)(src);       \
00132               for ( i0=0; i0<sizeof(ID); i0++ ) {       \
00133                      tmp <<= 8; tmp |= *_p++;    \
00134               } *(dst) = tmp; \
00135        } while (0)
00136 
00137 LDAP_END_DECL
00138 
00139 /* for the cache of attribute information (which are indexed, etc.) */
00140 typedef struct mdb_attrinfo {
00141        AttributeDescription *ai_desc; /* attribute description cn;lang-en */
00142        slap_mask_t ai_indexmask;   /* how the attr is indexed  */
00143        slap_mask_t ai_newmask;     /* new settings to replace old mask */
00144 #ifdef LDAP_COMP_MATCH
00145        ComponentReference* ai_cr; /*component indexing*/
00146 #endif
00147        Avlnode *ai_root;           /* for tools */
00148        void *ai_flist;             /* for tools */
00149        void *ai_clist;             /* for tools */
00150        MDB_cursor *ai_cursor;      /* for tools */
00151        int ai_idx;   /* position in AI array */
00152        MDB_dbi ai_dbi;
00153 } AttrInfo;
00154 
00155 /* These flags must not clash with SLAP_INDEX flags or ops in slap.h! */
00156 #define       MDB_INDEX_DELETING   0x8000U       /* index is being modified */
00157 #define       MDB_INDEX_UPDATE_OP  0x03   /* performing an index update */
00158 
00159 /* For slapindex to record which attrs in an entry belong to which
00160  * index database 
00161  */
00162 typedef struct AttrList {
00163        struct AttrList *next;
00164        Attribute *attr;
00165 } AttrList;
00166 
00167 #ifndef CACHELINE
00168 #define CACHELINE    64
00169 #endif
00170 
00171 #if defined(__i386) || defined(__x86_64)
00172 #define MISALIGNED_OK       1
00173 #else
00174 #define       ALIGNER       (sizeof(size_t)-1)
00175 #endif
00176 
00177 typedef struct IndexRbody {
00178        AttrInfo *ai;
00179        AttrList *attrs;
00180        void *tptr;
00181        int i;
00182 } IndexRbody;
00183 
00184 typedef struct IndexRec {
00185        union {
00186               IndexRbody irb;
00187 #define ir_ai iru.irb.ai
00188 #define ir_attrs     iru.irb.attrs
00189 #define ir_tptr      iru.irb.tptr
00190 #define ir_i  iru.irb.i
00191               /* cache line alignment */
00192               char pad[(sizeof(IndexRbody)+CACHELINE-1) & (!CACHELINE-1)];
00193        } iru;
00194 } IndexRec;
00195 
00196 #define MAXRDNS      SLAP_LDAPDN_MAXLEN/4
00197 
00198 #include "proto-mdb.h"
00199 
00200 #endif /* _BACK_MDB_H_ */