use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.
the class RangeTest method testRangeOfOnlyOneRegion.
@Test
public void testRangeOfOnlyOneRegion() {
// The startKey and endKey is "", if it's the only region of table
Range range = new Range(START, END);
List<Shard> shards = range.splitEven(0);
Assert.assertEquals(1, shards.size());
Assert.assertEquals(Strings.EMPTY, shards.get(0).start());
Assert.assertEquals(Strings.EMPTY, shards.get(0).end());
shards = range.splitEven(1);
Assert.assertEquals(1, shards.size());
Assert.assertEquals(Strings.EMPTY, shards.get(0).start());
Assert.assertEquals(Strings.EMPTY, shards.get(0).end());
shards = range.splitEven(3);
Assert.assertEquals(3, shards.size());
Assert.assertEquals(Strings.EMPTY, shards.get(0).start());
Assert.assertEquals("VVVVVVVVVVVVVVVVVVVVVQ==", shards.get(0).end());
Assert.assertEquals("VVVVVVVVVVVVVVVVVVVVVQ==", shards.get(1).start());
Assert.assertEquals("qqqqqqqqqqqqqqqqqqqqqg==", shards.get(1).end());
Assert.assertEquals("qqqqqqqqqqqqqqqqqqqqqg==", shards.get(2).start());
Assert.assertEquals(Strings.EMPTY, shards.get(2).end());
for (int i = 4; i < 100; i++) {
range.splitEven(i);
}
}
use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.
the class RangeTest method testRangeOfRegionWithStartKey.
@Test
public void testRangeOfRegionWithStartKey() {
byte[] start = new byte[] { -3, 0x35, 0x30, 0x30, 0x30, 0x77, 0x4e, -37, 0x31, 0x31, 0x30, 0x30, 0x30, 0x37, 0x36, 0x33 };
Range range = new Range(start, END);
List<Shard> shards = range.splitEven(0);
Assert.assertEquals(1, shards.size());
Assert.assertEquals("/TUwMDB3TtsxMTAwMDc2Mw==", shards.get(0).start());
Assert.assertEquals(Strings.EMPTY, shards.get(0).end());
shards = range.splitEven(1);
Assert.assertEquals(1, shards.size());
Assert.assertEquals("/TUwMDB3TtsxMTAwMDc2Mw==", shards.get(0).start());
Assert.assertEquals(Strings.EMPTY, shards.get(0).end());
shards = range.splitEven(2);
Assert.assertEquals(2, shards.size());
Assert.assertEquals("/TUwMDB3TtsxMTAwMDc2Mw==", shards.get(0).start());
Assert.assertEquals("/pqYGBg7p22YmJgYGBubGQ==", shards.get(0).end());
Assert.assertEquals("/pqYGBg7p22YmJgYGBubGQ==", shards.get(1).start());
Assert.assertEquals(Strings.EMPTY, shards.get(1).end());
for (int i = 3; i < 100; i++) {
range.splitEven(i);
}
}
use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.
the class CassandraShard method getSplits.
/**
* Get splits of a table
* @param splitPartitions: expected partitions count per split
* @param splitSize: expected size(bytes) per split,
* splitPartitions will be ignored if splitSize is passed
* @return a list of Shard
*/
public List<Shard> getSplits(long splitPartitions, long splitSize) {
// Canonical ranges, split into pieces, fetch the splits in parallel
ExecutorService executor = new ThreadPoolExecutor(0, 128, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
List<Shard> splits = new ArrayList<>();
try {
List<Future<List<Shard>>> futures = new ArrayList<>();
// Canonical ranges and nodes holding replicas
Map<TokenRange, Set<Host>> masterRangeNodes = getRangeMap();
for (TokenRange range : masterRangeNodes.keySet()) {
/*
* For each token range, pick a live owner and ask it to
* compute bite-sized splits.
*/
futures.add(executor.submit(new SplitCallable(range, splitPartitions, splitSize)));
}
// Wait until we have all the results back
for (Future<List<Shard>> future : futures) {
try {
splits.addAll(future.get());
} catch (Exception e) {
throw new BackendException("Can't get cassandra shards", e);
}
}
assert splits.size() > masterRangeNodes.size();
} finally {
executor.shutdownNow();
}
Collections.shuffle(splits, new Random(System.nanoTime()));
return splits;
}
use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.
the class CassandraTable method relation2Cql.
protected Clause relation2Cql(Relation relation) {
String key = relation.serialKey().toString();
Object value = relation.serialValue();
switch(relation.relation()) {
case EQ:
return QueryBuilder.eq(key, value);
case GT:
return QueryBuilder.gt(key, value);
case GTE:
return QueryBuilder.gte(key, value);
case LT:
return QueryBuilder.lt(key, value);
case LTE:
return QueryBuilder.lte(key, value);
case IN:
return Clauses.in(key, (List<?>) value);
case CONTAINS_VALUE:
return QueryBuilder.contains(key, value);
case CONTAINS_KEY:
return QueryBuilder.containsKey(key, value);
case SCAN:
String[] col = pkColumnName().stream().map(pk -> formatKey(pk)).toArray(String[]::new);
Shard shard = (Shard) value;
Object start = QueryBuilder.raw(shard.start());
Object end = QueryBuilder.raw(shard.end());
return Clauses.and(QueryBuilder.gte(QueryBuilder.token(col), start), QueryBuilder.lt(QueryBuilder.token(col), end));
// return QueryBuilder.like(key, value);
case NEQ:
default:
throw new NotSupportException("relation '%s'", relation);
}
}
use of com.baidu.hugegraph.backend.store.Shard in project incubator-hugegraph by apache.
the class InMemoryDBTable method queryByRange.
private Iterator<BackendEntry> queryByRange(ConditionQuery query) {
E.checkArgument(query.relations().size() == 1, "Invalid scan with multi conditions: %s", query);
Condition.Relation scan = query.relations().iterator().next();
Shard shard = (Shard) scan.value();
int start = Strings.isNullOrEmpty(shard.start()) ? 0 : Long.valueOf(shard.start()).intValue();
int end = Strings.isNullOrEmpty(shard.end()) ? 0 : Long.valueOf(shard.end()).intValue();
List<BackendEntry> rs = new ArrayList<>(end - start);
Iterator<BackendEntry> iterator = this.store.values().iterator();
int i = 0;
while (iterator.hasNext() && i++ < end) {
BackendEntry entry = iterator.next();
if (i > start) {
rs.add(entry);
}
}
return rs.iterator();
}
Aggregations