# HG changeset patch # User RhodeCode Admin # Date 2024-06-18 12:03:25 # Node ID c72dd577671fbd30fef2402593eb1982a505ea7f # Parent acea161c02eec037d091339b675ea16a10904a88 archive-cache: synced with CE codebase diff --git a/vcsserver/lib/archive_cache/backends/fanout_cache.py b/vcsserver/lib/archive_cache/backends/fanout_cache.py --- a/vcsserver/lib/archive_cache/backends/fanout_cache.py +++ b/vcsserver/lib/archive_cache/backends/fanout_cache.py @@ -115,6 +115,7 @@ class FileSystemShard(BaseShard): class FileSystemFanoutCache(BaseCache): + shard_name = 'shard_%03d' def __init__(self, locking_url, **settings): """ @@ -150,7 +151,7 @@ class FileSystemFanoutCache(BaseCache): self._shards = tuple( FileSystemShard( index=num, - directory=os.path.join(directory, 'shard_%03d' % num), + directory=os.path.join(directory, self.shard_name % num), **settings, ) for num in range(self._count) diff --git a/vcsserver/lib/archive_cache/backends/objectstore_cache.py b/vcsserver/lib/archive_cache/backends/objectstore_cache.py --- a/vcsserver/lib/archive_cache/backends/objectstore_cache.py +++ b/vcsserver/lib/archive_cache/backends/objectstore_cache.py @@ -41,12 +41,15 @@ class S3Shard(BaseShard): key = settings.pop('archive_cache.objectstore.key') secret = settings.pop('archive_cache.objectstore.secret') + # TODO: Add it all over the place... + self._bucket_root = settings.pop('archive_cache.objectstore.bucket_root') + self.fs = fsspec.filesystem('s3', anon=False, endpoint_url=endpoint_url, key=key, secret=secret) @property def bucket(self): """Cache bucket.""" - return self._bucket + return os.path.join(self._bucket_root, self._bucket) def _get_keyfile(self, archive_key) -> tuple[str, str]: key_file = f'{archive_key}-{self.key_suffix}' @@ -56,6 +59,10 @@ class S3Shard(BaseShard): return self.fs.open(path, 'wb') def _write_file(self, full_path, iterator, mode): + if self._bucket_root: + if not self.fs.exists(self._bucket_root): + self.fs.mkdir(self._bucket_root) + # ensure bucket exists destination = self.bucket if not self.fs.exists(destination): @@ -106,6 +113,7 @@ class S3Shard(BaseShard): class ObjectStoreCache(BaseCache): + shard_name = 'shard-bucket-%03d' def __init__(self, locking_url, **settings): """ @@ -134,7 +142,7 @@ class ObjectStoreCache(BaseCache): self._shards = tuple( S3Shard( index=num, - bucket='rhodecode-archivecache-%03d' % num, + bucket=self.shard_name % num, **settings, ) for num in range(self._count)