示例#1
0
    def atomic_update_hframe(self, hfr):
        """
        Given an HFR that has new meta information, such as tags, update the version on disk atomically,
        then make an update to the data base

        Note: This has only been spec'd to work when we update tags.   If you're making any other changes to the
        original HyperFrameRecord, you will need to review this code.

        TODO: This is not acid wrt to the database.  We need to make a transaction for this update.
        At least try / catch the remove before we update the file.

        Args:
            hfr:

        Returns:
            result object

        """

        # 1.) Delete DB record
        hyperframe.delete_hfr_db(self.local_engine, uuid=hfr.pb.uuid)

        # 2.) Write FS HyperFrame PB to a sister file and then move to original file.
        hyperframe.w_pb_fs(os.path.join(self.get_object_dir(), hfr.pb.uuid),
                           hfr,
                           atomic=True)

        # 3.) Write DB HyperFrame and tags
        result = hyperframe.w_pb_db(hfr, self.local_engine)

        return result
示例#2
0
    def _write_hframe_local(self, hfr):
        """

        Args:
            hfr:

        Returns:

        """
        # Write DB HyperFrame
        result = hyperframe.w_pb_db(hfr, self.local_engine)

        # Write FS Frames
        for fr in hfr.get_frames(self):
            hyperframe.w_pb_fs(
                os.path.join(self.get_object_dir(), hfr.pb.uuid), fr)

        # Write FS HyperFrame
        hyperframe.w_pb_fs(os.path.join(self.get_object_dir(), hfr.pb.uuid),
                           hfr)

        # Write DB Frames
        for fr in hfr.get_frames(self):
            hyperframe.w_pb_db(fr, self.local_engine)

        self.prune_uncommitted_history(hfr.pb.human_name)

        return result
示例#3
0
def test_linkauth_rw_pb():
    """
    Write LINKAUTH PBs to disk and back.
    :return:
    """

    slar = _make_linkauth_records()
    """ Write out protocol buffers """

    w_pb_fs(testdir, slar)
    """ Read in protocol buffers """

    r_pb_fs(os.path.join(testdir, slar.get_filename()),
            hyperframe.S3LinkAuthRecord)
示例#4
0
def test_link_rw_pb():
    """
    Write LINK PBs to disk and back.
    :return:
    """

    file_link, s3_link = _make_link_records()
    """ Write out protocol buffers """

    w_pb_fs(testdir, file_link)
    w_pb_fs(testdir, s3_link)
    """ Read in protocol buffers """

    r_pb_fs(os.path.join(testdir, file_link.get_filename()),
            hyperframe.FileLinkRecord)
    r_pb_fs(os.path.join(testdir, s3_link.get_filename()),
            hyperframe.S3LinkRecord)
示例#5
0
def test_hframe_rw_pb():
    """
    Write HyperFrame PBs to disk and back.
    :return:
    """

    hf1 = _make_hframe_record('inner_record')
    hf2 = _make_hframe_record('outer_record', hframes=[hf1, ])

    """ Write out protocol buffers """

    w_pb_fs(testdir, hf2)

    for fr in hf2.get_frames(None, testing_dir=testdir):
        w_pb_fs(testdir, fr)

    """ Read in protocol buffers """

    hf2_read = r_pb_fs(os.path.join(testdir, hf2.get_filename()), hyperframe.HyperFrameRecord)

    validate_hframe_record(hf2_read)