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");
}
}
}
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();
}
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();
}
}
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();
}
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);
}
}
Aggregations