]> git.sur5r.net Git - openldap/commitdiff
Add dbpagesize keyword for configuring DB file page sizes
authorHoward Chu <hyc@openldap.org>
Wed, 15 Oct 2008 07:41:57 +0000 (07:41 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 15 Oct 2008 07:41:57 +0000 (07:41 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/config.c
servers/slapd/back-bdb/dbcache.c
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/proto-bdb.h

index 6493a4583c96d75d380fb6cd3cd25fe4a0074035..7ef6fd376126f17725dfd11ecc2d2c0b14056541 100644 (file)
@@ -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;
index 40fca1f8c321130fad49ad7b467f3747e6cdeec9..5c7c1bac2072a9c108d8f6b043116c282bde8651 100644 (file)
@@ -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> <size", 3, 3, 0, ARG_MAGIC|BDB_PGSIZE,
+               bdb_cf_gen, "( OLcfgDbAt:1.15 NAME 'olcDbPageSize' "
+                       "DESC 'Page size of specified DB, in Kbytes' "
+                       "EQUALITY caseExactMatch "
+                       "SYNTAX OMsDirectoryString )", NULL, NULL },
        { "dirtyread", NULL, 1, 2, 0,
 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
                ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
@@ -157,7 +163,7 @@ static ConfigOCs bdbocs[] = {
                "olcDbNoSync $ olcDbDirtyRead $ olcDbIDLcacheSize $ "
                "olcDbIndex $ olcDbLinearIndex $ olcDbLockDetect $ "
                "olcDbMode $ olcDbSearchStack $ olcDbShmKey $ "
-               "olcDbCacheFree $ olcDbDNcacheSize ) )",
+               "olcDbCacheFree $ olcDbDNcacheSize $ olcDbPageSize ) )",
                        Cft_Database, bdbcfg },
        { NULL, 0, NULL }
 };
@@ -483,6 +489,23 @@ bdb_cf_gen( ConfigArgs *c )
                case BDB_SSTACK:
                        c->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;
 }
index c6b8b2368411553f0753309d44a4c5568baaa789..8de7a9c63bcee7d90fd14f98f3660a25345d693f 100644 (file)
@@ -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
index 393b6a52f42038b677814c6533ec9d866498eb22..79dfee9c517562681e069207bfcb2c05c8550502 100644 (file)
@@ -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
index 188d68e13c9dbfaa1bc48a65e88e775c1ac7c927..0659c6b1e261ecc8a56e59712e0a4316aa202131 100644 (file)
@@ -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
  */