... |
... |
@@ -197,29 +197,55 @@ class Context(): |
197
|
197
|
"\nValid values are, for example: 800M 10G 1T 50%\n"
|
198
|
198
|
.format(str(e))) from e
|
199
|
199
|
|
200
|
|
- # If we are asked not to set a quota, we set it to the maximum
|
201
|
|
- # disk space available minus a headroom of 2GB, such that we
|
202
|
|
- # at least try to avoid raising Exceptions.
|
|
200
|
+ # Headroom intended to give BuildStream a bit of leeway.
|
|
201
|
+ # This acts as the minimum size of cache_quota and also
|
|
202
|
+ # is taken from the user requested cache_quota.
|
203
|
203
|
#
|
204
|
|
- # Of course, we might still end up running out during a build
|
205
|
|
- # if we end up writing more than 2G, but hey, this stuff is
|
206
|
|
- # already really fuzzy.
|
207
|
|
- #
|
208
|
|
- if cache_quota is None:
|
209
|
|
- stat = os.statvfs(artifactdir_volume)
|
210
|
|
- # Again, the artifact directory may not yet have been
|
211
|
|
- # created
|
212
|
|
- if not os.path.exists(self.artifactdir):
|
213
|
|
- cache_size = 0
|
214
|
|
- else:
|
215
|
|
- cache_size = utils._get_dir_size(self.artifactdir)
|
216
|
|
- cache_quota = cache_size + stat.f_bsize * stat.f_bavail
|
217
|
|
-
|
218
|
204
|
if 'BST_TEST_SUITE' in os.environ:
|
219
|
205
|
headroom = 0
|
220
|
206
|
else:
|
221
|
207
|
headroom = 2e9
|
222
|
208
|
|
|
209
|
+ stat = os.statvfs(artifactdir_volume)
|
|
210
|
+ available_space = (stat.f_bsize * stat.f_bavail)
|
|
211
|
+
|
|
212
|
+ # Again, the artifact directory may not yet have been created yet
|
|
213
|
+ #
|
|
214
|
+ if not os.path.exists(self.artifactdir):
|
|
215
|
+ cache_size = 0
|
|
216
|
+ else:
|
|
217
|
+ cache_size = utils._get_dir_size(self.artifactdir)
|
|
218
|
+
|
|
219
|
+ # Ensure system has enough storage for the cache_quota
|
|
220
|
+ #
|
|
221
|
+ # If cache_quota is none, set it to the maximum it could possibly be.
|
|
222
|
+ #
|
|
223
|
+ # Also check that cache_quota is atleast as large as our headroom.
|
|
224
|
+ #
|
|
225
|
+ if cache_quota is None: # Infinity, set to max system storage
|
|
226
|
+ cache_quota = cache_size + available_space
|
|
227
|
+ if cache_quota < headroom: # Check minimum
|
|
228
|
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
229
|
+ "Invalid cache quota ({}): ".format(utils._pretty_size(cache_quota)) +
|
|
230
|
+ "BuildStream requires a minimum cache quota of 2G.")
|
|
231
|
+ elif cache_quota > available_space: # Check maximum
|
|
232
|
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
233
|
+ ("Your system does not have enough available " +
|
|
234
|
+ "space to support the cache quota specified.\n" +
|
|
235
|
+ "You currently have:\n" +
|
|
236
|
+ "- {used} of cache in use at {local_cache_path}\n" +
|
|
237
|
+ "- {available} of available system storage").format(
|
|
238
|
+ used=utils._pretty_size(cache_size),
|
|
239
|
+ local_cache_path=self.artifactdir,
|
|
240
|
+ available=utils._pretty_size(available_space)))
|
|
241
|
+
|
|
242
|
+ # Place a slight headroom (2e9 (2GB) on the cache_quota) into
|
|
243
|
+ # cache_quota to try and avoid exceptions.
|
|
244
|
+ #
|
|
245
|
+ # Of course, we might still end up running out during a build
|
|
246
|
+ # if we end up writing more than 2G, but hey, this stuff is
|
|
247
|
+ # already really fuzzy.
|
|
248
|
+ #
|
223
|
249
|
self.cache_quota = cache_quota - headroom
|
224
|
250
|
self.cache_lower_threshold = self.cache_quota / 2
|
225
|
251
|
|