Hardwire the fundamental BDB access method configuration inside rpm
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 20 Oct 2010 13:38:46 +0000 (16:38 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 20 Oct 2010 13:53:00 +0000 (16:53 +0300)
- The different access methods have different capabilities and are not
  interchangeable in all situations. Currently we can use either
  hash and btree but this might not be always the case for all indexes.
- We'll eventually want to force-switch the index types to our liking,
  but for now follow these simple rules:
  1) For existing databases, we accept both btree and hash
  2) For newly created databases, the main Packages database remains
     a hash, all indexes are btrees.
- Rip out nearly all the rest of the remaining macro configuration.

lib/backend/db3.c
lib/backend/dbconfig.c
lib/backend/dbi.h
macros.in

index ff458b5..1b3564c 100644 (file)
@@ -513,6 +513,7 @@ int dbiOpen(rpmdb rdb, rpmTag rpmtag, dbiIndex * dbip, int flags)
     int verifyonly = (flags & RPMDB_FLAG_VERIFYONLY);
 
     DB * db = NULL;
+    DBTYPE dbtype = DB_UNKNOWN;
     uint32_t oflags;
     static int _lockdbfd = 0;
 
@@ -552,28 +553,32 @@ int dbiOpen(rpmdb rdb, rpmTag rpmtag, dbiIndex * dbip, int flags)
            free(dbfs);
 
            rc = (db->open)(db, NULL, dbi->dbi_file, NULL,
-               dbi->dbi_dbtype, oflags, rdb->db_perms);
+                           dbtype, oflags, rdb->db_perms);
 
            /* Attempt to create if missing, discarding DB_RDONLY (!) */
            if (rc == ENOENT) {
                oflags |= DB_CREATE;
                oflags &= ~DB_RDONLY;
+               dbtype = (dbiType(dbi) == DBI_PRIMARY) ?  DB_HASH : DB_BTREE;
                retry_open--;
            } else {
                retry_open = 0;
            }
 
-           if (rc == 0 && dbi->dbi_dbtype == DB_UNKNOWN) {
-               DBTYPE dbi_dbtype = DB_UNKNOWN;
-               xx = db->get_type(db, &dbi_dbtype);
-               if (xx == 0)
-                   dbi->dbi_dbtype = dbi_dbtype;
-           }
-
            /* XXX return rc == errno without printing */
            _printit = (rc > 0 ? 0 : _debug);
            xx = cvtdberr(dbi, "db->open", rc, _printit);
 
+           /* Validate the index type is something we can support */
+           if ((rc == 0) && (dbtype == DB_UNKNOWN)) {
+               db->get_type(db, &dbtype);
+               if (dbtype != DB_HASH && dbtype != DB_BTREE) {
+                   rpmlog(RPMLOG_ERR, _("invalid index type %x on %s/%s\n"),
+                               dbtype, dbhome, dbi->dbi_file);
+                   rc = 1;
+               }
+           }
+
            if (rc != 0) {
                db->close(db, 0);
                db = NULL;
index ef30581..2f336b7 100644 (file)
@@ -65,13 +65,6 @@ static const struct poptOption rdbOptions[] = {
  { "nommap",   0,POPT_BIT_SET,         &staticdbi.dbi_oflags, DB_NOMMAP,
        NULL, NULL },
 
- { "btree",    0,POPT_ARG_VAL,         &staticdbi.dbi_dbtype, DB_BTREE,
-       NULL, NULL },
- { "hash",     0,POPT_ARG_VAL,         &staticdbi.dbi_dbtype, DB_HASH,
-       NULL, NULL },
- { "unknown",  0,POPT_ARG_VAL,         &staticdbi.dbi_dbtype, DB_UNKNOWN,
-       NULL, NULL },
-
  { "nodbsync", 0,POPT_ARG_NONE,        &staticdbi.dbi_no_dbsync, 0,
        NULL, NULL },
  { "lockdbfd", 0,POPT_ARG_NONE,        &staticdbi.dbi_lockdbfd, 0,
@@ -88,10 +81,6 @@ dbiIndex dbiFree(dbiIndex dbi)
     return dbi;
 }
 
-/** @todo Set a reasonable "last gasp" default db config. */
-static const char * const dbi_config_default =
-    "hash:cdb:verbose";
-
 dbiIndex dbiNew(rpmdb rdb, rpmTag rpmtag)
 {
     dbiIndex dbi = xcalloc(1, sizeof(*dbi));
@@ -103,7 +92,7 @@ dbiIndex dbiNew(rpmdb rdb, rpmTag rpmtag)
        dbOpts = _free(dbOpts);
        dbOpts = rpmExpand("%{_dbi_config}", NULL);
        if (!(dbOpts && *dbOpts && *dbOpts != '%')) {
-           dbOpts = rpmExpand(dbi_config_default, NULL);
+           dbOpts = _free(dbOpts);
        }
     }
 
index 7932397..f9b7949 100644 (file)
@@ -65,7 +65,6 @@ enum dbiFlags_e {
 struct _dbiIndex {
     const char * dbi_file;     /*!< file component of path */
 
-    DBTYPE dbi_dbtype;         /*!< db index type */
     int        dbi_oflags;             /*!< db->open flags */
     int        dbi_permit_dups;        /*!< permit duplicate entries? */
     int        dbi_no_dbsync;          /*!< don't call dbiSync */
index 6a6078a..63ca234 100644 (file)
--- a/macros.in
+++ b/macros.in
@@ -517,9 +517,6 @@ print (t)\
 #    I believe that you will find pagesize=512 "best".
 # 3) Adding nofsync increases speed, but risks total data loss. Fiddle shared
 #    and/or mp_size instead.
-# 4) btree is faster than hash, but would require some painful rpm release
-#    engineering to convert everbody's databases to btree, not gonna happen
-#    soon.
 #
 #   token      works?  Berkeley db flag or value
 #==================================================
@@ -528,10 +525,6 @@ print (t)\
 #   cachesize=1Mb      DBENV->set_cachesize, DB->set_cachesize
 #---------------------- DB->open bits:
 #   nommap     ???     DB_NOMMAP
-#---------------------- DB->open types:
-#   btree              DB_BTREE
-#   hash               DB_HASH
-#   unknown    +++     DB_UNKNOWN
 #----------------------- rpmdb specific configuration:
 #   lockdbfd           (always on for Packages) Use fcntl(2) locking ?
 #   nofsync            Disable fsync(2) call performed after db3 writes?
@@ -540,31 +533,10 @@ print (t)\
 # Misc BDB tuning options
 %__dbi_other                   mp_mmapsize=16Mb mp_size=1Mb
 
-#
-#--- Hash database configuration
-%__dbi_htconfig        \
-  hash         \
-  %{__dbi_other}\
-%{nil}
-
-%_dbi_htconfig                 %{__dbi_htconfig}
-
-#
-#--- Btree database configuration
-%__dbi_btconfig        \
-  btree                \
-  %{__dbi_other}\
-%{nil}
-
-%_dbi_btconfig                 %{__dbi_btconfig}
+%_dbi_config                   %{?__dbi_other}
 
 # "Packages" should have shared/exclusive fcntl(2) lock using "lockdbfd".
-%_dbi_config_Packages          %{_dbi_htconfig} lockdbfd
-
-%_dbi_config_Dirnames          %{_dbi_btconfig}
-%_dbi_config_Installtid                %{_dbi_btconfig}
-
-%_dbi_config   %{_dbi_htconfig}
+%_dbi_config_Packages          %{?_dbi_config} lockdbfd
 
 # XXX legacy configuration.
 # Choose db interface: