Search in sources :

Example 21 with BackendException

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);
                }
            }
        }
    }
}
Also used : BackendException(com.baidu.hugegraph.backend.BackendException)

Example 22 with BackendException

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;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Entry(java.util.Map.Entry) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 23 with BackendException

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);
}
Also used : Relation(com.baidu.hugegraph.backend.query.Condition.Relation) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 24 with BackendException

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;
}
Also used : RaftBackendStoreProvider(com.baidu.hugegraph.backend.store.raft.RaftBackendStoreProvider) BackendException(com.baidu.hugegraph.backend.BackendException) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 25 with BackendException

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);
}
Also used : BackendException(com.baidu.hugegraph.backend.BackendException) BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

BackendException (com.baidu.hugegraph.backend.BackendException)79 SQLException (java.sql.SQLException)15 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)6 Status (com.alipay.sofa.jraft.Status)5 PeerId (com.alipay.sofa.jraft.entity.PeerId)5 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)5 BytesBuffer (com.baidu.hugegraph.backend.serializer.BytesBuffer)4 Path (java.nio.file.Path)4 Random (java.util.Random)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 RocksDBException (org.rocksdb.RocksDBException)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Id (com.baidu.hugegraph.backend.id.Id)3 Query (com.baidu.hugegraph.backend.query.Query)3 HugeConfig (com.baidu.hugegraph.config.HugeConfig)3 Map (java.util.Map)3 ReadIndexClosure (com.alipay.sofa.jraft.closure.ReadIndexClosure)2 Condition (com.baidu.hugegraph.backend.query.Condition)2 Relation (com.baidu.hugegraph.backend.query.Condition.Relation)2