Search in sources :

Example 6 with Shard

use of com.baidu.hugegraph.structure.graph.Shard in project incubator-hugegraph-toolchain by apache.

the class BackupManager method backupEdges.

protected void backupEdges() {
    Printer.print("Edges backup started");
    Printer.printInBackward("Edges has been backup: ");
    List<Shard> shards = retry(() -> this.client.traverser().edgeShards(splitSize()), "querying shards of edges");
    this.writeShards(this.allShardsLog(HugeType.EDGE), shards);
    for (Shard shard : shards) {
        this.backupEdgeShardAsync(shard);
    }
    this.awaitTasks();
    this.postProcessFailedShard(HugeType.EDGE);
    Printer.print("%d", this.edgeCounter.get());
    Printer.print("Edges backup finished: %d", this.edgeCounter.get());
}
Also used : Shard(com.baidu.hugegraph.structure.graph.Shard)

Example 7 with Shard

use of com.baidu.hugegraph.structure.graph.Shard in project incubator-hugegraph-toolchain by apache.

the class BackupManager method readShards.

private List<Shard> readShards(File file) {
    E.checkArgument(file.exists() && file.isFile() && file.canRead(), "Need to specify a readable filter file rather than:" + " %s", file.toString());
    List<Shard> shards = new ArrayList<>();
    try (InputStream is = new FileInputStream(file);
        InputStreamReader isr = new InputStreamReader(is, API.CHARSET);
        BufferedReader reader = new BufferedReader(isr)) {
        String line;
        while ((line = reader.readLine()) != null) {
            shards.addAll(this.readList("shards", Shard.class, line));
        }
    } catch (IOException e) {
        throw new ToolsException("IOException occur while reading %s", e, file.getName());
    }
    return shards;
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Shard(com.baidu.hugegraph.structure.graph.Shard) FileInputStream(java.io.FileInputStream)

Example 8 with Shard

use of com.baidu.hugegraph.structure.graph.Shard in project incubator-hugegraph-toolchain by apache.

the class TraverserManagerTest method testIterateEdgesByShard.

@Test
public void testIterateEdgesByShard() {
    List<Shard> shards = traverser().edgeShards(1 * 1024 * 1024);
    List<Edge> edges = new LinkedList<>();
    for (Shard shard : shards) {
        Iterator<Edge> iter = traverser().iteratorEdges(shard, 1);
        while (iter.hasNext()) {
            edges.add(iter.next());
        }
    }
    Assert.assertEquals(6, edges.size());
}
Also used : Shard(com.baidu.hugegraph.structure.graph.Shard) Edge(com.baidu.hugegraph.structure.graph.Edge) LinkedList(java.util.LinkedList) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 9 with Shard

use of com.baidu.hugegraph.structure.graph.Shard in project incubator-hugegraph-toolchain by apache.

the class TraverserManagerTest method testIterateVerticesByShard.

@Test
public void testIterateVerticesByShard() {
    List<Shard> shards = traverser().vertexShards(1 * 1024 * 1024);
    List<Vertex> vertices = new LinkedList<>();
    for (Shard shard : shards) {
        Iterator<Vertex> iter = traverser().iteratorVertices(shard, 1);
        while (iter.hasNext()) {
            vertices.add(iter.next());
        }
    }
    Assert.assertEquals(6, vertices.size());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Shard(com.baidu.hugegraph.structure.graph.Shard) LinkedList(java.util.LinkedList) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 10 with Shard

use of com.baidu.hugegraph.structure.graph.Shard in project hugegraph-computer by hugegraph.

the class HugeInputSplitFetcher method fetchVertexInputSplits.

@Override
public List<InputSplit> fetchVertexInputSplits() {
    long splitSize = this.config.get(ComputerOptions.INPUT_SPLITS_SIZE);
    int maxSplits = this.config.get(ComputerOptions.INPUT_MAX_SPLITS);
    List<Shard> shards = this.client.traverser().vertexShards(splitSize);
    E.checkArgument(shards.size() <= maxSplits, "Too many shards due to too small splitSize");
    List<InputSplit> splits = new ArrayList<>();
    for (Shard shard : shards) {
        InputSplit split = new InputSplit(shard.start(), shard.end());
        splits.add(split);
    }
    return splits;
}
Also used : ArrayList(java.util.ArrayList) Shard(com.baidu.hugegraph.structure.graph.Shard) InputSplit(com.baidu.hugegraph.computer.core.input.InputSplit)

Aggregations

Shard (com.baidu.hugegraph.structure.graph.Shard)13 Test (org.junit.Test)8 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)6 LinkedList (java.util.LinkedList)6 Edge (com.baidu.hugegraph.structure.graph.Edge)3 Vertex (com.baidu.hugegraph.structure.graph.Vertex)3 ArrayList (java.util.ArrayList)3 BaseClientTest (com.baidu.hugegraph.BaseClientTest)2 InputSplit (com.baidu.hugegraph.computer.core.input.InputSplit)2 Edges (com.baidu.hugegraph.structure.graph.Edges)2 Vertices (com.baidu.hugegraph.structure.graph.Vertices)2 ToolsException (com.baidu.hugegraph.exception.ToolsException)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1