diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2010-04-01 15:28:45 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2010-04-01 15:34:08 +0300 |
commit | fed962f059461f64b1017836599c9aa51285d026 (patch) | |
tree | cb02610acbab8ace12822ad15a9c601cdd612c45 /lib/rpmdb.c | |
parent | 86348031c259919bac5085708985cf55084670a9 (diff) | |
download | rpm-fed962f059461f64b1017836599c9aa51285d026.tar.gz rpm-fed962f059461f64b1017836599c9aa51285d026.tar.bz2 rpm-fed962f059461f64b1017836599c9aa51285d026.zip |
Generate package database statistics on close & make use of it on open
- Turn dbiStat() into more useful: return the number of keys in the
index, hiding away the BDB internal access method stuff into the backend
- Force statistics gathering at Packages db close, take advantage of
that when its opened to get a fairly accurate count of packages for
initial "header verified" bitmap allocation. Previously DB_FAST_STAT
was used on open but it never returns anything when no stats have
been previously collected, hence the need for the expensive slow stat.
- The performance hit from stat generation is hardly worth it for
the bitmap allocation alone, but lets see if there are other uses...
- Also gets rid of dbi_stats member, this is not particularly useful
Diffstat (limited to 'lib/rpmdb.c')
-rw-r--r-- | lib/rpmdb.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/rpmdb.c b/lib/rpmdb.c index e324667eb..d15403ab8 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -178,20 +178,15 @@ static dbiIndex rpmdbOpenIndex(rpmdb db, rpmTag rpmtag, unsigned int flags) if (dbi != NULL && rc == 0) { db->_dbi[dbix] = dbi; + /* Grab a fast estimate of package count for allocation */ if (rpmtag == RPMDBI_PACKAGES && db->db_bits == NULL) { - db->db_nbits = 1024; - if (!dbiStat(dbi, DB_FAST_STAT)) { - DB_HASH_STAT * hash = (DB_HASH_STAT *)dbi->dbi_stats; - if (hash) - db->db_nbits += hash->hash_nkeys; - } + int nkeys = dbiNumKeys(dbi, 1); + db->db_nbits = 1024 + (nkeys > 0 ? nkeys : 0); db->db_bits = PBM_ALLOC(db->db_nbits); } - } -#ifdef HAVE_DB_H - else + } else { dbi = dbiFree(dbi); -#endif + } /* FIX: db->_dbi may be NULL */ return dbi; @@ -687,6 +682,13 @@ int rpmdbClose(rpmdb db) int xx; if (db->_dbi[dbix] == NULL) continue; + + /* Force full statistics generation at package db close */ + if (dbiTags[dbix] == RPMDBI_PACKAGES && + (db->db_mode & O_ACCMODE) != O_RDONLY) { + (void) dbiNumKeys(db->_dbi[dbix], 0); + } + xx = dbiClose(db->_dbi[dbix], 0); if (xx && rc == 0) rc = xx; db->_dbi[dbix] = NULL; |