Hi all:

So here, for your amusement and subject to your general mockery, are two
patches that modify the database in such a way as to break compatibility
with existing code.

In a nutshell, the code stores as many values as possible in the db as
integers, rather than text. Also, it drops the checksum_value row,
because this is the same as pkgId.

We could also just drop the header_start and header_end columns, because
 yum is awesomer now and doesn't need them.

Some stats (just the development repo):

new db -

db generation - 8.64user 0.88system 0:11.85elapsed
13M filelists.xml.gz.sqlite
30M other.xml.gz.sqlite
4.7M primary.xml.gz.sqlite
remove glibc - 33.82user 2.78system 0:37.61elapsed
install eclipse-cdt - 11.26user 1.99system 0:13.85elapsed

original db -

db generation - 8.92user 0.90system 0:12.31elapsed
13M filelists.xml.gz.sqlite
31M other.xml.gz.sqlite
5.2M primary.xml.gz.sqlite
remove glibc - 34.09user 2.71system 0:37.85elapsed
install eclipse-cdt - 14.61user 2.50system 0:17.79elapsed

Nothing too mind-blowing, but the space savings and install speedup are
nice.

Some things that could be done but probably shouldn't:
- Convert the values from ints to strings as they are pulled out of the
database. I'd rather not do this for performance reasons, but it would
mean that the API is not broken (see epoch related code in the yum patch)
- Write equivalent code for sqlitecache.py. I didn't because C is the
best. Also it's probably about time to drop that file.
- Store the pkgId as raw data rather than a printable string. This would
save 20 bytes per pkgId, but pysqlite makes it very difficult to do
anything with this value once you've gotten it out of the db.

Since these patches will make Tim have to rewrite large amounts of code,
I say we apply them post yum 3.2.

What say everyone?

-James
diff --git a/db.c b/db.c
index 51af8d8..16254f3 100644
--- a/db.c
+++ b/db.c
@@ -163,7 +163,7 @@ yum_db_create_dbinfo_table (sqlite3 *db, GError **err)
     int rc;
     const char *sql;
 
-    sql = "CREATE TABLE db_info (dbversion TEXT, checksum TEXT)";
+    sql = "CREATE TABLE db_info (dbversion INTEGER, checksum TEXT)";
     rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
     if (rc != SQLITE_OK) {
         g_set_error (err, YUM_DB_ERROR, YUM_DB_ERROR,
@@ -319,28 +319,27 @@ yum_db_create_primary_tables (sqlite3 *db, GError **err)
         "  name TEXT,"
         "  arch TEXT,"
         "  version TEXT,"
-        "  epoch TEXT,"
+        "  epoch INTEGER,"
         "  release TEXT,"
         "  summary TEXT,"
         "  description TEXT,"
         "  url TEXT,"
-        "  time_file TEXT,"
-        "  time_build TEXT,"
+        "  time_file INTEGER,"
+        "  time_build INTEGER,"
         "  rpm_license TEXT,"
         "  rpm_vendor TEXT,"
         "  rpm_group TEXT,"
         "  rpm_buildhost TEXT,"
         "  rpm_sourcerpm TEXT,"
-        "  rpm_header_start TEXT,"
-        "  rpm_header_end TEXT,"
+        "  rpm_header_start INTEGER,"
+        "  rpm_header_end INTEGER,"
         "  rpm_packager TEXT,"
-        "  size_package TEXT,"
-        "  size_installed TEXT,"
-        "  size_archive TEXT,"
+        "  size_package INTEGER,"
+        "  size_installed INTEGER,"
+        "  size_archive INTEGER,"
         "  location_href TEXT,"
         "  location_base TEXT,"
-        "  checksum_type TEXT,"
-        "  checksum_value TEXT)";
+        "  checksum_type TEXT)";
 
     rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
     if (rc != SQLITE_OK) {
@@ -372,7 +371,7 @@ yum_db_create_primary_tables (sqlite3 *db, GError **err)
         "CREATE TABLE files ("
         "  name TEXT,"
         "  type TEXT,"
-        "  pkgKey TEXT)";
+        "  pkgKey INTEGER)";
     rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
     if (rc != SQLITE_OK) {
         g_set_error (err, YUM_DB_ERROR, YUM_DB_ERROR,
@@ -385,10 +384,10 @@ yum_db_create_primary_tables (sqlite3 *db, GError **err)
         "CREATE TABLE %s ("
         "  name TEXT,"
         "  flags TEXT,"
-        "  epoch TEXT,"
+        "  epoch INTEGER,"
         "  version TEXT,"
         "  release TEXT,"
-        "  pkgKey TEXT %s)";
+        "  pkgKey INTEGER %s)";
 
     const char *deps[] = { "requires", "provides", "conflicts", "obsoletes", NULL };
     int i;
@@ -468,9 +467,9 @@ yum_db_package_prepare (sqlite3 *db, GError **err)
         "  url, time_file, time_build, rpm_license, rpm_vendor, rpm_group,"
         "  rpm_buildhost, rpm_sourcerpm, rpm_header_start, rpm_header_end,"
         "  rpm_packager, size_package, size_installed, size_archive,"
-        "  location_href, location_base, checksum_type, checksum_value) "
+        "  location_href, location_base, checksum_type) "
         "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
-        "  ?, ?, ?, ?, ?, ?, ?, ?)";
+        "  ?, ?, ?, ?, ?, ?, ?)";
 
     rc = sqlite3_prepare (db, query, -1, &handle, NULL);
     if (rc != SQLITE_OK) {
@@ -493,28 +492,27 @@ yum_db_package_write (sqlite3 *db, sqlite3_stmt *handle, Package *p)
     sqlite3_bind_text (handle, 2,  p->name, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 3,  p->arch, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 4,  p->version, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 5,  p->epoch, -1, SQLITE_STATIC);
+    sqlite3_bind_int  (handle, 5,  p->epoch);
     sqlite3_bind_text (handle, 6,  p->release, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 7,  p->summary, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 8,  p->description, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 9,  p->url, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 10, p->time_file, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 11, p->time_build, -1, SQLITE_STATIC);
+    sqlite3_bind_int  (handle, 10, p->time_file);
+    sqlite3_bind_int  (handle, 11, p->time_build);
     sqlite3_bind_text (handle, 12, p->rpm_license, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 13, p->rpm_vendor, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 14, p->rpm_group, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 15, p->rpm_buildhost, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 16, p->rpm_sourcerpm, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 17, p->rpm_header_start, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 18, p->rpm_header_end, -1, SQLITE_STATIC);
+    sqlite3_bind_int  (handle, 17, p->rpm_header_start);
+    sqlite3_bind_int  (handle, 18, p->rpm_header_end);
     sqlite3_bind_text (handle, 19, p->rpm_packager, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 20, p->size_package, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 21, p->size_installed, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 22, p->size_archive, -1, SQLITE_STATIC);
+    sqlite3_bind_int  (handle, 20, p->size_package);
+    sqlite3_bind_int  (handle, 21, p->size_installed);
+    sqlite3_bind_int  (handle, 22, p->size_archive);
     sqlite3_bind_text (handle, 23, p->location_href, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 24, p->location_base, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 25, p->checksum_type, -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 26, p->checksum_value, -1, SQLITE_STATIC);
 
     rc = sqlite3_step (handle);
     sqlite3_reset (handle);
@@ -572,7 +570,7 @@ yum_db_dependency_write (sqlite3 *db,
 
     sqlite3_bind_text (handle, 1, dep->name,    -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 2, dep->flags,   -1, SQLITE_STATIC);
-    sqlite3_bind_text (handle, 3, dep->epoch,   -1, SQLITE_STATIC);
+    sqlite3_bind_int  (handle, 3, dep->epoch);
     sqlite3_bind_text (handle, 4, dep->version, -1, SQLITE_STATIC);
     sqlite3_bind_text (handle, 5, dep->release, -1, SQLITE_STATIC);
     sqlite3_bind_int  (handle, 6, pkgKey);
@@ -822,7 +820,7 @@ yum_db_create_other_tables (sqlite3 *db, GError **err)
         "CREATE TABLE changelog ("
         "  pkgKey INTEGER,"
         "  author TEXT,"
-        "  date TEXT,"
+        "  date INTEGER,"
         "  changelog TEXT)";
     rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
     if (rc != SQLITE_OK) {
@@ -900,7 +898,7 @@ yum_db_changelog_write (sqlite3 *db, sqlite3_stmt *handle, Package *p)
 
         sqlite3_bind_int  (handle, 1, p->pkgKey);
         sqlite3_bind_text (handle, 2, entry->author, -1, SQLITE_STATIC);
-        sqlite3_bind_text (handle, 3, entry->date, -1, SQLITE_STATIC);
+        sqlite3_bind_int  (handle, 3, entry->date);
         sqlite3_bind_text (handle, 4, entry->changelog, -1, SQLITE_STATIC);
 
         rc = sqlite3_step (handle);
diff --git a/db.h b/db.h
index d58762d..a91d329 100644
--- a/db.h
+++ b/db.h
@@ -22,7 +22,7 @@
 #include <sqlite3.h>
 #include "package.h"
 
-#define YUM_SQLITE_CACHE_DBVERSION 9
+#define YUM_SQLITE_CACHE_DBVERSION 10
 
 #define YUM_DB_ERROR yum_db_error_quark()
 GQuark yum_db_error_quark (void);
diff --git a/package.h b/package.h
index 4335929..4d71cc9 100644
--- a/package.h
+++ b/package.h
@@ -23,7 +23,7 @@
 typedef struct {
     char *name;
     char *flags;
-    char *epoch;
+    gint64 epoch;
     char *version;
     char *release;
     gboolean pre;
@@ -36,7 +36,7 @@ typedef struct {
 
 typedef struct {
     char *author;
-    char *date;
+    gint64 date;
     char *changelog;
 } ChangelogEntry;
 
@@ -46,28 +46,27 @@ typedef struct {
     char *name;
     char *arch;
     char *version;
-    char *epoch;
+    gint64 epoch;
     char *release;
     char *summary;
     char *description;
     char *url;
-    char *time_file;
-    char *time_build;
+    gint64 time_file;
+    gint64 time_build;
     char *rpm_license;
     char *rpm_vendor;
     char *rpm_group;
     char *rpm_buildhost;
     char *rpm_sourcerpm;
-    char *rpm_header_start;
-    char *rpm_header_end;
+    gint64 rpm_header_start;
+    gint64 rpm_header_end;
     char *rpm_packager;
-    char *size_package;
-    char *size_installed;
-    char *size_archive;
+    gint64 size_package;
+    gint64 size_installed;
+    gint64 size_archive;
     char *location_href;
     char *location_base;
     char *checksum_type;
-    char *checksum_value;
 
     GSList *requires;
     GSList *provides;
diff --git a/xml-parser.c b/xml-parser.c
index 2db9443..767027b 100644
--- a/xml-parser.c
+++ b/xml-parser.c
@@ -116,7 +116,7 @@ parse_version_info(const char **attrs, Package *p)
         value = attrs[++i];
 
         if (!strcmp (attr, "epoch"))
-            p->epoch = g_string_chunk_insert (p->chunk, value);
+            p->epoch = strtol(value, NULL, 10);
         else if (!strcmp (attr, "ver"))
             p->version = g_string_chunk_insert (p->chunk, value);
         else if (!strcmp (attr, "rel"))
@@ -162,9 +162,9 @@ primary_parser_package_start (PrimarySAXContext *ctx,
             value = attrs[++i];
 
             if (!strcmp (attr, "file"))
-                p->time_file = g_string_chunk_insert (p->chunk, value);
+                p->time_file = strtol(value, NULL, 10);
             else if (!strcmp (attr, "build"))
-                p->time_build = g_string_chunk_insert (p->chunk, value);
+                p->time_build = strtol(value, NULL, 10);
         }
     }
 
@@ -174,11 +174,11 @@ primary_parser_package_start (PrimarySAXContext *ctx,
             value = attrs[++i];
 
             if (!strcmp (attr, "package"))
-                p->size_package = g_string_chunk_insert (p->chunk, value);
+                p->size_package = strtol(value, NULL, 10);
             else if (!strcmp (attr, "installed"))
-                p->size_installed = g_string_chunk_insert (p->chunk, value);
+                p->size_installed = strtol(value, NULL, 10);
             else if (!strcmp (attr, "archive"))
-                p->size_archive = g_string_chunk_insert (p->chunk, value);
+                p->size_archive = strtol(value, NULL, 10);
         }
     }
 
@@ -213,9 +213,9 @@ primary_parser_format_start (PrimarySAXContext *ctx,
             value = attrs[++i];
 
             if (!strcmp (attr, "start"))
-                p->rpm_header_start = g_string_chunk_insert (p->chunk, value);
+                p->rpm_header_start = strtol(value, NULL, 10);
             else if (!strcmp (attr, "end"))
-                p->rpm_header_end = g_string_chunk_insert (p->chunk, value);
+                p->rpm_header_end = strtol(value, NULL, 10);
         }
     }
 
@@ -295,7 +295,7 @@ primary_parser_dep_start (PrimarySAXContext *ctx,
             if (tmp_flags)
                 dep->flags = g_string_chunk_insert (chunk, tmp_flags);
             if (tmp_epoch)
-                dep->epoch = g_string_chunk_insert (chunk, tmp_epoch);
+                dep->epoch = strtol(tmp_epoch, NULL, 10);
             if (tmp_version)
                 dep->version = g_string_chunk_insert (chunk, tmp_version);
             if (tmp_release)
@@ -366,10 +366,9 @@ primary_parser_package_end (PrimarySAXContext *ctx, const char *name)
                                              ctx->text_buffer->str,
                                              ctx->text_buffer->len);
     else if (!strcmp (name, "checksum"))
-        p->checksum_value = p->pkgId =
-            g_string_chunk_insert_len (p->chunk,
-                                       ctx->text_buffer->str,
-                                       ctx->text_buffer->len);
+        p->pkgId = g_string_chunk_insert_len (p->chunk,
+                                              ctx->text_buffer->str,
+                                              ctx->text_buffer->len);
     else if (!strcmp (name, "summary"))
         p->summary = g_string_chunk_insert_len (p->chunk,
                                                 ctx->text_buffer->str,
@@ -928,8 +927,7 @@ other_parser_package_start (OtherSAXContext *ctx,
                 ctx->current_entry->author =
                     g_string_chunk_insert_const (p->chunk, value);
             else if (!strcmp (attr, "date"))
-                ctx->current_entry->date =
-                    g_string_chunk_insert_const (p->chunk, value);
+                ctx->current_entry->date = strtol(value, NULL, 10);
         }
     }
 }
diff --git a/output.py b/output.py
index 6cc7d7e..d3f58cf 100644
--- a/output.py
+++ b/output.py
@@ -63,7 +63,7 @@ class YumOutput:
     def infoOutput(self, pkg):
         print _("Name   : %s") % pkg.name
         print _("Arch   : %s") % pkg.arch
-        if pkg.epoch != "0":
+        if pkg.epoch != 0:
             print _("Epoch  : %s") % pkg.epoch
         print _("Version: %s") % pkg.version
         print _("Release: %s") % pkg.release
diff --git a/rpmUtils/miscutils.py b/rpmUtils/miscutils.py
index f36122f..dc5a52e 100644
--- a/rpmUtils/miscutils.py
+++ b/rpmUtils/miscutils.py
@@ -311,17 +311,17 @@ def flagToString(flags):
     return flags
 
 def stringToVersion(verstring):
-    if verstring in [None, '']:
+    if not verstring:
         return (None, None, None)
     i = verstring.find(':')
     if i != -1:
         try:
-            epoch = str(long(verstring[:i]))
+            epoch = long(verstring[:i])
         except ValueError:
             # look, garbage in the epoch field, how fun, kill it
-            epoch = '0' # this is our fallback, deal
+            epoch = 0 # this is our fallback, deal
     else:
-        epoch = '0'
+        epoch = 0
     j = verstring.find('-')
     if j != -1:
         if verstring[i + 1:j] == '':
diff --git a/yum/constants.py b/yum/constants.py
index ab0ae90..e1c12a9 100644
--- a/yum/constants.py
+++ b/yum/constants.py
@@ -72,7 +72,7 @@ PLUG_OPT_WHERE_REPO = 1
 PLUG_OPT_WHERE_ALL = 2
 
 # version of sqlite database schemas
-DBVERSION = '9'
+DBVERSION = '10'
 
 # boolean dict:
 BOOLEAN_STATES = {'1': True, 'yes': True, 'true': True, 'on': True,
diff --git a/yum/packages.py b/yum/packages.py
index 2965cfd..1372acd 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -706,11 +706,9 @@ class YumHeaderPackage(YumAvailablePackage):
         return self.hdr[thing]
 
     def doepoch(self):
-        tmpepoch = self.hdr['epoch']
-        if tmpepoch is None:
-            epoch = '0'
-        else:
-            epoch = str(tmpepoch)
+        epoch = self.hdr['epoch']
+        if epoch is None:
+            epoch = 0
         
         return epoch
 
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index 16f0829..2d3c0c7 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -291,10 +291,8 @@ class RPMDBPackageSack(PackageSackBase):
         rel = str(hdr['release'])
         epoch = hdr['epoch']
         if epoch is None:
-            epoch = '0'
-        else:
-            epoch = str(epoch)
-    
+            epoch = 0
+
         return (name, arch, epoch, ver, rel)
 
     # deprecated options for compat only - remove once rpmdb is converted:
@@ -363,7 +361,7 @@ class RPMDBPackageSack(PackageSackBase):
 
         # Normalise epoch
         if epoch in (None, 0, '(none)', ''):
-            epoch = '0'
+            epoch = 0
 
         out = []
         for hdr, tup, idx in self._search(name, epoch, version, release, arch):
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index 4e952a3..4102f37 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -71,7 +71,7 @@ class YumAvailablePackageSqlite(YumAvailablePackage, PackageObject, RpmBase):
                 pass
 
         try:
-            self._checksums.append((db_obj['checksum_type'], db_obj['checksum_value'], True))
+            self._checksums.append((db_obj['checksum_type'], db_obj['pkgId'], True))
         except (IndexError, KeyError):
             pass
 
@@ -159,7 +159,7 @@ class YumAvailablePackageSqlite(YumAvailablePackage, PackageObject, RpmBase):
     
         
     def returnIdSum(self):
-            return (self.checksum_type, self.checksum_value)
+            return (self.checksum_type, self.pkgId)
     
     def returnChangelog(self):
         self._loadChangelog()
@@ -539,7 +539,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
         y.hdrange = {'start': db['rpm_header_start'],'end': db['rpm_header_end']}
         y.location = {'href': db['location_href'],'value': '', 'base': db['location_base']}
         y.checksum = {'pkgid': 'YES','type': db['checksum_type'], 
-                    'value': db['checksum_value'] }
+                    'value': db['pkgId'] }
         y.time = {'build': db['time_build'], 'file': db['time_file'] }
         y.size = {'package': db['size_package'], 'archive': db['size_archive'], 'installed': db['size_installed'] }
         y.info = {'summary': db['summary'], 'description': db['description'],

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel

Reply via email to