use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RaftNode method waitIfBusy.
private void waitIfBusy() {
int counter = this.busyCounter.get();
if (counter <= 0) {
return;
}
// It may lead many thread sleep, but this is exactly what I want
long time = counter * RaftSharedContext.BUSY_SLEEP_FACTOR;
LOG.info("The node {} will try to sleep {} ms", this.node, time);
try {
Thread.sleep(time);
} catch (InterruptedException e) {
// Throw busy exception if the request is timeout
throw new BackendException("The raft backend store is busy", e);
} finally {
if (this.busyCounter.get() > 0) {
synchronized (this) {
if (this.busyCounter.get() > 0) {
counter = this.busyCounter.decrementAndGet();
LOG.info("Decrease busy counter: [{}]", counter);
}
}
}
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class TextBackendEntry method copyHead.
public TextBackendEntry copyHead(int count) {
TextBackendEntry clone;
try {
clone = (TextBackendEntry) this.clone();
} catch (CloneNotSupportedException e) {
throw new BackendException(e);
}
clone.resetColumns();
// Copy the head count columns
Iterator<Entry<String, String>> it = this.columns.entrySet().iterator();
for (int i = 0; it.hasNext() && i < count; i++) {
Entry<String, String> entry = it.next();
clone.columns.put(entry.getKey(), entry.getValue());
}
return clone;
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class ConditionQuery method userpropValuesString.
/**
* This method is only used for secondary index scenario,
* its relation must be EQ
* @param fields the user property fields
* @return the corresponding user property serial values of fields
*/
public String userpropValuesString(List<Id> fields) {
List<Object> values = new ArrayList<>(fields.size());
for (Id field : fields) {
boolean got = false;
for (Relation r : this.userpropRelations()) {
if (r.key().equals(field) && !r.isSysprop()) {
E.checkState(r.relation == RelationType.EQ || r.relation == RelationType.CONTAINS, "Method userpropValues(List<String>) only " + "used for secondary index, " + "relation must be EQ or CONTAINS, but got %s", r.relation());
values.add(r.serialValue());
got = true;
}
}
if (!got) {
throw new BackendException("No such userprop named '%s' in the query '%s'", field, this);
}
}
return concatValues(values);
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class BackendProviderFactory method newProvider.
private static BackendStoreProvider newProvider(HugeConfig config) {
String backend = config.get(CoreOptions.BACKEND).toLowerCase();
String graph = config.get(CoreOptions.STORE);
if (InMemoryDBStoreProvider.matchType(backend)) {
return InMemoryDBStoreProvider.instance(graph);
}
Class<? extends BackendStoreProvider> clazz = providers.get(backend);
BackendException.check(clazz != null, "Not exists BackendStoreProvider: %s", backend);
assert BackendStoreProvider.class.isAssignableFrom(clazz);
BackendStoreProvider instance = null;
try {
instance = clazz.newInstance();
} catch (Exception e) {
throw new BackendException(e);
}
BackendException.check(backend.equals(instance.type()), "BackendStoreProvider with type '%s' " + "can't be opened by key '%s'", instance.type(), backend);
return instance;
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class BackendProviderFactory method register.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void register(String name, String classPath) {
ClassLoader classLoader = BackendProviderFactory.class.getClassLoader();
Class<?> clazz = null;
try {
clazz = classLoader.loadClass(classPath);
} catch (Exception e) {
throw new BackendException(e);
}
// Check subclass
boolean subclass = BackendStoreProvider.class.isAssignableFrom(clazz);
BackendException.check(subclass, "Class '%s' is not a subclass of " + "class BackendStoreProvider", classPath);
// Check exists
BackendException.check(!providers.containsKey(name), "Exists BackendStoreProvider: %s (%s)", name, providers.get(name));
// Register class
providers.put(name, (Class) clazz);
}
Aggregations