Пример #1
0
    def enter(self, from_state):
        """ Implementation of State virtual.

            This computes the minimal graph that will fit in a 32k
            block from the graph in the context and inserts it
            into two different Freenet CHK's.  Different headers
            are added before the graph data to get different
            CHKs.
        """
        require_state(from_state, INSERTING_BUNDLES)

        if self.parent.params.get('DUMP_GRAPH', False):
            self.parent.ctx.ui_.status("--- Updated Graph ---\n")
            self.parent.ctx.ui_.status(graph_to_string(self.parent.ctx.graph)
                                   + '\n')

        # Create minimal graph that will fit in a 32k block.
        assert not self.parent.ctx.version_table is None
        self.working_graph = minimal_graph(self.parent.ctx.graph,
                                           self.parent.ctx.repo,
                                           self.parent.ctx.version_table,
                                           31*1024)
        if self.parent.params.get('DUMP_GRAPH', False):
            self.parent.ctx.ui_.status("--- Minimal Graph ---\n")
            self.parent.ctx.ui_.status(graph_to_string(self.working_graph)
                                       + '\n---\n')

        # Make sure the string rep is small enough!
        graph_bytes = graph_to_string(self.working_graph)
        assert len(graph_bytes) <= 31 * 1024

        # Insert the graph twice for redundancy
        self.queue(['CHK@', 0, True, '#A\n' + graph_bytes, None, None])
        self.queue(['CHK@', 0, True, '#B\n' + graph_bytes, None, None])
        self.required_successes = 2
Пример #2
0
def test_presentation():
    """ Smoke test graph_to_string and parse_graph. """
    graph = UpdateGraph()
    print "EMPTY:"
    print graph_to_string(graph)
    print "Adding index: ", graph.add_index([
        VER_1,
    ], [
        VER_2,
    ])
    print "Adding index: ", graph.add_index([
        VER_2,
    ], [VER_3, VER_4])
    print "Adding index: ", graph.add_index([VER_3, VER_2], [
        VER_5,
    ])
    chks = fake_chks()
    graph.add_edge((-1, 0), (100, chks.next()))
    graph.add_edge((1, 2), (200, chks.next()))
    graph.add_edge((-1, 2), (500, chks.next()))
    text = graph_to_string(graph)
    print
    print text
    print
    graph1 = parse_graph(text)
    print
    text1 = graph_to_string(graph1)
    print "Round trip:"
    print text1
    assert text == text1
Пример #3
0
    def enter(self, from_state):
        """ Implementation of State virtual.

            This computes the minimal graph that will fit in a 32k
            block from the graph in the context and inserts it
            into two different Freenet CHK's.  Different headers
            are added before the graph data to get different
            CHKs.
        """
        require_state(from_state, INSERTING_BUNDLES)

        if self.parent.params.get('DUMP_GRAPH', False):
            self.parent.ctx.ui_.status("--- Updated Graph ---\n")
            self.parent.ctx.ui_.status(
                graph_to_string(self.parent.ctx.graph) + '\n')

        # Create minimal graph that will fit in a 32k block.
        assert not self.parent.ctx.version_table is None
        self.working_graph = minimal_graph(self.parent.ctx.graph,
                                           self.parent.ctx.repo,
                                           self.parent.ctx.version_table,
                                           31 * 1024)
        if self.parent.params.get('DUMP_GRAPH', False):
            self.parent.ctx.ui_.status("--- Minimal Graph ---\n")
            self.parent.ctx.ui_.status(
                graph_to_string(self.working_graph) + '\n---\n')

        # Make sure the string rep is small enough!
        graph_bytes = graph_to_string(self.working_graph)
        assert len(graph_bytes) <= 31 * 1024

        # Insert the graph twice for redundancy
        self.queue(['CHK@', 0, True, '#A\n' + graph_bytes, None, None])
        self.queue(['CHK@', 0, True, '#B\n' + graph_bytes, None, None])
        self.required_successes = 2
Пример #4
0
def test_minimal_graph(repo_dir, version_list, file_name=None):
    """ Smoke test minimal_graph(). """
    ui_ = ui.ui()
    if file_name is None:
        graph, repo, cache = test_update_real(repo_dir, version_list, True)
        open('/tmp/latest_graph.txt', 'wb').write(graph_to_string(graph))
    else:
        repo = hg.repository(ui_, repo_dir)
        cache = BundleCache(repo, ui_, CACHE_DIR)
        cache.remove_files()
        graph = parse_graph(open(file_name, 'rb').read())
        print "--- from file: %s ---" % file_name
        print graph_to_string(graph)
    version_map = build_version_table(graph, repo)

    # Incomplete, but better than nothing.
    # Verify that the chk bounds are the same after shrinking.
    chk_bounds = {}
    initial_edges = graph.get_top_key_edges()
    for edge in initial_edges:
        chk_bounds[graph.get_chk(edge)] = (
            get_rollup_bounds(graph, repo, edge[0] + 1, edge[1], version_map))

    print "CHK BOUNDS:"
    for value in chk_bounds:
        print value
        print "  ", chk_bounds[value]
    print
    sizes = (512, 1024, 2048, 4096, 16 * 1024)
    for max_size in sizes:
        try:
            print "MAX:", max(version_map.values())
            small = minimal_graph(graph, repo, version_map, max_size)
            print "--- size == %i" % max_size
            print graph_to_string(small)

            small.rep_invariant(repo, True) # Full check
            chks = chk_bounds.keys()
            path = small.get_top_key_edges()
            print "TOP KEY EDGES:"
            print path
            for edge in path:
                # MUST rebuild the version map because the indices changed.
                new_map = build_version_table(small, repo)
                bounds = get_rollup_bounds(small, repo, edge[0] + 1,
                                           edge[1], new_map)
                print "CHK:", small.get_chk(edge)
                print "BOUNDS: ", bounds
                assert chk_bounds[small.get_chk(edge)] == bounds
                print "DELETING: ", edge, small.get_chk(edge)
                chks.remove(small.get_chk(edge))
            assert len(chks) == 0
        except UpdateGraphException, err:
            print "IGNORED: ", err
Пример #5
0
def test_minimal_graph(repo_dir, version_list, file_name=None):
    """ Smoke test minimal_graph(). """
    ui_ = ui.ui()
    if file_name is None:
        graph, repo, cache = test_update_real(repo_dir, version_list, True)
        open('/tmp/latest_graph.txt', 'wb').write(graph_to_string(graph))
    else:
        repo = hg.repository(ui_, repo_dir)
        cache = BundleCache(repo, ui_, CACHE_DIR)
        cache.remove_files()
        graph = parse_graph(open(file_name, 'rb').read())
        print "--- from file: %s ---" % file_name
        print graph_to_string(graph)
    version_map = build_version_table(graph, repo)

    # Incomplete, but better than nothing.
    # Verify that the chk bounds are the same after shrinking.
    chk_bounds = {}
    initial_edges = graph.get_top_key_edges()
    for edge in initial_edges:
        chk_bounds[graph.get_chk(edge)] = (get_rollup_bounds(
            graph, repo, edge[0] + 1, edge[1], version_map))

    print "CHK BOUNDS:"
    for value in chk_bounds:
        print value
        print "  ", chk_bounds[value]
    print
    sizes = (512, 1024, 2048, 4096, 16 * 1024)
    for max_size in sizes:
        try:
            print "MAX:", max(version_map.values())
            small = minimal_graph(graph, repo, version_map, max_size)
            print "--- size == %i" % max_size
            print graph_to_string(small)

            small.rep_invariant(repo, True)  # Full check
            chks = chk_bounds.keys()
            path = small.get_top_key_edges()
            print "TOP KEY EDGES:"
            print path
            for edge in path:
                # MUST rebuild the version map because the indices changed.
                new_map = build_version_table(small, repo)
                bounds = get_rollup_bounds(small, repo, edge[0] + 1, edge[1],
                                           new_map)
                print "CHK:", small.get_chk(edge)
                print "BOUNDS: ", bounds
                assert chk_bounds[small.get_chk(edge)] == bounds
                print "DELETING: ", edge, small.get_chk(edge)
                chks.remove(small.get_chk(edge))
            assert len(chks) == 0
        except UpdateGraphException, err:
            print "IGNORED: ", err
Пример #6
0
def test_update_real(repo_dir, version_list=None, full=False):
    """ Smoke test graph.update(). """
    ui_ = ui.ui()
    repo = hg.repository(ui_, repo_dir)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()
    if version_list is None:
        latest = repo['tip'].rev()
        version_list = [[
            ordinal,
        ] for ordinal in range(0, latest + 1)]

    chks = fake_chks()
    for vers in version_list:
        print "UPDATING TO: ", vers
        new_edges = graph.update(repo, ui, vers, cache)
        for edge in new_edges:
            length = graph.get_length(edge)
            graph.set_chk(edge[:2], edge[2], length, chks.next())

        # REDFLAG: should call minimal_graph for "real" behavior
        text = graph_to_string(graph)
        print "GRAPH_LEN: ", len(text)
        print text

    if full:
        print "UPDATING TO: latest heads"
        try:
            new_edges = graph.update(repo, ui, None, cache)
            for edge in new_edges:
                length = graph.get_length(edge)
                graph.set_chk(edge[:2], edge[2], length, chks.next())

            # REDFLAG: should call minimal_graph for "real" behavior
            text = graph_to_string(graph)
            print "GRAPH_LEN: ", len(text)
            print text
        except UpToDate:
            print "Already has the head revs."

    return (graph, repo, cache)
Пример #7
0
    def enter(self, dummy):
        """ Implementation of State virtual.

            This checks the graph against the local repository and
            adds edges required to update it to the TARGET_VERSION
            specified in the context object. Then it starts inserting
            CHKS for the new edges into Freenet, doing padding /
            metadata salting as required.

        """
        #require_state(from_state, QUIESCENT)
        assert (self.parent.ctx.get('REINSERT', 0) > 0 or
                (not self.parent.ctx['INSERT_URI'] is None))
        assert not self.parent.ctx.graph is None

        graph = self.parent.ctx.graph.clone()
        if self.parent.params.get('DUMP_GRAPH', False):
            self.parent.ctx.ui_.status("--- Initial Graph ---\n")
            self.parent.ctx.ui_.status(graph_to_string(graph) +'\n')

        latest_revs = get_heads(graph)

        self.parent.ctx.ui_.status("Latest heads(s) in Freenet: %s\n"
                                 % ' '.join([ver[:12] for ver in latest_revs]))

        if self.parent.ctx.get('REINSERT', 0) == 1:
            self.parent.ctx.ui_.status("No bundles to reinsert.\n")
            # REDFLAG: Think this through. Crappy code, but expedient.
            # Hmmmm.... need version table to build minimal graph
            self.parent.ctx.version_table = build_version_table(graph,
                                                                self.parent.ctx.
                                                                repo)
            self.parent.transition(INSERTING_GRAPH)
            return

        if not self.parent.ctx.has_versions(latest_revs):
            self.parent.ctx.ui_.warn("The local repository isn't up "
                                     + "to date.\n"
                                     + "Try doing an fn-pull.\n")
            self.parent.transition(FAILING) # Hmmm... hard coded state name
            return

        # Update graph.
        try:
            self.set_new_edges(graph)
        except UpToDate, err:
            # REDFLAG: Later, add FORCE_INSERT parameter?
            # REDFLAG: rework UpToDate exception to include versions, stuff
            #      versions in  ctx?
            self.parent.ctx['UP_TO_DATE'] = True
            self.parent.ctx.ui_.warn(str(err) + '\n') # Hmmm
            self.parent.transition(FAILING) # Hmmm... hard coded state name
            return
Пример #8
0
def test_update_real(repo_dir, version_list=None, full=False):
    """ Smoke test graph.update(). """
    ui_ = ui.ui()
    repo = hg.repository(ui_, repo_dir)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()
    if version_list is None:
        latest = repo['tip'].rev()
        version_list = [[ordinal, ] for ordinal in range(0, latest + 1)]

    chks = fake_chks()
    for vers in version_list:
        print "UPDATING TO: ", vers
        new_edges = graph.update(repo, ui, vers, cache)
        for edge in new_edges:
            length = graph.get_length(edge)
            graph.set_chk(edge[:2], edge[2], length, chks.next())

        # REDFLAG: should call minimal_graph for "real" behavior
        text = graph_to_string(graph)
        print "GRAPH_LEN: ", len(text)
        print text

    if full:
        print "UPDATING TO: latest heads"
        try:
            new_edges = graph.update(repo, ui, None, cache)
            for edge in new_edges:
                length = graph.get_length(edge)
                graph.set_chk(edge[:2], edge[2], length, chks.next())

            # REDFLAG: should call minimal_graph for "real" behavior
            text = graph_to_string(graph)
            print "GRAPH_LEN: ", len(text)
            print text
        except UpToDate:
            print "Already has the head revs."

    return (graph, repo, cache)
Пример #9
0
def test_presentation():
    """ Smoke test graph_to_string and parse_graph. """
    graph = UpdateGraph()
    print "EMPTY:"
    print graph_to_string(graph)
    print "Adding index: ", graph.add_index([VER_1, ], [VER_2, ])
    print "Adding index: ", graph.add_index([VER_2, ], [VER_3, VER_4])
    print "Adding index: ", graph.add_index([VER_3, VER_2], [VER_5, ])
    chks = fake_chks()
    graph.add_edge((-1, 0), (100, chks.next()))
    graph.add_edge((1, 2), (200, chks.next()))
    graph.add_edge((-1, 2), (500, chks.next()))
    text = graph_to_string(graph)
    print
    print text
    print
    graph1 = parse_graph(text)
    print
    text1 = graph_to_string(graph1)
    print "Round trip:"
    print text1
    assert text == text1
Пример #10
0
def test_update(repo_dir):
    """ OBSOLETE? """
    ui_ = ui.ui()
    repo = hg.repository(ui_, repo_dir)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()
    graph.update(repo, ui, [1, 2], cache)
    print graph_to_string(graph)
    print
    print
    graph.update(repo, ui, [3, 4], cache)

    print graph_to_string(graph)
    print
    print
    graph.update(repo, ui, [6, ], cache)

    print graph_to_string(graph)
Пример #11
0
def test_update(repo_dir):
    """ OBSOLETE? """
    ui_ = ui.ui()
    repo = hg.repository(ui_, repo_dir)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()
    graph.update(repo, ui, [1, 2], cache)
    print graph_to_string(graph)
    print
    print
    graph.update(repo, ui, [3, 4], cache)

    print graph_to_string(graph)
    print
    print
    graph.update(repo, ui, [
        6,
    ], cache)

    print graph_to_string(graph)
Пример #12
0
def test_rollup():
    """ Smoke test get_rollup_bounds(). """
    repo, ui_ = setup_rollup_test_repo(TST_REPO_DIR)
    dump_changesets(repo)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()

    chks = fake_chks()
    # 0 Single changeset
    edges = graph.update(repo, ui_, ['716c293192c7', ], cache)
    set_chks(graph, edges, chks)
    # 1 Multiple changesets
    edges = graph.update(repo, ui_, ['076aec9f34c9', ], cache)
    set_chks(graph, edges, chks)
    # 2 Multiple heads, single base
    edges = graph.update(repo, ui_, ['62a72a238ffc', '4409936ef21f'], cache)
    set_chks(graph, edges, chks)
    # 3 Multiple bases, single head
    edges = graph.update(repo, ui_, ['a2c749d99d54', ], cache)
    set_chks(graph, edges, chks)
    # 4
    edges = graph.update(repo, ui_, ['f6248cd464e3', ], cache)
    set_chks(graph, edges, chks)
    # 5
    edges = graph.update(repo, ui_, ['fd1e6832820b', ], cache)
    set_chks(graph, edges, chks)
    # 6
    edges = graph.update(repo, ui_, ['7429bf7b11f5', ], cache)
    set_chks(graph, edges, chks)
    # 7
    edges = graph.update(repo, ui_, ['fcc2e90dbf0d', ], cache)
    set_chks(graph, edges, chks)
    # 8
    edges = graph.update(repo, ui_, ['03c047d036ca', ], cache)
    set_chks(graph, edges, chks)

    # 9
    edges = graph.update(repo, ui_, ['2f6c65f64ce5', ], cache)
    set_chks(graph, edges, chks)

    print
    print graph_to_string(graph)
    version_map = build_version_table(graph, repo)

    dump_version_map(version_map)
    assert version_map == EXPECTED_VERSION_MAP

    graph.rep_invariant(repo, True) # Verify contiguousness.

    print "From earliest..."
    for index in range(0, graph.latest_index + 1):
        parents, heads = get_rollup_bounds(graph, repo, 0, index, version_map)
        print "(%i->%i): %s" % (0, index, versions_str(heads))
        print "       ", versions_str(parents)


    print "To latest..."
    for index in range(0, graph.latest_index + 1):
        parents, heads = get_rollup_bounds(graph, repo, index,
                                           graph.latest_index,
                                           version_map)
        print "(%i->%i): %s" % (index, graph.latest_index, versions_str(heads))
        print "       ", versions_str(parents)


    # Empty
    try:
        get_rollup_bounds(graph, repo, FIRST_INDEX, FIRST_INDEX,
                          version_map)
    except AssertionError:
        # Asserted as expected for to_index == FIRST_INDEX
        print "Got expected assertion."

    # Rollup of one changeset index.
    result = get_rollup_bounds(graph, repo, 0, 0, version_map)
    check_result(result, (('000000000000', ), ('716c293192c7',)))

    # Rollup of multiple changeset index.
    result = get_rollup_bounds(graph, repo, 1, 1, version_map)
    check_result(result, (('716c293192c7', ), ('076aec9f34c9',)))

    # Rollup of with multiple heads.
    result = get_rollup_bounds(graph, repo, 1, 2, version_map)
    check_result(result, (('716c293192c7', ), ('4409936ef21f','62a72a238ffc')))

    # Rollup of with multiple bases.
    result = get_rollup_bounds(graph, repo, 3, 4, version_map)
    check_result(result, (('4409936ef21f', '62a72a238ffc', ),
                          ('f6248cd464e3',)))

    # Rollup with head pulled in from earlier base.
    result = get_rollup_bounds(graph, repo, 3, 8, version_map)
    print result
    check_result(result, (('4409936ef21f', '62a72a238ffc', ),
                          ('03c047d036ca', '7429bf7b11f5')))

    # Rollup after remerge to a single head.
    result = get_rollup_bounds(graph, repo, 0, 9, version_map)
    print result
    check_result(result, (('000000000000', ), ('2f6c65f64ce5', )))
Пример #13
0
def test_rollup():
    """ Smoke test get_rollup_bounds(). """
    repo, ui_ = setup_rollup_test_repo(TST_REPO_DIR)
    dump_changesets(repo)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()

    chks = fake_chks()
    # 0 Single changeset
    edges = graph.update(repo, ui_, [
        '716c293192c7',
    ], cache)
    set_chks(graph, edges, chks)
    # 1 Multiple changesets
    edges = graph.update(repo, ui_, [
        '076aec9f34c9',
    ], cache)
    set_chks(graph, edges, chks)
    # 2 Multiple heads, single base
    edges = graph.update(repo, ui_, ['62a72a238ffc', '4409936ef21f'], cache)
    set_chks(graph, edges, chks)
    # 3 Multiple bases, single head
    edges = graph.update(repo, ui_, [
        'a2c749d99d54',
    ], cache)
    set_chks(graph, edges, chks)
    # 4
    edges = graph.update(repo, ui_, [
        'f6248cd464e3',
    ], cache)
    set_chks(graph, edges, chks)
    # 5
    edges = graph.update(repo, ui_, [
        'fd1e6832820b',
    ], cache)
    set_chks(graph, edges, chks)
    # 6
    edges = graph.update(repo, ui_, [
        '7429bf7b11f5',
    ], cache)
    set_chks(graph, edges, chks)
    # 7
    edges = graph.update(repo, ui_, [
        'fcc2e90dbf0d',
    ], cache)
    set_chks(graph, edges, chks)
    # 8
    edges = graph.update(repo, ui_, [
        '03c047d036ca',
    ], cache)
    set_chks(graph, edges, chks)

    # 9
    edges = graph.update(repo, ui_, [
        '2f6c65f64ce5',
    ], cache)
    set_chks(graph, edges, chks)

    print
    print graph_to_string(graph)
    version_map = build_version_table(graph, repo)

    dump_version_map(version_map)
    assert version_map == EXPECTED_VERSION_MAP

    graph.rep_invariant(repo, True)  # Verify contiguousness.

    print "From earliest..."
    for index in range(0, graph.latest_index + 1):
        parents, heads = get_rollup_bounds(graph, repo, 0, index, version_map)
        print "(%i->%i): %s" % (0, index, versions_str(heads))
        print "       ", versions_str(parents)

    print "To latest..."
    for index in range(0, graph.latest_index + 1):
        parents, heads = get_rollup_bounds(graph, repo, index,
                                           graph.latest_index, version_map)
        print "(%i->%i): %s" % (index, graph.latest_index, versions_str(heads))
        print "       ", versions_str(parents)

    # Empty
    try:
        get_rollup_bounds(graph, repo, FIRST_INDEX, FIRST_INDEX, version_map)
    except AssertionError:
        # Asserted as expected for to_index == FIRST_INDEX
        print "Got expected assertion."

    # Rollup of one changeset index.
    result = get_rollup_bounds(graph, repo, 0, 0, version_map)
    check_result(result, (('000000000000', ), ('716c293192c7', )))

    # Rollup of multiple changeset index.
    result = get_rollup_bounds(graph, repo, 1, 1, version_map)
    check_result(result, (('716c293192c7', ), ('076aec9f34c9', )))

    # Rollup of with multiple heads.
    result = get_rollup_bounds(graph, repo, 1, 2, version_map)
    check_result(result,
                 (('716c293192c7', ), ('4409936ef21f', '62a72a238ffc')))

    # Rollup of with multiple bases.
    result = get_rollup_bounds(graph, repo, 3, 4, version_map)
    check_result(result, ((
        '4409936ef21f',
        '62a72a238ffc',
    ), ('f6248cd464e3', )))

    # Rollup with head pulled in from earlier base.
    result = get_rollup_bounds(graph, repo, 3, 8, version_map)
    print result
    check_result(result, ((
        '4409936ef21f',
        '62a72a238ffc',
    ), ('03c047d036ca', '7429bf7b11f5')))

    # Rollup after remerge to a single head.
    result = get_rollup_bounds(graph, repo, 0, 9, version_map)
    print result
    check_result(result, (('000000000000', ), ('2f6c65f64ce5', )))