Search in sources :

Example 1 with BackendException

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

the class GraphManager method checkBackendVersionOrExit.

private void checkBackendVersionOrExit(HugeConfig config) {
    for (String graph : this.graphs()) {
        // TODO: close tx from main thread
        HugeGraph hugegraph = this.graph(graph);
        if (!hugegraph.backendStoreFeatures().supportsPersistence()) {
            hugegraph.initBackend();
            if (this.requireAuthentication()) {
                String token = config.get(ServerOptions.AUTH_ADMIN_TOKEN);
                try {
                    this.authenticator.initAdminUser(token);
                } catch (Exception e) {
                    throw new BackendException("The backend store of '%s' can't " + "initialize admin user", hugegraph.name());
                }
            }
        }
        BackendStoreSystemInfo info = hugegraph.backendStoreSystemInfo();
        if (!info.exists()) {
            throw new BackendException("The backend store of '%s' has not been initialized", hugegraph.name());
        }
        if (!info.checkVersion()) {
            throw new BackendException("The backend store version is inconsistent");
        }
    }
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) BackendStoreSystemInfo(com.baidu.hugegraph.backend.store.BackendStoreSystemInfo) BackendException(com.baidu.hugegraph.backend.BackendException) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) AuthenticationException(org.apache.tinkerpop.gremlin.server.auth.AuthenticationException) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 2 with BackendException

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

the class CassandraSessionPool method open.

@Override
public synchronized void open() {
    if (this.opened()) {
        throw new BackendException("Please close the old SessionPool " + "before opening a new one");
    }
    HugeConfig config = this.config();
    // Contact options
    String hosts = config.get(CassandraOptions.CASSANDRA_HOST);
    int port = config.get(CassandraOptions.CASSANDRA_PORT);
    assert this.cluster == null || this.cluster.isClosed();
    /*
         * We disable cassandra metrics through withoutMetrics(), due to
         * metrics versions are incompatible, java11 glassfish use metrics 4,
         * but cassandra use metrics 3.
         * TODO: fix it after after cassandra upgrade metrics version
         */
    Builder builder = Cluster.builder().addContactPoints(hosts.split(",")).withoutMetrics().withPort(port);
    // Timeout options
    int connTimeout = config.get(CassandraOptions.CASSANDRA_CONN_TIMEOUT);
    int readTimeout = config.get(CassandraOptions.CASSANDRA_READ_TIMEOUT);
    SocketOptions socketOptions = new SocketOptions();
    socketOptions.setConnectTimeoutMillis(connTimeout * SECOND);
    socketOptions.setReadTimeoutMillis(readTimeout * SECOND);
    builder.withSocketOptions(socketOptions);
    // Credential options
    String username = config.get(CassandraOptions.CASSANDRA_USERNAME);
    String password = config.get(CassandraOptions.CASSANDRA_PASSWORD);
    if (!username.isEmpty()) {
        builder.withCredentials(username, password);
    }
    // Compression options
    String compression = config.get(CassandraOptions.CASSANDRA_COMPRESSION);
    builder.withCompression(Compression.valueOf(compression.toUpperCase()));
    this.cluster = builder.build();
}
Also used : Builder(com.datastax.driver.core.Cluster.Builder) SocketOptions(com.datastax.driver.core.SocketOptions) HugeConfig(com.baidu.hugegraph.config.HugeConfig) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 3 with BackendException

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

the class RocksDBStore method resumeSnapshot.

@Override
public void resumeSnapshot(String snapshotPrefix, boolean deleteSnapshot) {
    Lock readLock = this.storeLock.readLock();
    readLock.lock();
    try {
        if (!this.opened()) {
            return;
        }
        Map<String, RocksDBSessions> snapshotPaths = new HashMap<>();
        for (Map.Entry<String, RocksDBSessions> entry : this.dbs.entrySet()) {
            RocksDBSessions sessions = entry.getValue();
            String snapshotPath = sessions.buildSnapshotPath(snapshotPrefix);
            LOG.debug("The origin data path: {}", entry.getKey());
            if (!deleteSnapshot) {
                snapshotPath = sessions.hardLinkSnapshot(snapshotPath);
            }
            LOG.debug("The snapshot data path: {}", snapshotPath);
            snapshotPaths.put(snapshotPath, sessions);
        }
        for (Map.Entry<String, RocksDBSessions> entry : snapshotPaths.entrySet()) {
            String snapshotPath = entry.getKey();
            RocksDBSessions sessions = entry.getValue();
            sessions.resumeSnapshot(snapshotPath);
            if (deleteSnapshot) {
                // Delete empty snapshot parent directory
                Path parentPath = Paths.get(snapshotPath).getParent();
                if (Files.list(parentPath).count() == 0) {
                    FileUtils.deleteDirectory(parentPath.toFile());
                }
            }
        }
        LOG.info("The store '{}' resume snapshot successfully", this);
    } catch (RocksDBException | IOException e) {
        throw new BackendException("Failed to resume snapshot", e);
    } finally {
        readLock.unlock();
    }
}
Also used : Path(java.nio.file.Path) RocksDBException(org.rocksdb.RocksDBException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 4 with BackendException

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

the class RocksDBStore method waitOpenFinish.

private void waitOpenFinish(List<Future<?>> futures, ExecutorService openPool) {
    for (Future<?> future : futures) {
        try {
            future.get();
        } catch (Throwable e) {
            throw new BackendException("Failed to open RocksDB store", e);
        }
    }
    if (openPool.isShutdown()) {
        return;
    }
    /*
         * Transfer the session holder from db-open thread to main thread,
         * otherwise once the db-open thread pool is closed, we can no longer
         * close the session created by it, which will cause the rocksdb
         * instance fail to close
         */
    this.useSessions();
    try {
        Consumers.executeOncePerThread(openPool, OPEN_POOL_THREADS, this::closeSessions);
    } catch (InterruptedException e) {
        throw new BackendException("Failed to close session opened by " + "open-pool");
    }
    boolean terminated = false;
    openPool.shutdown();
    try {
        terminated = openPool.awaitTermination(OPEN_TIMEOUT, TimeUnit.SECONDS);
    } catch (Throwable e) {
        throw new BackendException("Failed to wait db-open thread pool shutdown", e);
    }
    if (!terminated) {
        LOG.warn("Timeout when waiting db-open thread pool shutdown");
    }
    openPool.shutdownNow();
}
Also used : BackendException(com.baidu.hugegraph.backend.BackendException)

Example 5 with BackendException

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

the class OpenedRocksDB method createCheckpoint.

public void createCheckpoint(String targetPath) {
    Path parentName = Paths.get(targetPath).getParent().getFileName();
    assert parentName.toString().startsWith("snapshot") : targetPath;
    // https://github.com/facebook/rocksdb/wiki/Checkpoints
    try (Checkpoint checkpoint = Checkpoint.create(this.rocksdb)) {
        String tempPath = targetPath + "_temp";
        File tempFile = new File(tempPath);
        FileUtils.deleteDirectory(tempFile);
        LOG.debug("Deleted temp directory {}", tempFile);
        FileUtils.forceMkdir(tempFile.getParentFile());
        checkpoint.createCheckpoint(tempPath);
        File snapshotFile = new File(targetPath);
        FileUtils.deleteDirectory(snapshotFile);
        LOG.debug("Deleted stale directory {}", snapshotFile);
        if (!tempFile.renameTo(snapshotFile)) {
            throw new IOException(String.format("Failed to rename %s to %s", tempFile, snapshotFile));
        }
    } catch (Exception e) {
        throw new BackendException("Failed to create checkpoint at path %s", e, targetPath);
    }
}
Also used : Path(java.nio.file.Path) Checkpoint(org.rocksdb.Checkpoint) IOException(java.io.IOException) File(java.io.File) BackendException(com.baidu.hugegraph.backend.BackendException) IOException(java.io.IOException) 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