Skip to content

Commit 32e3a33

Browse files
authored
Fail loudly when file is missing and change defaults to aggressively fail instead of passively
1 parent a327f34 commit 32e3a33

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pkg/workloads/lib/storage/local.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _get_or_create_path(self, key):
3838
p.parent.mkdir(parents=True, exist_ok=True)
3939
return p
4040

41-
def _get_path_if_exists(self, key, allow_missing=True):
41+
def _get_path_if_exists(self, key, allow_missing=False):
4242
p = Path(os.path.join(self.base_dir, key))
4343
if not p.exists() and allow_missing:
4444
return None
@@ -69,7 +69,7 @@ def put_json(self, obj, key):
6969
f = self._get_or_create_path(key)
7070
f.write_text(json.dumps(obj))
7171

72-
def get_json(self, key, allow_missing=True):
72+
def get_json(self, key, allow_missing=False):
7373
f = self._get_path_if_exists(key, allow_missing)
7474
if f is None:
7575
return None
@@ -79,7 +79,7 @@ def put_msgpack(self, obj, key):
7979
f = self._get_or_create_path(key)
8080
f.write_bytes(msgpack.dumps(obj))
8181

82-
def get_msgpack(self, key, allow_missing=True):
82+
def get_msgpack(self, key, allow_missing=False):
8383
f = self._get_path_if_exists(key, allow_missing)
8484
if f is None:
8585
return None
@@ -89,7 +89,7 @@ def put_pyobj(self, obj, key):
8989
f = self._get_or_create_path(key)
9090
f.write_bytes(pickle.dumps(obj))
9191

92-
def get_pyobj(self, key, bucket, allow_missing=True):
92+
def get_pyobj(self, key, bucket, allow_missing=False):
9393
f = self._get_path_if_exists(key, allow_missing)
9494
if f is None:
9595
return None

pkg/workloads/lib/storage/s3.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ def _get_matching_s3_keys_generator(self, prefix="", suffix=""):
114114
def _upload_string_to_s3(self, string, key):
115115
self.s3.put_object(Bucket=self.bucket, Key=key, Body=string)
116116

117-
def _read_bytes_from_s3(self, key, allow_missing=True):
117+
def _read_bytes_from_s3(self, key, allow_missing=False):
118118
try:
119119
byte_array = self.s3.get_object(Bucket=self.bucket, Key=key)["Body"].read()
120120
except self.s3.exceptions.NoSuchKey as e:
121121
if allow_missing:
122122
return None
123-
raise e
123+
raise CortexException("bucket " + self.bucket, "key " + key) from e
124124

125125
return byte_array.strip()
126126

@@ -130,7 +130,7 @@ def search(self, prefix="", suffix=""):
130130
def put_json(self, obj, key):
131131
self._upload_string_to_s3(json.dumps(obj), key)
132132

133-
def get_json(self, key, allow_missing=True):
133+
def get_json(self, key, allow_missing=False):
134134
obj = self._read_bytes_from_s3(key, allow_missing).decode("utf-8")
135135
if obj is None:
136136
return None
@@ -139,7 +139,7 @@ def get_json(self, key, allow_missing=True):
139139
def put_msgpack(self, obj, key):
140140
self._upload_string_to_s3(msgpack.dumps(obj), key)
141141

142-
def get_msgpack(self, key, allow_missing=True):
142+
def get_msgpack(self, key, allow_missing=False):
143143
obj = self._read_bytes_from_s3(key, allow_missing)
144144
if obj == None:
145145
return None
@@ -148,7 +148,7 @@ def get_msgpack(self, key, allow_missing=True):
148148
def put_pyobj(self, obj, key):
149149
self._upload_string_to_s3(pickle.dumps(obj), key)
150150

151-
def get_pyobj(self, key, allow_missing=True):
151+
def get_pyobj(self, key, allow_missing=False):
152152
obj = self._read_bytes_from_s3(key, allow_missing)
153153
if obj is None:
154154
return None

0 commit comments

Comments
 (0)