MCPcopy Create free account
hub / github.com/wal-e/wal-e / _delete_wals_before

Method _delete_wals_before

wal_e/worker/base.py:329–393  ·  view source on GitHub ↗

Delete all WAL files before segment_info. Doesn't delete any base-backup data.

(self, segment_info)

Source from the content-addressed store, hash-verified

327 assert False
328
329 def _delete_wals_before(self, segment_info):
330 """
331 Delete all WAL files before segment_info.
332
333 Doesn't delete any base-backup data.
334 """
335 wal_key_depth = self.layout.wal_directory().count('/') + 1
336 for key in self._backup_list(prefix=self.layout.wal_directory()):
337 key_name = self.layout.key_name(key)
338 bucket = self._container_name(key)
339 url = '{scm}://{bucket}/{name}'.format(scm=self.layout.scheme,
340 bucket=bucket,
341 name=key_name)
342 key_parts = key_name.split('/')
343 key_depth = len(key_parts)
344 if key_depth != wal_key_depth:
345 logger.warning(
346 msg="skipping non-qualifying key in 'delete before'",
347 detail=(
348 'The unexpected key is "{0}", and it appears to be '
349 'at an unexpected depth.'.format(url)),
350 hint=generic_weird_key_hint_message)
351 elif key_depth == wal_key_depth:
352 segment_match = (re.match(storage.SEGMENT_REGEXP + r'\.lzo',
353 key_parts[-1]))
354 label_match = (re.match(storage.SEGMENT_REGEXP +
355 r'\.[A-F0-9]{8,8}.backup.lzo',
356 key_parts[-1]))
357 history_match = re.match(r'[A-F0-9]{8,8}\.history',
358 key_parts[-1])
359
360 all_matches = [segment_match, label_match, history_match]
361
362 non_matches = len(list(m for m in all_matches if m is None))
363
364 # These patterns are intended to be mutually
365 # exclusive, so either one should match or none should
366 # match.
367 assert non_matches in (len(all_matches) - 1, len(all_matches))
368 if non_matches == len(all_matches):
369 logger.warning(
370 msg="skipping non-qualifying key in 'delete before'",
371 detail=('The unexpected key is "{0}", and it appears '
372 'not to match the WAL file naming pattern.'
373 .format(url)),
374 hint=generic_weird_key_hint_message)
375 elif segment_match is not None:
376 scanned_sn = self._groupdict_to_segment_number(
377 segment_match.groupdict())
378 self._delete_if_before(segment_info, scanned_sn, key,
379 'a wal file')
380 elif label_match is not None:
381 scanned_sn = self._groupdict_to_segment_number(
382 label_match.groupdict())
383 self._delete_if_before(segment_info, scanned_sn, key,
384 'a backup history file')
385 elif history_match is not None:
386 # History (timeline) files do not have any actual

Callers 2

delete_beforeMethod · 0.95
delete_with_retentionMethod · 0.95

Calls 8

_container_nameMethod · 0.95
_delete_if_beforeMethod · 0.95
wal_directoryMethod · 0.80
key_nameMethod · 0.80
formatMethod · 0.80
warningMethod · 0.80
_backup_listMethod · 0.45

Tested by

no test coverage detected