Search in sources :

Example 1 with Shard

use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.

the class VertexCoreTest method testScanVertex.

@Test
public void testScanVertex() {
    HugeGraph graph = graph();
    // TODO: also support test scan by range
    Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange());
    this.init10VerticesAndCommit();
    List<Vertex> vertices = new LinkedList<>();
    long splitSize = 1 * 1024 * 1024;
    List<Shard> splits = graph.metadata(HugeType.VERTEX, "splits", splitSize);
    for (Shard split : splits) {
        ConditionQuery q = new ConditionQuery(HugeType.VERTEX);
        q.scan(split.start(), split.end());
        vertices.addAll(ImmutableList.copyOf(graph.vertices(q)));
    }
    Assert.assertEquals(10, vertices.size());
}
Also used : FakeVertex(com.baidu.hugegraph.testutil.FakeObjects.FakeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Shard(com.baidu.hugegraph.backend.store.Shard) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with Shard

use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.

the class EdgesAPI method shards.

@GET
@Timed
@Path("shards")
@Compress
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String shards(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("split_size") long splitSize) {
    LOG.debug("Graph [{}] get vertex shards with split size '{}'", graph, splitSize);
    HugeGraph g = graph(manager, graph);
    List<Shard> shards = g.metadata(HugeType.EDGE_OUT, "splits", splitSize);
    return manager.serializer(g).writeList("shards", shards);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) Shard(com.baidu.hugegraph.backend.store.Shard) Path(jakarta.ws.rs.Path) Compress(com.baidu.hugegraph.api.filter.CompressInterceptor.Compress) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 3 with Shard

use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.

the class VerticesAPI method shards.

@GET
@Timed
@Path("shards")
@Compress
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String shards(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("split_size") long splitSize) {
    LOG.debug("Graph [{}] get vertex shards with split size '{}'", graph, splitSize);
    HugeGraph g = graph(manager, graph);
    List<Shard> shards = g.metadata(HugeType.VERTEX, "splits", splitSize);
    return manager.serializer(g).writeList("shards", shards);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) Shard(com.baidu.hugegraph.backend.store.Shard) Path(jakarta.ws.rs.Path) Compress(com.baidu.hugegraph.api.filter.CompressInterceptor.Compress) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 4 with Shard

use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.

the class RocksDBTable method queryByCond.

protected BackendColumnIterator queryByCond(Session session, ConditionQuery query) {
    if (query.containsScanRelation()) {
        E.checkArgument(query.relations().size() == 1, "Invalid scan with multi conditions: %s", query);
        Relation scan = query.relations().iterator().next();
        Shard shard = (Shard) scan.value();
        return this.queryByRange(session, shard, query.page());
    }
    throw new NotSupportException("query: %s", query);
}
Also used : Relation(com.baidu.hugegraph.backend.query.Condition.Relation) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) Shard(com.baidu.hugegraph.backend.store.Shard)

Example 5 with Shard

use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.

the class RangeTest method testRangeOfRegionWithStartKeyAndEndKey.

@Test
public void testRangeOfRegionWithStartKeyAndEndKey() {
    byte[] start = new byte[] { -3, 0x31, 0x30, 0x30, 0x30, 0x77, 0x20, 0x09, 0x38, 0x31, 0x33, 0x32, 0x35 };
    byte[] end = new byte[] { -3, 0x31, 0x33, 0x35, 0x33, 0x32, 0x37, 0x34, 0x31, 0x35, 0x32 };
    Range range = new Range(start, end);
    List<Shard> shards = range.splitEven(0);
    Assert.assertEquals(1, shards.size());
    Assert.assertEquals("/TEwMDB3IAk4MTMyNQ==", shards.get(0).start());
    Assert.assertEquals("/TEzNTMyNzQxNTI=", shards.get(0).end());
    shards = range.splitEven(1);
    Assert.assertEquals(1, shards.size());
    Assert.assertEquals("/TEwMDB3IAk4MTMyNQ==", shards.get(0).start());
    Assert.assertEquals("/TEzNTMyNzQxNTI=", shards.get(0).end());
    shards = range.splitEven(2);
    Assert.assertEquals(3, shards.size());
    Assert.assertEquals("/TEwMDB3IAk4MTMyNQ==", shards.get(0).start());
    Assert.assertEquals("/TExsrHUq560szKZGg==", shards.get(0).end());
    Assert.assertEquals("/TExsrHUq560szKZGg==", shards.get(1).start());
    Assert.assertEquals("/TEzNTMyNzQxNTH//w==", shards.get(1).end());
    Assert.assertEquals("/TEzNTMyNzQxNTH//w==", shards.get(2).start());
    Assert.assertEquals("/TEzNTMyNzQxNTI=", shards.get(2).end());
    for (int i = 3; i < 100; i++) {
        range.splitEven(i);
    }
}
Also used : Range(com.baidu.hugegraph.backend.store.BackendTable.ShardSplitter.Range) Shard(com.baidu.hugegraph.backend.store.Shard) Test(org.junit.Test)

Aggregations

Shard (com.baidu.hugegraph.backend.store.Shard)15 Test (org.junit.Test)6 HugeGraph (com.baidu.hugegraph.HugeGraph)4 Range (com.baidu.hugegraph.backend.store.BackendTable.ShardSplitter.Range)4 ArrayList (java.util.ArrayList)4 BackendException (com.baidu.hugegraph.backend.BackendException)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 Relation (com.baidu.hugegraph.backend.query.Condition.Relation)3 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)3 ResultSet (com.datastax.driver.core.ResultSet)3 List (java.util.List)3 Set (java.util.Set)3 Compress (com.baidu.hugegraph.api.filter.CompressInterceptor.Compress)2 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)2 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)2 HugeKeys (com.baidu.hugegraph.type.define.HugeKeys)2 Timed (com.codahale.metrics.annotation.Timed)2 TokenRange (com.datastax.driver.core.TokenRange)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2