Esempio n. 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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 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