Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 57ea96b

Browse files
committed
fix: improve new minio implementation
The team mentioned wanting to ship the new read implementation first then the new write implementation so this commit enables that. i'm folding the NewMinioStorageService functionality back into the MinioStorageService and creating 2 new feature flags one for read and one for write. Based on the values of those feature flags the MinioStorageService will choose an implementation of read/write. I also removed the old USE_NEW_MINIO feature flag, and modified the get_appropriate_storage_service function to make it so it no longer caches the MinioStorageService and instead the MinioStorageService is caching its internal minio_client since that is the expensive part of creating a new MinioStorageService instance. I also moved some code around
1 parent 015d76e commit 57ea96b

File tree

10 files changed

+471
-567
lines changed

10 files changed

+471
-567
lines changed

shared/rollouts/features.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
BUNDLE_THRESHOLD_FLAG = Feature("bundle_threshold_flag")
44
INCLUDE_GITHUB_COMMENT_ACTIONS_BY_OWNER = Feature("include_github_comment_actions")
5-
USE_NEW_MINIO = Feature("use_new_minio")
5+
6+
READ_NEW_MINIO = Feature("read_new_minio")
7+
WRITE_NEW_MINIO = Feature("write_new_minio")

shared/storage/__init__.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from shared.config import get_config
2-
from shared.rollouts.features import USE_NEW_MINIO
2+
from shared.rollouts.features import READ_NEW_MINIO, WRITE_NEW_MINIO
33
from shared.storage.aws import AWSStorageService
44
from shared.storage.base import BaseStorageService
55
from shared.storage.fallback import StorageWithFallbackService
66
from shared.storage.gcp import GCPStorageService
77
from shared.storage.minio import MinioStorageService
8-
from shared.storage.new_minio import NewMinioStorageService
98

109
_storage_service_cache: dict[str, BaseStorageService] = {}
1110

@@ -18,9 +17,8 @@ def get_appropriate_storage_service(
1817
if force_minio:
1918
chosen_storage = "minio"
2019

21-
if repoid and chosen_storage == "minio":
22-
if USE_NEW_MINIO.check_value(repoid, default=False):
23-
chosen_storage = "new_minio"
20+
if chosen_storage == "minio":
21+
return get_minio_storage_service(repoid)
2422

2523
if chosen_storage not in _storage_service_cache:
2624
_storage_service_cache[chosen_storage] = (
@@ -30,6 +28,22 @@ def get_appropriate_storage_service(
3028
return _storage_service_cache[chosen_storage]
3129

3230

31+
def get_minio_storage_service(
32+
repo_id: int | None,
33+
) -> MinioStorageService:
34+
minio_config = get_config("services", "minio", default={})
35+
if repo_id:
36+
new_read = READ_NEW_MINIO.check_value(repo_id, default=False)
37+
new_write = WRITE_NEW_MINIO.check_value(repo_id, default=False)
38+
return MinioStorageService(
39+
minio_config,
40+
new_read=new_read,
41+
new_write=new_write,
42+
)
43+
else:
44+
return MinioStorageService(minio_config)
45+
46+
3347
def _get_appropriate_storage_service_given_storage(
3448
chosen_storage: str,
3549
) -> BaseStorageService:
@@ -45,9 +59,5 @@ def _get_appropriate_storage_service_given_storage(
4559
aws_config = get_config("services", "aws", default={})
4660
aws_service = AWSStorageService(aws_config)
4761
return StorageWithFallbackService(gcp_service, aws_service)
48-
elif chosen_storage == "new_minio":
49-
minio_config = get_config("services", "minio", default={})
50-
return NewMinioStorageService(minio_config)
5162
else:
52-
minio_config = get_config("services", "minio", default={})
53-
return MinioStorageService(minio_config)
63+
raise ValueError(f"Invalid storage service: {chosen_storage}")

shared/storage/compression.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import gzip
2+
import importlib.metadata
3+
from typing import IO
4+
5+
6+
class GZipStreamReader:
7+
def __init__(self, fileobj: IO[bytes]):
8+
self.data = fileobj
9+
10+
def read(self, size: int = -1, /) -> bytes:
11+
curr_data = self.data.read(size)
12+
13+
if not curr_data:
14+
return b""
15+
16+
return gzip.compress(curr_data)
17+
18+
19+
def zstd_decoded_by_default() -> bool:
20+
try:
21+
version = importlib.metadata.version("urllib3")
22+
except importlib.metadata.PackageNotFoundError:
23+
return False
24+
25+
if version < "2.0.0":
26+
return False
27+
28+
distribution = importlib.metadata.metadata("urllib3")
29+
if requires_dist := distribution.get_all("Requires-Dist"):
30+
for req in requires_dist:
31+
if "[zstd]" in req:
32+
return True
33+
34+
return False

0 commit comments

Comments
 (0)