use of com.baidu.hugegraph.backend.BackendException 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.BackendException in project incubator-hugegraph by apache.
the class CassandraTable method query.
protected <R> Iterator<R> query(Query query, Function<Statement, ResultSet> fetcher, BiFunction<Query, ResultSet, Iterator<R>> parser) {
ExtendableIterator<R> rs = new ExtendableIterator<>();
if (query.limit() == 0L && !query.noLimit()) {
LOG.debug("Return empty result(limit=0) for query {}", query);
return rs;
}
List<Select> selects = this.query2Select(this.table(), query);
try {
for (Select select : selects) {
ResultSet results = fetcher.apply(select);
rs.extend(parser.apply(query, results));
}
} catch (DriverException e) {
LOG.debug("Failed to query [{}], detail statement: {}", query, selects, e);
throw new BackendException("Failed to query [%s]", e, query);
}
LOG.debug("Return {} for query {}", rs, query);
return rs;
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class SerializerFactory method register.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void register(String name, String classPath) {
ClassLoader classLoader = SerializerFactory.class.getClassLoader();
Class<?> clazz;
try {
clazz = classLoader.loadClass(classPath);
} catch (Exception e) {
throw new BackendException("Invalid class: '%s'", e, classPath);
}
// Check subclass
if (!AbstractSerializer.class.isAssignableFrom(clazz)) {
throw new BackendException("Class is not a subclass of class " + "AbstractSerializer: '%s'", classPath);
}
// Check exists
if (serializers.containsKey(name)) {
throw new BackendException("Exists serializer: %s(Class '%s')", name, serializers.get(name).getName());
}
// Register class
serializers.put(name, (Class) clazz);
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class SerializerFactory method serializer.
public static AbstractSerializer serializer(HugeConfig config, String name) {
name = name.toLowerCase();
switch(name) {
case "binary":
return new BinarySerializer(config);
case "binaryscatter":
return new BinaryScatterSerializer(config);
case "text":
return new TextSerializer(config);
default:
}
Class<? extends AbstractSerializer> clazz = serializers.get(name);
if (clazz == null) {
throw new BackendException("Not exists serializer: '%s'", name);
}
assert AbstractSerializer.class.isAssignableFrom(clazz);
try {
return clazz.getConstructor(HugeConfig.class).newInstance(config);
} catch (Exception e) {
throw new BackendException(e);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RaftGroupManagerImpl method removePeer.
@Override
public String removePeer(String endpoint) {
E.checkArgument(this.raftNode.selfIsLeader(), "Operation add_peer can only be executed on leader");
PeerId peerId = PeerId.parsePeer(endpoint);
RaftClosure<?> future = new RaftClosure<>();
try {
this.raftNode.node().removePeer(peerId, future);
future.waitFinished();
} catch (Throwable e) {
throw new BackendException("Failed to remove peer '%s'", e, endpoint);
}
return peerId.toString();
}
Aggregations