comparison rhodecode/lib/utils.py @ 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 ffaaeb5a5a69
children 070d2eacd48b
comparison
equal deleted inserted replaced
2807:57456b1c215b 2808:3a007d806f0f
410 rm = RepoModel() 410 rm = RepoModel()
411 user = sa.query(User).filter(User.admin == True).first() 411 user = sa.query(User).filter(User.admin == True).first()
412 if user is None: 412 if user is None:
413 raise Exception('Missing administrative account !') 413 raise Exception('Missing administrative account !')
414 added = [] 414 added = []
415
416 # # clear cache keys
417 # log.debug("Clearing cache keys now...")
418 # CacheInvalidation.clear_cache()
419 # sa.commit()
415 420
416 for name, repo in initial_repo_list.items(): 421 for name, repo in initial_repo_list.items():
417 group = map_groups(name) 422 group = map_groups(name)
418 db_repo = rm.get_by_repo_name(name) 423 db_repo = rm.get_by_repo_name(name)
419 # found repo that is on filesystem not in RhodeCode database 424 # found repo that is on filesystem not in RhodeCode database
436 if new_repo.repo_type == 'git': 441 if new_repo.repo_type == 'git':
437 ScmModel().install_git_hook(new_repo.scm_instance) 442 ScmModel().install_git_hook(new_repo.scm_instance)
438 elif install_git_hook: 443 elif install_git_hook:
439 if db_repo.repo_type == 'git': 444 if db_repo.repo_type == 'git':
440 ScmModel().install_git_hook(db_repo.scm_instance) 445 ScmModel().install_git_hook(db_repo.scm_instance)
446 # during starting install all cache keys for all repositories in the
447 # system, this will register all repos and multiple instances
448 key, _prefix, _org_key = CacheInvalidation._get_key(name)
449 CacheInvalidation._get_or_create_key(key, _prefix, _org_key, commit=False)
441 sa.commit() 450 sa.commit()
442 removed = [] 451 removed = []
443 if remove_obsolete: 452 if remove_obsolete:
444 # remove from database those repositories that are not in the filesystem 453 # remove from database those repositories that are not in the filesystem
445 for repo in sa.query(Repository).all(): 454 for repo in sa.query(Repository).all():
453 except: 462 except:
454 #don't hold further removals on error 463 #don't hold further removals on error
455 log.error(traceback.format_exc()) 464 log.error(traceback.format_exc())
456 sa.rollback() 465 sa.rollback()
457 466
458 # clear cache keys
459 log.debug("Clearing cache keys now...")
460 CacheInvalidation.clear_cache()
461 sa.commit()
462 return added, removed 467 return added, removed
463 468
464 469
465 # set cache regions for beaker so celery can utilise it 470 # set cache regions for beaker so celery can utilise it
466 def add_cache(settings): 471 def add_cache(settings):