From dbf6376544af8ff4a839d4ecf5919eec96a70df8 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Wed, 1 Aug 2007 13:15:43 +0000 Subject: [PATCH] - implement disk usage basic infrastructure for cache store - todo: retrieving it - make changelog and filelist api similar to the other functions --- zypp/cache/CacheInitializer.h | 2 +- zypp/cache/CacheStore.cc | 38 +++++++++++++++++++++++++++++++++----- zypp/cache/CacheStore.h | 22 ++++++++++++++++++---- zypp/cache/schema/schema.sql | 34 +++++++++++++++++++++++++++++++++- zypp/data/ResolvableDataConsumer.h | 9 ++++++--- zypp/parser/yum/RepoParser.cc | 4 ++-- 6 files changed, 93 insertions(+), 16 deletions(-) diff --git a/zypp/cache/CacheInitializer.h b/zypp/cache/CacheInitializer.h index 084e547..61a41ef 100644 --- a/zypp/cache/CacheInitializer.h +++ b/zypp/cache/CacheInitializer.h @@ -19,7 +19,7 @@ #include "zypp/Pathname.h" #include "zypp/cache/sqlite3x/sqlite3x.hpp" -#define ZYPP_CACHE_SCHEMA_VERSION 1000 +#define ZYPP_CACHE_SCHEMA_VERSION 1001 /////////////////////////////////////////////////////////////////// namespace zypp diff --git a/zypp/cache/CacheStore.cc b/zypp/cache/CacheStore.cc index cedffdc..27cb0e6 100644 --- a/zypp/cache/CacheStore.cc +++ b/zypp/cache/CacheStore.cc @@ -128,7 +128,11 @@ struct CacheStore::Impl "insert into patch_packages_baseversions (patch_package_id, version, release, epoch) " "values (:patch_package_id, :version, :release, :epoch)" )); - + update_disk_usage_cmd.reset( new sqlite3_command (con, + "insert or replace into resolvable_disk_usage (resolvable_id, dir_name_id, files, size) " + "values (:resolvable_id, :dir_name_id, :files, :size)" )); + + // disable autocommit con.executenonquery("BEGIN;"); } @@ -190,6 +194,8 @@ struct CacheStore::Impl sqlite3_command_ptr insert_deltarpm_cmd; sqlite3_command_ptr append_patch_baseversion_cmd; + sqlite3_command_ptr update_disk_usage_cmd; + map name_cache; map< pair, RecordId> type_cache; int name_cache_hits; @@ -412,8 +418,7 @@ RecordId CacheStore::consumeProduct( const data::RecordId & repository_id, return id; } -RecordId CacheStore::consumeChangelog( const data::RecordId & repository_id, - const data::Resolvable_Ptr & resolvable, +RecordId CacheStore::consumeChangelog( const data::RecordId &resolvable_id, const Changelog & changelog ) { //! \todo maybe appendChangelog(const data::RecordId & resolvable_id, Changelog changelog) will be needed @@ -422,14 +427,37 @@ RecordId CacheStore::consumeChangelog( const data::RecordId & repository_id, return data::noRecordId; } -RecordId CacheStore::consumeFilelist( const data::RecordId & repository_id, - const data::Resolvable_Ptr & resolvable, +RecordId CacheStore::consumeFilelist( const data::RecordId &resolvable_id, const data::Filenames & filenames ) { //! \todo maybe consumeFilelist(const data::RecordId & resolvable_id, data::Filenames &) will be needed return data::noRecordId; } +void CacheStore::consumeDiskUsage( const data::RecordId &resolvable_id, + const DiskUsage &disk ) +{ + // iterate over entries + for ( DiskUsage::const_iterator it = disk.begin(); + it != disk.end(); + ++it ) + { + data::RecordId dirid = lookupOrAppendDirName( (*it).path ); + try + { + _pimpl->update_disk_usage_cmd->bind(":resolvable_id", resolvable_id); + _pimpl->update_disk_usage_cmd->bind(":dir_name_id", dirid); + _pimpl->update_disk_usage_cmd->bind(":files", (int)(*it)._files ); + _pimpl->update_disk_usage_cmd->bind(":size", (int)(*it)._size ); + _pimpl->update_disk_usage_cmd->executenonquery(); + } + catch ( const sqlite3x::database_error &e ) + { + ZYPP_RETHROW(e); + } + } +} + void CacheStore::updatePackageLang( const data::RecordId & resolvable_id, const data::Packagebase_Ptr & data_r ) { diff --git a/zypp/cache/CacheStore.h b/zypp/cache/CacheStore.h index b940f94..447d914 100644 --- a/zypp/cache/CacheStore.h +++ b/zypp/cache/CacheStore.h @@ -169,8 +169,7 @@ namespace zypp * \param changelog the changelog * \todo see implementation */ - virtual data::RecordId consumeChangelog( const data::RecordId & repository_id, - const data::Resolvable_Ptr & resolvable, + virtual data::RecordId consumeChangelog( const data::RecordId & resolvable_id, const Changelog & changelog ); /** @@ -182,9 +181,24 @@ namespace zypp * \param filenames list of filenames the resolvable contains * \todo see implementation */ - virtual data::RecordId consumeFilelist( const data::RecordId &repository_id, - const data::Resolvable_Ptr & resolvable, + virtual data::RecordId consumeFilelist( const data::RecordId & resolvable_id, const data::Filenames & filenames ); + + /** + * Implementation of the \ref ResolvableDataConsumer interface + * + * Consume disk usage of a resolvable, inserting it in the cache. + * + * Repeated entries are updated (replaced) + * + * \param repository_id ownership. + * \param resolvable resolvable for which the filelist is to be saved + * \param disk Disk usage object + * \todo see implementation + */ + virtual void consumeDiskUsage( const data::RecordId &resolvable_id, + const DiskUsage &disk ); + /** * Implementation of the \ref ResolvableDataConsumer interface diff --git a/zypp/cache/schema/schema.sql b/zypp/cache/schema/schema.sql index d0739e2..30a3a41 100644 --- a/zypp/cache/schema/schema.sql +++ b/zypp/cache/schema/schema.sql @@ -258,7 +258,34 @@ CREATE TABLE split_capabilities ( ); CREATE INDEX split_capabilities_resolvable ON split_capabilities(resolvable_id); --- Auto clean capabilities +------------------------------------------------ +-- File list +------------------------------------------------ + +CREATE TABLE resolvable_files ( + resolvable_id INTEGER REFERENCES resolvables (id) + , file_id INTEGER REFERENCES files (id) + , PRIMARY KEY ( resolvable_id, file_id ) +); + +------------------------------------------------ +-- Disk usage +------------------------------------------------ + +CREATE TABLE resolvable_disk_usage ( + resolvable_id INTEGER REFERENCES resolvables (id) + , dir_name_id INTEGER REFERENCES dir_name (id) + , files INTEGER + , size INTEGER + , PRIMARY KEY ( resolvable_id, dir_name_id ) +); +CREATE INDEX disk_usage_resolvable_id ON resolvable_disk_usage(resolvable_id); +CREATE INDEX disk_usage_dir_name_id ON resolvable_disk_usage(dir_name_id); + +------------------------------------------------ +-- Cleanup +------------------------------------------------ + CREATE TRIGGER remove_resolvables AFTER DELETE ON resolvables BEGIN @@ -271,8 +298,13 @@ CREATE TRIGGER remove_resolvables DELETE FROM text_attributes WHERE weak_resolvable_id = old.id; DELETE FROM numeric_attributes WHERE weak_resolvable_id = old.id; + DELETE FROM resolvable_disk_usage WHERE resolvable_id = old.id; + DELETE FROM resolvable_files WHERE resolvable_id = old.id; END; + + + ------------------------------------------------ -- Associate resolvables and repositories ------------------------------------------------ diff --git a/zypp/data/ResolvableDataConsumer.h b/zypp/data/ResolvableDataConsumer.h index 5141db0..844af57 100644 --- a/zypp/data/ResolvableDataConsumer.h +++ b/zypp/data/ResolvableDataConsumer.h @@ -11,6 +11,7 @@ #define ZYPP_ResolvableDataConsumer_H +#include "zypp/DiskUsage.h" #include "zypp/data/RecordId.h" #include "zypp/data/ResolvableData.h" @@ -37,10 +38,12 @@ namespace data virtual data::RecordId consumeScript ( const data::RecordId & repository_id, const data::Script_Ptr & ) = 0; virtual data::RecordId consumePattern ( const data::RecordId & repository_id, const data::Pattern_Ptr & ) = 0; - virtual data::RecordId consumeChangelog ( const data::RecordId & repository_id, const data::Resolvable_Ptr &, const Changelog & ) = 0; - virtual data::RecordId consumeFilelist ( const data::RecordId & repository_id, const data::Resolvable_Ptr &, const data::Filenames & ) = 0; - + virtual data::RecordId consumeChangelog ( const data::RecordId & resolvable_id, const Changelog & ) = 0; + virtual data::RecordId consumeFilelist ( const data::RecordId & resolvable_id, const data::Filenames & ) = 0; + virtual void consumeDiskUsage ( const data::RecordId &resolvable_id, const DiskUsage &disk ) = 0; + virtual void updatePackageLang( const data::RecordId & resolvable_id, const data::Packagebase_Ptr & data_r ) = 0; + }; } // namespace parser diff --git a/zypp/parser/yum/RepoParser.cc b/zypp/parser/yum/RepoParser.cc index 82d76e5..e941413 100644 --- a/zypp/parser/yum/RepoParser.cc +++ b/zypp/parser/yum/RepoParser.cc @@ -246,7 +246,7 @@ namespace zypp bool RepoParser::Impl::other_CB( const data::Resolvable_Ptr & res_ptr, const Changelog & changelog) { - _consumer.consumeChangelog(_repository_id, res_ptr, changelog); + //_consumer.consumeChangelog(_repository_id, res_ptr, changelog); /* DBG << "got changelog for " << res_ptr->name << res_ptr->edition << " " @@ -263,7 +263,7 @@ namespace zypp bool RepoParser::Impl::filelist_CB( const data::Resolvable_Ptr & res_ptr, const data::Filenames & filenames) { - _consumer.consumeFilelist(_repository_id, res_ptr, filenames); + //_consumer.consumeFilelist(_repository_id, res_ptr, filenames); /* DBG << "got filelist for " << res_ptr->name << res_ptr->edition << " " -- 2.7.4