Search in sources :

Example 1 with ConnectionException

use of com.baidu.hugegraph.exception.ConnectionException in project incubator-hugegraph by apache.

the class RocksDBStore method open.

protected RocksDBSessions open(HugeConfig config, String dataPath, String walPath, List<String> tableNames) {
    LOG.info("Opening RocksDB with data path: {}", dataPath);
    RocksDBSessions sessions = null;
    try {
        sessions = this.openSessionPool(config, dataPath, walPath, tableNames);
    } catch (RocksDBException e) {
        RocksDBSessions origin = this.dbs.get(dataPath);
        if (origin != null) {
            if (e.getMessage().contains("No locks available")) {
                /*
                     * Open twice, copy a RocksDBSessions reference, since from
                     * v0.11.2 release we don't support multi graphs share
                     * rocksdb instance (before v0.11.2 graphs with different
                     * CF-prefix share one rocksdb instance and data path),
                     * so each graph has its independent data paths, but multi
                     * CFs may share same optimized disk(or optimized disk path).
                     */
                sessions = origin.copy(config, this.database, this.store);
            }
        }
        if (e.getMessage().contains("Column family not found")) {
            if (this.isSchemaStore()) {
                LOG.info("Failed to open RocksDB '{}' with database '{}'," + " try to init CF later", dataPath, this.database);
            }
            List<String> none;
            boolean existsOtherKeyspace = existsOtherKeyspace(dataPath);
            if (existsOtherKeyspace) {
                // Open a keyspace after other keyspace closed
                // Set to empty list to open old CFs(of other keyspace)
                none = ImmutableList.of();
            } else {
                // Before init the first keyspace
                none = null;
            }
            try {
                sessions = this.openSessionPool(config, dataPath, walPath, none);
            } catch (RocksDBException e1) {
                e = e1;
            }
            if (sessions == null && !existsOtherKeyspace) {
                LOG.error("Failed to open RocksDB with default CF, " + "is there data for other programs: {}", dataPath);
            }
        }
        if (sessions == null) {
            // Error after trying other ways
            LOG.error("Failed to open RocksDB '{}'", dataPath, e);
            throw new ConnectionException("Failed to open RocksDB '%s'", e, dataPath);
        }
    }
    if (sessions != null) {
        // May override the original session pool
        this.dbs.put(dataPath, sessions);
        sessions.session().open();
        LOG.debug("Store opened: {}", dataPath);
    }
    return sessions;
}
Also used : RocksDBException(org.rocksdb.RocksDBException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ConnectionException(com.baidu.hugegraph.exception.ConnectionException)

Example 2 with ConnectionException

use of com.baidu.hugegraph.exception.ConnectionException in project incubator-hugegraph by apache.

the class HbaseStore method open.

@Override
public synchronized void open(HugeConfig config) {
    E.checkNotNull(config, "config");
    this.vertexLogicPartitions = config.get(HbaseOptions.HBASE_VERTEX_PARTITION).shortValue();
    this.edgeLogicPartitions = config.get(HbaseOptions.HBASE_EDGE_PARTITION).shortValue();
    if (this.sessions == null) {
        this.sessions = new HbaseSessions(config, this.namespace, this.store);
    }
    assert this.sessions != null;
    if (!this.sessions.closed()) {
        LOG.debug("Store {} has been opened before", this.store);
        this.sessions.useSession();
        return;
    }
    try {
        // NOTE: won't throw error even if connection refused
        this.sessions.open();
    } catch (Throwable e) {
        LOG.error("Failed to open HBase '{}'", this.store, e);
        throw new ConnectionException("Failed to connect to HBase", e);
    }
    this.sessions.session().open();
    LOG.debug("Store opened: {}", this.store);
}
Also used : ConnectionException(com.baidu.hugegraph.exception.ConnectionException)

Example 3 with ConnectionException

use of com.baidu.hugegraph.exception.ConnectionException in project incubator-hugegraph by apache.

the class CassandraStore method open.

@Override
public synchronized void open(HugeConfig config) {
    LOG.debug("Store open: {}", this.store);
    E.checkNotNull(config, "config");
    if (this.sessions == null) {
        this.sessions = new CassandraSessionPool(config, this.keyspace, this.store);
    }
    assert this.sessions != null;
    if (!this.sessions.closed()) {
        // TODO: maybe we should throw an exception here instead of ignore
        LOG.debug("Store {} has been opened before", this.store);
        this.sessions.useSession();
        return;
    }
    this.conf = config;
    String graphStore = this.conf.get(CoreOptions.STORE_GRAPH);
    this.isGraphStore = this.store.equals(graphStore);
    // Init cluster
    this.sessions.open();
    // Init a session for current thread
    try {
        LOG.debug("Store connect with keyspace: {}", this.keyspace);
        try {
            this.sessions.session().open();
        } catch (InvalidQueryException e) {
            // TODO: the error message may be changed in different versions
            if (!e.getMessage().contains(String.format("Keyspace '%s' does not exist", this.keyspace))) {
                throw e;
            }
            if (this.isSchemaStore()) {
                LOG.info("Failed to connect keyspace: {}, " + "try to init keyspace later", this.keyspace);
            }
        }
    } catch (Throwable e) {
        try {
            this.sessions.close();
        } catch (Throwable e2) {
            LOG.warn("Failed to close cluster after an error", e2);
        }
        throw new ConnectionException("Failed to connect to Cassandra", e);
    }
    LOG.debug("Store opened: {}", this.store);
}
Also used : InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) ConnectionException(com.baidu.hugegraph.exception.ConnectionException)

Example 4 with ConnectionException

use of com.baidu.hugegraph.exception.ConnectionException in project incubator-hugegraph by apache.

the class MysqlStore method open.

@Override
public synchronized void open(HugeConfig config) {
    LOG.debug("Store open: {}", this.store);
    E.checkNotNull(config, "config");
    if (this.sessions != null && !this.sessions.closed()) {
        LOG.debug("Store {} has been opened before", this.store);
        this.sessions.useSession();
        return;
    }
    this.sessions = this.openSessionPool(config);
    if (this.sessions.existsDatabase()) {
        LOG.debug("Store connect with database: {}", this.database);
        try {
            this.sessions.open();
        } catch (Throwable e) {
            throw new ConnectionException("Failed to connect to MySQL", e);
        }
        try {
            this.sessions.session().open();
        } catch (Throwable e) {
            try {
                this.sessions.close();
            } catch (Throwable e2) {
                LOG.warn("Failed to close connection after an error", e2);
            }
            throw new BackendException("Failed to open database", e);
        }
    } else {
        if (this.isSchemaStore()) {
            LOG.info("Failed to open database '{}', " + "try to init database later", this.database);
        }
        this.sessions.session();
    }
    LOG.debug("Store opened: {}", this.store);
}
Also used : ConnectionException(com.baidu.hugegraph.exception.ConnectionException) BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

ConnectionException (com.baidu.hugegraph.exception.ConnectionException)4 BackendException (com.baidu.hugegraph.backend.BackendException)1 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RocksDBException (org.rocksdb.RocksDBException)1