From d06301f303ba10dd306986f6cd8df5a126abb22e Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 4 Oct 2011 02:18:09 -0700 Subject: [PATCH] Turn off tool IDL caching Well, just like in back-bdb in 2005, it only slowed things down on larger LDIFs. --- servers/slapd/back-mdb/idl.c | 6 +++++- servers/slapd/back-mdb/index.c | 2 ++ servers/slapd/back-mdb/tools.c | 31 +++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/servers/slapd/back-mdb/idl.c b/servers/slapd/back-mdb/idl.c index 67d77bd5bf..f4cb11f960 100644 --- a/servers/slapd/back-mdb/idl.c +++ b/servers/slapd/back-mdb/idl.c @@ -399,6 +399,7 @@ mdb_idl_insert_keys( ID lo, hi, *i; char *err; int rc, k; + unsigned int flag = MDB_NODUPDATA; { char buf[16]; @@ -409,6 +410,9 @@ mdb_idl_insert_keys( assert( id != NOID ); + if ( slapMode & SLAP_TOOL_QUICK ) + flag |= MDB_APPEND; + for ( k=0; keys[k].bv_val; k++ ) { /* Fetch the first data item for this key, to see if it * exists and if it's a range. @@ -501,7 +505,7 @@ mdb_idl_insert_keys( } else if ( rc == MDB_NOTFOUND ) { put1: data.mv_data = &id; data.mv_size = sizeof(ID); - rc = mdb_cursor_put( cursor, &key, &data, MDB_NODUPDATA ); + rc = mdb_cursor_put( cursor, &key, &data, flag ); /* Don't worry if it's already there */ if ( rc == MDB_KEYEXIST ) rc = 0; diff --git a/servers/slapd/back-mdb/index.c b/servers/slapd/back-mdb/index.c index 8d361bede1..1c6a23871f 100644 --- a/servers/slapd/back-mdb/index.c +++ b/servers/slapd/back-mdb/index.c @@ -185,9 +185,11 @@ static int indexer( if ( rc ) goto done; if ( opid == SLAP_INDEX_ADD_OP ) { +#ifdef MDB_TOOL_IDL_CACHING if ( slapMode & SLAP_TOOL_QUICK ) keyfunc = mdb_tool_idl_add; else +#endif keyfunc = mdb_idl_insert_keys; } else keyfunc = mdb_idl_delete_keys; diff --git a/servers/slapd/back-mdb/tools.c b/servers/slapd/back-mdb/tools.c index f2da4fdc41..e4da95ec94 100644 --- a/servers/slapd/back-mdb/tools.c +++ b/servers/slapd/back-mdb/tools.c @@ -24,6 +24,7 @@ #include "back-mdb.h" #include "idl.h" +#ifdef MDB_TOOL_IDL_CACHING static int mdb_tool_idl_flush( BackendDB *be, MDB_txn *txn ); #define IDBLOCK 1024 @@ -47,6 +48,11 @@ typedef struct mdb_tool_idl_cache { static mdb_tool_idl_cache_entry *mdb_tool_idl_free_list; static Avlnode *mdb_tool_roots[MDB_INDICES]; +#define MDB_TOOL_IDL_FLUSH(be, txn) mdb_tool_idl_flush(be, txn) +#else +#define MDB_TOOL_IDL_FLUSH(be, txn) +#endif /* MDB_TOOL_IDL_CACHING */ + static MDB_txn *txn = NULL, *txi = NULL; static MDB_cursor *cursor = NULL, *idcursor = NULL; static MDB_val key, data; @@ -161,7 +167,7 @@ int mdb_tool_entry_close( mdb_cursor_close( cursor ); cursor = NULL; } - mdb_tool_idl_flush( be, txn ); + MDB_TOOL_IDL_FLUSH( be, txn ); if( txn ) { if ( mdb_txn_commit( txn )) return -1; @@ -618,7 +624,7 @@ done: if( rc == 0 ) { mdb_writes++; if ( mdb_writes >= mdb_writes_per_commit ) { - mdb_tool_idl_flush( be, txn ); + MDB_TOOL_IDL_FLUSH( be, txn ); rc = mdb_txn_commit( txn ); mdb_writes = 0; txn = NULL; @@ -773,7 +779,7 @@ done: if( rc == 0 ) { mdb_writes++; if ( mdb_writes >= mdb_writes_per_commit ) { - mdb_tool_idl_flush( be, txi ); + MDB_TOOL_IDL_FLUSH( be, txi ); rc = mdb_txn_commit( txi ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, @@ -914,6 +920,7 @@ mdb_tool_index_task( void *ctx, void *ptr ) } #endif +#ifdef MDB_TOOL_IDL_CACHING static int mdb_tool_idl_cmp( const void *v1, const void *v2 ) { @@ -1044,13 +1051,14 @@ mdb_tool_idl_flush( BackendDB *be, MDB_txn *txn ) { struct mdb_info *mdb = (struct mdb_info *) be->be_private; int rc = 0; - unsigned int i; - - for ( i=MDB_NDB; i < mdb->mi_nattrs+MDB_NDB; i++ ) { - if ( !mdb_tool_roots[i] ) continue; - rc = mdb_tool_idl_flush_db( txn, i, mdb_tool_roots[i] ); - tavl_free(mdb_tool_roots[i], NULL); - mdb_tool_roots[i] = NULL; + unsigned int i, dbi; + + for ( i=0; i < mdb->mi_nattrs; i++ ) { + dbi = mdb->mi_attrs[i]->ai_dbi; + if ( !mdb_tool_roots[dbi] ) continue; + rc = mdb_tool_idl_flush_db( txn, dbi, mdb_tool_roots[dbi] ); + tavl_free(mdb_tool_roots[dbi], NULL); + mdb_tool_roots[dbi] = NULL; if ( rc ) break; } @@ -1146,6 +1154,8 @@ int mdb_tool_idl_add( ic->tail->next = ice; } ic->tail = ice; + if ( lcount ) + ice->ids[lcount-1] = 0; if ( !ic->count ) ic->first = id; } @@ -1157,3 +1167,4 @@ int mdb_tool_idl_add( return 0; } +#endif /* MDB_TOOL_IDL_CACHING */ -- 2.39.5