def delete_remote_wal_before(self, wal_segment, site): self.log.debug("Starting WAL deletion from: %r before: %r", site, wal_segment) storage = self.site_transfers.get(site) valid_timeline = True tli, log, seg = wal.name_to_tli_log_seg(wal_segment) while True: if valid_timeline: # Decrement one segment if we're on a valid timeline if seg == 0 and log == 0: break seg, log = wal.get_previous_wal_on_same_timeline(seg, log) wal_path = os.path.join(self.config.get("path_prefix", ""), site, "xlog", wal.name_for_tli_log_seg(tli, log, seg)) self.log.debug("Deleting wal_file: %r", wal_path) try: storage.delete_key(wal_path) valid_timeline = True except FileNotFoundFromStorageError: if not valid_timeline or tli <= 1: # if we didn't find any WALs to delete on this timeline or we're already at # timeline 1 there's no need or possibility to try older timelines, break. self.log.info("Could not delete wal_file: %r, returning", wal_path) break # let's try the same segment number on a previous timeline, but flag that timeline # as "invalid" until we're able to delete at least one segment on it. valid_timeline = False tli -= 1 self.log.info("Could not delete wal_file: %r, trying the same segment on a previous " "timeline (%s)", wal_path, wal.name_for_tli_log_seg(tli, log, seg)) except: # FIXME: don't catch all exceptions; pylint: disable=bare-except self.log.exception("Problem deleting: %r", wal_path)
def delete_remote_wal_before(self, wal_segment, site, pg_version): self.log.info("Starting WAL deletion from: %r before: %r, pg_version: %r", site, wal_segment, pg_version) storage = self.site_transfers.get(site) valid_timeline = True tli, log, seg = wal.name_to_tli_log_seg(wal_segment) while True: if valid_timeline: # Decrement one segment if we're on a valid timeline if seg == 0 and log == 0: break seg, log = wal.get_previous_wal_on_same_timeline(seg, log, pg_version) wal_path = os.path.join(self.config["backup_sites"][site]["prefix"], "xlog", wal.name_for_tli_log_seg(tli, log, seg)) self.log.debug("Deleting wal_file: %r", wal_path) try: storage.delete_key(wal_path) valid_timeline = True except FileNotFoundFromStorageError: if not valid_timeline or tli <= 1: # if we didn't find any WALs to delete on this timeline or we're already at # timeline 1 there's no need or possibility to try older timelines, break. self.log.info("Could not delete wal_file: %r, returning", wal_path) break # let's try the same segment number on a previous timeline, but flag that timeline # as "invalid" until we're able to delete at least one segment on it. valid_timeline = False tli -= 1 self.log.info("Could not delete wal_file: %r, trying the same segment on a previous " "timeline (%s)", wal_path, wal.name_for_tli_log_seg(tli, log, seg)) except Exception as ex: # FIXME: don't catch all exceptions; pylint: disable=broad-except self.log.exception("Problem deleting: %r", wal_path) self.metrics.unexpected_exception(ex, where="delete_remote_wal_before")