##// END OF EJS Templates
feat: svn hooks are mandatory and blocking from now on
feat: svn hooks are mandatory and blocking from now on

File last commit:

r1127:367165a5 python3
r1231:0970c42d default
Show More
archive_cache.py
87 lines | 2.7 KiB | text/x-python | PythonLexer
# RhodeCode VCSServer provides access to different vcs backends via network.
# Copyright (C) 2014-2023 RhodeCode GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import logging
import os
import diskcache
from diskcache import RLock
log = logging.getLogger(__name__)
cache_meta = None
class ReentrantLock(RLock):
def __enter__(self):
reentrant_lock_key = self._key
log.debug('Acquire ReentrantLock(key=%s) for archive cache generation...', reentrant_lock_key)
#self.acquire()
log.debug('Lock for key=%s acquired', reentrant_lock_key)
def __exit__(self, *exc_info):
#self.release()
pass
def get_archival_config(config):
final_config = {
'archive_cache.eviction_policy': 'least-frequently-used'
}
for k, v in config.items():
if k.startswith('archive_cache'):
final_config[k] = v
return final_config
def get_archival_cache_store(config):
global cache_meta
if cache_meta is not None:
return cache_meta
config = get_archival_config(config)
archive_cache_dir = config['archive_cache.store_dir']
archive_cache_size_gb = config['archive_cache.cache_size_gb']
archive_cache_shards = config['archive_cache.cache_shards']
archive_cache_eviction_policy = config['archive_cache.eviction_policy']
log.debug('Initializing archival cache instance under %s', archive_cache_dir)
# check if it's ok to write, and re-create the archive cache
if not os.path.isdir(archive_cache_dir):
os.makedirs(archive_cache_dir, exist_ok=True)
d_cache = diskcache.FanoutCache(
archive_cache_dir, shards=archive_cache_shards,
cull_limit=0, # manual eviction required
size_limit=archive_cache_size_gb * 1024 * 1024 * 1024,
eviction_policy=archive_cache_eviction_policy,
timeout=30
)
cache_meta = d_cache
return cache_meta
def includeme(config):
# init our cache at start, for vcsserver we don't init at runtime
# because our cache config is sent via wire on make archive call, this call just lazy-enables the client
return