hope to fix sync problems of multiple cache writers
flush, invalidate where needed
This commit is contained in:
@@ -62,10 +62,6 @@ def _cleanup():
|
|||||||
if filesdb.is_initialized():
|
if filesdb.is_initialized():
|
||||||
filesdb.close()
|
filesdb.close()
|
||||||
|
|
||||||
installdb = pisi.db.installdb.InstallDB()
|
|
||||||
if installdb.is_initialized():
|
|
||||||
installdb.close()
|
|
||||||
|
|
||||||
if ctx.build_leftover and os.path.exists(ctx.build_leftover):
|
if ctx.build_leftover and os.path.exists(ctx.build_leftover):
|
||||||
os.unlink(ctx.build_leftover)
|
os.unlink(ctx.build_leftover)
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -65,8 +65,10 @@ def locked(func):
|
|||||||
raise pisi.errors.AnotherInstanceError(_("Another instance of PiSi is running. Only one instance is allowed."))
|
raise pisi.errors.AnotherInstanceError(_("Another instance of PiSi is running. Only one instance is allowed."))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
pisi.db.invalidate_caches()
|
||||||
return func(*__args,**__kw)
|
return func(*__args,**__kw)
|
||||||
finally:
|
finally:
|
||||||
|
pisi.db.update_caches()
|
||||||
lock.close()
|
lock.close()
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@@ -646,6 +648,7 @@ def add_repo(name, indexuri, at = None):
|
|||||||
else:
|
else:
|
||||||
repo = pisi.db.repodb.Repo(pisi.uri.URI(indexuri))
|
repo = pisi.db.repodb.Repo(pisi.uri.URI(indexuri))
|
||||||
repodb.add_repo(name, repo, at = at)
|
repodb.add_repo(name, repo, at = at)
|
||||||
|
pisi.db.flush_caches()
|
||||||
ctx.ui.info(_('Repo %s added to system.') % name)
|
ctx.ui.info(_('Repo %s added to system.') % name)
|
||||||
|
|
||||||
@locked
|
@locked
|
||||||
@@ -653,6 +656,7 @@ def remove_repo(name):
|
|||||||
repodb = pisi.db.repodb.RepoDB()
|
repodb = pisi.db.repodb.RepoDB()
|
||||||
if repodb.has_repo(name):
|
if repodb.has_repo(name):
|
||||||
repodb.remove_repo(name)
|
repodb.remove_repo(name)
|
||||||
|
pisi.db.flush_caches()
|
||||||
ctx.ui.info(_('Repo %s removed from system.') % name)
|
ctx.ui.info(_('Repo %s removed from system.') % name)
|
||||||
else:
|
else:
|
||||||
raise pisi.Error(_('Repository %s does not exist. Cannot remove.')
|
raise pisi.Error(_('Repository %s does not exist. Cannot remove.')
|
||||||
@@ -663,14 +667,13 @@ def update_repos(repos, force=False):
|
|||||||
pisi.db.historydb.HistoryDB().create_history("repoupdate")
|
pisi.db.historydb.HistoryDB().create_history("repoupdate")
|
||||||
for repo in repos:
|
for repo in repos:
|
||||||
__update_repo(repo, force)
|
__update_repo(repo, force)
|
||||||
pisi.db.reload()
|
pisi.db.flush_caches()
|
||||||
|
|
||||||
|
|
||||||
@locked
|
@locked
|
||||||
def update_repo(repo, force=False):
|
def update_repo(repo, force=False):
|
||||||
pisi.db.historydb.HistoryDB().create_history("repoupdate")
|
pisi.db.historydb.HistoryDB().create_history("repoupdate")
|
||||||
__update_repo(repo, force)
|
__update_repo(repo, force)
|
||||||
pisi.db.reload()
|
pisi.db.flush_caches()
|
||||||
|
|
||||||
def __update_repo(repo, force=False):
|
def __update_repo(repo, force=False):
|
||||||
ctx.ui.info(_('* Updating repository: %s') % repo)
|
ctx.ui.info(_('* Updating repository: %s') % repo)
|
||||||
|
|||||||
+15
-5
@@ -10,9 +10,19 @@
|
|||||||
# Please read the COPYING file.
|
# Please read the COPYING file.
|
||||||
#
|
#
|
||||||
|
|
||||||
import pisi
|
def invalidate_caches():
|
||||||
|
# Invalidates pisi caches in use and forces to re-fill caches from disk when needed
|
||||||
|
for db in [packagedb.PackageDB(), sourcedb.SourceDB(), componentdb.ComponentDB(), installdb.InstallDB()]:
|
||||||
|
db.invalidate()
|
||||||
|
|
||||||
def reload():
|
def flush_caches():
|
||||||
pisi.db.packagedb.PackageDB().reload()
|
# Invalidate and flush caches to re-generate them when needed
|
||||||
pisi.db.sourcedb.SourceDB().reload()
|
for db in [packagedb.PackageDB(), sourcedb.SourceDB(), componentdb.ComponentDB()]:
|
||||||
pisi.db.componentdb.ComponentDB().reload()
|
db.invalidate()
|
||||||
|
db.cache_flush()
|
||||||
|
|
||||||
|
def update_caches():
|
||||||
|
# Updates ondisk caches
|
||||||
|
for db in [packagedb.PackageDB(), sourcedb.SourceDB(), componentdb.ComponentDB(), installdb.InstallDB()]:
|
||||||
|
if db.is_initialized():
|
||||||
|
db.cache_save()
|
||||||
|
|||||||
+14
-12
@@ -16,10 +16,17 @@ import time
|
|||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
|
|
||||||
class Singleton(object):
|
class Singleton(object):
|
||||||
|
_the_instances = {}
|
||||||
def __new__(type):
|
def __new__(type):
|
||||||
if not '_the_instance' in type.__dict__:
|
if not type.__name__ in Singleton._the_instances:
|
||||||
type._the_instance = object.__new__(type)
|
Singleton._the_instances[type.__name__] = object.__new__(type)
|
||||||
return type._the_instance
|
return Singleton._the_instances[type.__name__]
|
||||||
|
|
||||||
|
def _instance(self):
|
||||||
|
return self._the_instances[type(self).__name__]
|
||||||
|
|
||||||
|
def _delete(self):
|
||||||
|
del self._the_instances[type(self).__name__]
|
||||||
|
|
||||||
class LazyDB(Singleton):
|
class LazyDB(Singleton):
|
||||||
def __init__(self, cacheable=False):
|
def __init__(self, cacheable=False):
|
||||||
@@ -32,12 +39,12 @@ class LazyDB(Singleton):
|
|||||||
|
|
||||||
def cache_save(self):
|
def cache_save(self):
|
||||||
if os.access("/var/cache/pisi", os.W_OK) and self.cacheable:
|
if os.access("/var/cache/pisi", os.W_OK) and self.cacheable:
|
||||||
cPickle.dump(self.__class__._the_instance.__dict__,
|
cPickle.dump(self._instance().__dict__,
|
||||||
file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'wb'), 1)
|
file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'wb'), 1)
|
||||||
|
|
||||||
def cache_load(self):
|
def cache_load(self):
|
||||||
if os.path.exists("/var/cache/pisi/%s.cache" % self.__class__.__name__.lower()):
|
if os.path.exists("/var/cache/pisi/%s.cache" % self.__class__.__name__.lower()):
|
||||||
self.__class__._the_instance.__dict__ = cPickle.load(file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'rb'))
|
self._instance().__dict__ = cPickle.load(file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'rb'))
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -46,17 +53,12 @@ class LazyDB(Singleton):
|
|||||||
if os.path.exists(cache_file):
|
if os.path.exists(cache_file):
|
||||||
os.unlink(cache_file)
|
os.unlink(cache_file)
|
||||||
|
|
||||||
def reload(self):
|
def invalidate(self):
|
||||||
self.cache_flush()
|
self._delete()
|
||||||
self.__init()
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
self.cache_save()
|
|
||||||
|
|
||||||
def __init(self):
|
def __init(self):
|
||||||
if not self.cache_load():
|
if not self.cache_load():
|
||||||
self.init()
|
self.init()
|
||||||
self.cache_save()
|
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if not attr == "__setstate__" and not self.initialized:
|
if not attr == "__setstate__" and not self.initialized:
|
||||||
|
|||||||
Reference in New Issue
Block a user