Search in sources :

Example 66 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class MysqlSessions method buildUri.

protected String buildUri(boolean withConnParams, boolean withDB, boolean autoReconnect, Integer timeout) {
    String url = this.buildUrlPrefix(withDB);
    boolean forcedAutoReconnect = this.config.get(MysqlOptions.JDBC_FORCED_AUTO_RECONNECT);
    int maxTimes = this.config.get(MysqlOptions.JDBC_RECONNECT_MAX_TIMES);
    int interval = this.config.get(MysqlOptions.JDBC_RECONNECT_INTERVAL);
    String sslMode = this.config.get(MysqlOptions.JDBC_SSL_MODE);
    E.checkArgument(url.startsWith(JDBC_PREFIX), "The url must start with '%s': '%s'", JDBC_PREFIX, url);
    String urlWithoutJdbc = url.substring(JDBC_PREFIX.length());
    URIBuilder builder;
    try {
        builder = this.newConnectionURIBuilder(urlWithoutJdbc);
    } catch (URISyntaxException e) {
        throw new BackendException("Invalid url '%s'", e, url);
    }
    if (forcedAutoReconnect) {
        autoReconnect = true;
    }
    if (withConnParams || forcedAutoReconnect) {
        builder.setParameter("characterEncoding", "utf-8").setParameter("rewriteBatchedStatements", "true").setParameter("useServerPrepStmts", "false").setParameter("autoReconnect", String.valueOf(autoReconnect)).setParameter("maxReconnects", String.valueOf(maxTimes)).setParameter("initialTimeout", String.valueOf(interval));
    }
    if (timeout != null) {
        builder.setParameter("socketTimeout", String.valueOf(timeout));
    }
    builder.setParameter("useSSL", sslMode);
    return JDBC_PREFIX + builder.toString();
}
Also used : URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 67 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class RocksDBStdSessions method cf.

private CFHandle cf(String cfName) {
    CFHandle cfh = this.rocksdb.cf(cfName);
    if (cfh == null) {
        throw new BackendException("Table '%s' is not opened", cfName);
    }
    cfh.open();
    return cfh;
}
Also used : CFHandle(com.baidu.hugegraph.backend.store.rocksdb.OpenedRocksDB.CFHandle) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 68 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class RocksDBStdSessions method resumeSnapshot.

@Override
public void resumeSnapshot(String snapshotPath) {
    File originDataDir = new File(this.dataPath);
    File snapshotDir = new File(snapshotPath);
    try {
        /*
             * Close current instance first
             * NOTE: must close rocksdb instance before deleting file directory,
             * if close after copying the snapshot directory to origin position,
             * it may produce dirty data.
             */
        this.forceCloseRocksDB();
        // Delete origin data directory
        if (originDataDir.exists()) {
            LOG.info("Delete origin data directory {}", originDataDir);
            FileUtils.deleteDirectory(originDataDir);
        }
        // Move snapshot directory to origin data directory
        FileUtils.moveDirectory(snapshotDir, originDataDir);
        LOG.info("Move snapshot directory {} to {}", snapshotDir, originDataDir);
        // Reload rocksdb instance
        this.reloadRocksDB();
    } catch (Exception e) {
        throw new BackendException("Failed to resume snapshot '%s' to' %s'", e, snapshotDir, this.dataPath);
    }
}
Also used : File(java.io.File) BackendException(com.baidu.hugegraph.backend.BackendException) RocksDBException(org.rocksdb.RocksDBException) NoSuchElementException(java.util.NoSuchElementException) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 69 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class MysqlTable method createTable.

protected void createTable(Session session, TableDefine tableDefine) {
    StringBuilder sql = new StringBuilder();
    sql.append("CREATE TABLE IF NOT EXISTS ");
    sql.append(this.table()).append(" (");
    // Add columns
    for (Map.Entry<HugeKeys, String> entry : tableDefine.columns().entrySet()) {
        sql.append(formatKey(entry.getKey()));
        sql.append(" ");
        sql.append(entry.getValue());
        sql.append(", ");
    }
    // Specified primary keys
    sql.append(" PRIMARY KEY (");
    int i = 0;
    int size = tableDefine.keys().size();
    for (HugeKeys key : tableDefine.keys()) {
        sql.append(formatKey(key));
        if (++i != size) {
            sql.append(", ");
        }
    }
    sql.append("))");
    sql.append(this.engine(session));
    sql.append(";");
    LOG.debug("Create table: {}", sql);
    try {
        session.execute(sql.toString());
    } catch (SQLException e) {
        throw new BackendException("Failed to create table with '%s'", e, sql);
    }
}
Also used : SQLException(java.sql.SQLException) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) Map(java.util.Map) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 70 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class MysqlTable method insert.

/**
 * Insert an entire row
 */
@Override
public void insert(Session session, MysqlBackendEntry.Row entry) {
    String template = this.buildInsertTemplate(entry);
    PreparedStatement insertStmt;
    try {
        // Create or get insert prepare statement
        insertStmt = session.prepareStatement(template);
        int i = 1;
        for (Object object : this.buildInsertObjects(entry)) {
            insertStmt.setObject(i++, object);
        }
    } catch (SQLException e) {
        throw new BackendException("Failed to prepare statement '%s'" + "for entry: %s", template, entry);
    }
    session.add(insertStmt);
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) 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