From 81ed60c0564873fa032cb475024cf25f251d1e2f Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 15 Oct 2008 07:41:57 +0000 Subject: [PATCH] Add dbpagesize keyword for configuring DB file page sizes --- servers/slapd/back-bdb/back-bdb.h | 9 +++- servers/slapd/back-bdb/config.c | 70 +++++++++++++++++++++++++++++- servers/slapd/back-bdb/dbcache.c | 29 ++++++++++++- servers/slapd/back-bdb/init.c | 12 +++-- servers/slapd/back-bdb/proto-bdb.h | 6 +++ 5 files changed, 118 insertions(+), 8 deletions(-) diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 6493a4583c..7ef6fd3761 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -156,6 +156,12 @@ struct bdb_db_info { DB *bdi_db; }; +struct bdb_db_pgsize { + struct bdb_db_pgsize *bdp_next; + struct berval bdp_name; + int bdp_size; +}; + #ifdef LDAP_DEVEL #define BDB_MONITOR_IDX #endif /* LDAP_DEVEL */ @@ -178,9 +184,10 @@ struct bdb_info { int bi_dbenv_mode; int bi_ndatabases; + int bi_db_opflags; /* db-specific flags */ struct bdb_db_info **bi_databases; ldap_pvt_thread_mutex_t bi_database_mutex; - int bi_db_opflags; /* db-specific flags */ + struct bdb_db_pgsize *bi_pagesizes; slap_mask_t bi_defaultmask; Cache bi_cache; diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index 40fca1f8c3..5c7c1bac20 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -50,7 +50,8 @@ enum { BDB_INDEX, BDB_LOCKD, BDB_SSTACK, - BDB_MODE + BDB_MODE, + BDB_PGSIZE }; static ConfigTable bdbcfg[] = { @@ -89,6 +90,11 @@ static ConfigTable bdbcfg[] = { bdb_cf_gen, "( OLcfgDbAt:1.4 NAME 'olcDbNoSync' " "DESC 'Disable synchronous database writes' " "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, + { "dbpagesize", "db> value_int = bdb->bi_search_stack_depth; break; + + case BDB_PGSIZE: { + struct bdb_db_pgsize *ps; + char buf[SLAP_TEXT_BUFLEN]; + struct berval bv; + int rc = 1; + + bv.bv_val = buf; + for ( ps = bdb->bi_pagesizes; ps; ps = ps->bdp_next ) { + bv.bv_len = sprintf( buf, "%s %d", ps->bdp_name.bv_val, + ps->bdp_size / 1024 ); + value_add_one( &c->rvalue_vals, &bv ); + rc = 0; + + } + break; + } } return rc; } else if ( c->op == LDAP_MOD_DELETE ) { @@ -608,6 +631,24 @@ bdb_cf_gen( ConfigArgs *c ) } } break; + /* doesn't make sense on the fly; the DB file must be + * recreated + */ + case BDB_PGSIZE: { + struct bdb_db_pgsize *ps, **prev; + int i; + + for ( i = 0, prev = &bdb->bi_pagesizes, ps = *prev; ps; + prev = &ps->bdp_next, ps = ps->bdp_next, i++ ) { + if ( c->valx == -1 || i == c->valx ) { + *prev = ps->bdp_next; + ch_free( ps ); + ps = *prev; + if ( i == c->valx ) break; + } + } + } + break; } return rc; } @@ -841,6 +882,31 @@ bdb_cf_gen( ConfigArgs *c ) } bdb->bi_search_stack_depth = c->value_int; break; + + case BDB_PGSIZE: { + struct bdb_db_pgsize *ps, **prev; + int i, s; + + s = atoi(c->argv[2]); + if ( s < 1 || s > 64 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "%s: size must be > 0 and <= 64: %d", + c->log, s ); + Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 ); + return -1; + } + i = strlen(c->argv[1]); + ps = ch_malloc( sizeof(struct bdb_db_pgsize) + i + 1 ); + ps->bdp_next = NULL; + ps->bdp_name.bv_len = i; + ps->bdp_name.bv_val = (char *)(ps+1); + strcpy( ps->bdp_name.bv_val, c->argv[1] ); + ps->bdp_size = s * 1024; + for ( prev = &bdb->bi_pagesizes; *prev; prev = &(*prev)->bdp_next ) + ; + *prev = ps; + } + break; } return 0; } diff --git a/servers/slapd/back-bdb/dbcache.c b/servers/slapd/back-bdb/dbcache.c index c6b8b23684..8de7a9c63b 100644 --- a/servers/slapd/back-bdb/dbcache.c +++ b/servers/slapd/back-bdb/dbcache.c @@ -57,6 +57,29 @@ bdb_db_hash( #define BDB_INDEXTYPE DB_BTREE #endif +/* If a configured size is found, return it, otherwise return 0 */ +int +bdb_db_findsize( + struct bdb_info *bdb, + struct berval *name +) +{ + struct bdb_db_pgsize *bp; + int rc; + + for ( bp = bdb->bi_pagesizes; bp; bp=bp->bdp_next ) { + rc = strncmp( name->bv_val, bp->bdp_name.bv_val, name->bv_len ); + if ( !rc ) { + if ( name->bv_len == bp->bdp_name.bv_len ) + return bp->bdp_size; + if ( name->bv_len < bp->bdp_name.bv_len && + bp->bdp_name.bv_val[name->bv_len] == '.' ) + return bp->bdp_size; + } + } + return 0; +} + int bdb_db_cache( Backend *be, @@ -121,7 +144,11 @@ bdb_db_cache( } } - rc = db->bdi_db->set_pagesize( db->bdi_db, BDB_PAGESIZE ); + /* If no explicit size set, use the default */ + flags = bdb_db_findsize( bdb, name ); + if ( !flags ) flags = BDB_PAGESIZE; + rc = db->bdi_db->set_pagesize( db->bdi_db, flags ); + #ifdef BDB_INDEX_USE_HASH rc = db->bdi_db->set_h_hash( db->bdi_db, bdb_db_hash ); #endif diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 393b6a52f4..79dfee9c51 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -416,19 +416,25 @@ shm_retry: } } + rc = bdb_db_findsize( bdb, (struct berval *)&bdbi_databases[i].name ); + if( i == BDB_ID2ENTRY ) { + if ( !rc ) rc = BDB_ID2ENTRY_PAGESIZE; + rc = db->bdi_db->set_pagesize( db->bdi_db, rc ); + if ( slapMode & SLAP_TOOL_MODE ) db->bdi_db->mpf->set_priority( db->bdi_db->mpf, DB_PRIORITY_VERY_LOW ); - rc = db->bdi_db->set_pagesize( db->bdi_db, - BDB_ID2ENTRY_PAGESIZE ); if ( slapMode & SLAP_TOOL_READMAIN ) { flags |= DB_RDONLY; } else { flags |= DB_CREATE; } } else { + if ( !rc ) rc = BDB_PAGESIZE; + rc = db->bdi_db->set_pagesize( db->bdi_db, rc ); + rc = db->bdi_db->set_flags( db->bdi_db, DB_DUP | DB_DUPSORT ); #ifndef BDB_HIER @@ -446,8 +452,6 @@ shm_retry: flags |= DB_CREATE; } #endif - rc = db->bdi_db->set_pagesize( db->bdi_db, - BDB_PAGESIZE ); } #ifdef HAVE_EBCDIC diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 188d68e13c..0659c6b1e2 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -70,6 +70,7 @@ int bdb_back_init_cf( BackendInfo *bi ); * dbcache.c */ #define bdb_db_cache BDB_SYMBOL(db_cache) +#define bdb_db_findsize BDB_SYMBOL(db_findsize) int bdb_db_cache( @@ -77,6 +78,11 @@ bdb_db_cache( struct berval *name, DB **db ); +int +bdb_db_findsize( + struct bdb_info *bdb, + struct berval *name ); + /* * dn2entry.c */ -- 2.39.5