Example #1
0
    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)
Example #2
0
 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")
Example #3
0
def wal_header_for_file(name, version=90500):
    tli, log, seg = wal.name_to_tli_log_seg(name)
    if version < 90300:
        recoff = seg * wal.WAL_SEG_SIZE
        return struct.pack("=HHILLI", wal.WAL_MAGIC_BY_VERSION[version], 0, tli, log, recoff, 0)
    pageaddr = (log << 32) | (seg * wal.WAL_SEG_SIZE)
    return struct.pack("=HHIQI", wal.WAL_MAGIC_BY_VERSION[version], 0, tli, pageaddr, 0)
Example #4
0
def wal_header_for_file(name, version=90500):
    tli, log, seg = wal.name_to_tli_log_seg(name)
    if version < 90300:
        recoff = seg * wal.XLOG_SEG_SIZE
        return struct.pack("=HHILLI", wal.WAL_MAGIC_BY_VERSION[version], 0, tli, log, recoff, 0)
    pageaddr = (log << 32) | (seg * wal.XLOG_SEG_SIZE)
    return struct.pack("=HHIQI", wal.WAL_MAGIC_BY_VERSION[version], 0, tli, pageaddr, 0)
Example #5
0
def wal_header_for_file(name):
    tli, log, seg = wal.name_to_tli_log_seg(name)
    pageaddr = (log << 32) | (seg * wal.XLOG_SEG_SIZE)
    return struct.pack("=HHIQI", list(wal.WAL_MAGIC).pop(0), 0, tli, pageaddr, 0)