示例#1
0
    def recreate_attr(self, regress_time):
        """
        Make regress_time mirror_metadata snapshot by patching

        We write to a tempfile first.  Otherwise, in case of a crash, it
        would seem we would have an intact snapshot and partial diff, not
        the reverse.
        """
        temprp = [self.data_dir.get_temp_rpath()]

        def callback(rp):
            temprp[0] = rp

        writer = self._meta_main_class(temprp[0],
                                       'wb',
                                       check_path=0,
                                       callback=callback)
        for rorp in self._get_meta_main_at_time(regress_time, None):
            writer.write_object(rorp)
        writer.close()

        finalrp = self.data_dir.append(b"mirror_metadata.%b.snapshot.gz" %
                                       Time.timetobytes(regress_time))
        assert not finalrp.lstat(), (
            "Metadata path '{mrp}' shouldn't exist.".format(mrp=finalrp))
        rpath.rename(temprp[0], finalrp)
        if Globals.fsync_directories:
            self.data_dir.fsync()
示例#2
0
    def _writer_helper(self, typestr, time, meta_class, force=False):
        """
        Returns a writer class or None if the meta class isn't active.

        For testing purposes, the force option allows to skip the activity
        validation.
        """
        if time is None:
            timestr = Time.getcurtimestr()
        else:
            timestr = Time.timetobytes(time)
        triple = map(os.fsencode, (meta_class.get_prefix(), timestr, typestr))
        filename = b'.'.join(triple)
        rp = self.data_dir.append(filename)
        assert not rp.lstat(), "File '{rp}' shouldn't exist.".format(rp=rp)
        assert rp.isincfile(), (
            "Path '{irp}' must be an increment file.".format(irp=rp))
        if meta_class.is_active() or force:
            # Before API 201, metafiles couldn't be compressed
            return meta_class(rp, 'w',
                              compress=(Globals.compression
                                        or Globals.get_api_version() < 201),
                              callback=self._add_incrp)
        else:
            return None
示例#3
0
 def get_correct(self, mirror_rp, test_time):
     """Return correct version with base mirror_rp at time test_time"""
     assert -1 < test_time < 2000000000, test_time
     dirname, basename = mirror_rp.dirsplit()
     for filename in restore_base_filenames:
         comps = filename.split(b".")
         base = b".".join(comps[:-1])
         t = Time.bytestotime(comps[-1])
         if t == test_time and basename == base:
             return restore_base_rp.append(filename)
     # Correct rp must be empty
     return restore_base_rp.append(b"%b.%b" %
                                   (basename, Time.timetobytes(test_time)))