changeset 2808:3a007d806f0f beta

Fixing issues of cache invalidation for multiple instances running in rhodecode. - during server start always register all cache keys for all repositories - Don't clear cache markers on start since multiple instances can clear each other out
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 05 Sep 2012 22:09:25 +0200
parents 57456b1c215b
children 070d2eacd48b
files rhodecode/lib/utils.py rhodecode/model/db.py
diffstat 2 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/utils.py	Wed Sep 05 20:24:21 2012 +0200
+++ b/rhodecode/lib/utils.py	Wed Sep 05 22:09:25 2012 +0200
@@ -413,6 +413,11 @@
         raise Exception('Missing administrative account !')
     added = []
 
+#    # clear cache keys
+#    log.debug("Clearing cache keys now...")
+#    CacheInvalidation.clear_cache()
+#    sa.commit()
+
     for name, repo in initial_repo_list.items():
         group = map_groups(name)
         db_repo = rm.get_by_repo_name(name)
@@ -438,6 +443,10 @@
         elif install_git_hook:
             if db_repo.repo_type == 'git':
                 ScmModel().install_git_hook(db_repo.scm_instance)
+        # during starting install all cache keys for all repositories in the
+        # system, this will register all repos and multiple instances
+        key, _prefix, _org_key = CacheInvalidation._get_key(name)
+        CacheInvalidation._get_or_create_key(key, _prefix, _org_key, commit=False)
     sa.commit()
     removed = []
     if remove_obsolete:
@@ -455,10 +464,6 @@
                     log.error(traceback.format_exc())
                     sa.rollback()
 
-    # clear cache keys
-    log.debug("Clearing cache keys now...")
-    CacheInvalidation.clear_cache()
-    sa.commit()
     return added, removed
 
 
--- a/rhodecode/model/db.py	Wed Sep 05 20:24:21 2012 +0200
+++ b/rhodecode/model/db.py	Wed Sep 05 22:09:25 2012 +0200
@@ -1425,13 +1425,14 @@
         return cls.query().filter(cls.cache_key == key).scalar()
 
     @classmethod
-    def _get_or_create_key(cls, key, prefix, org_key):
+    def _get_or_create_key(cls, key, prefix, org_key, commit=True):
         inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar()
         if not inv_obj:
             try:
                 inv_obj = CacheInvalidation(key, org_key)
                 Session().add(inv_obj)
-                Session().commit()
+                if commit:
+                    Session().commit()
             except Exception:
                 log.error(traceback.format_exc())
                 Session().rollback()