use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class PerfExample2 method testInsert.
@Override
protected void testInsert(GraphManager graph, int times, int multiple) {
List<Object> personIds = new ArrayList<>(PERSON_NUM * multiple);
List<Object> softwareIds = new ArrayList<>(SOFTWARE_NUM * multiple);
for (int time = 0; time < times; time++) {
LOG.debug("============== random person vertex ===============");
for (int i = 0; i < PERSON_NUM * multiple; i++) {
Vertex vertex = graph.addVertex(T.label, "person");
personIds.add(vertex.id());
LOG.debug("Add person: {}", vertex);
}
LOG.debug("============== random software vertex ============");
for (int i = 0; i < SOFTWARE_NUM * multiple; i++) {
Vertex vertex = graph.addVertex(T.label, "software");
softwareIds.add(vertex.id());
LOG.debug("Add software: {}", vertex);
}
LOG.debug("========== random knows & created edges ==========");
for (int i = 0; i < EDGE_NUM / 2 * multiple; i++) {
Random random = new Random();
// Add edge: person --knows-> person
Object p1 = personIds.get(random.nextInt(PERSON_NUM));
Object p2 = personIds.get(random.nextInt(PERSON_NUM));
graph.getVertex(p1).addEdge("knows", graph.getVertex(p2));
// Add edge: person --created-> software
Object p3 = personIds.get(random.nextInt(PERSON_NUM));
Object s1 = softwareIds.get(random.nextInt(SOFTWARE_NUM));
graph.getVertex(p3).addEdge("created", graph.getVertex(s1));
}
try {
graph.tx().commit();
} catch (BackendException e) {
if (e.getCause() instanceof NoHostAvailableException) {
LOG.warn("Failed to commit tx: {}", e.getMessage());
} else {
throw e;
}
}
this.vertices.addAll(personIds);
this.vertices.addAll(softwareIds);
personIds.clear();
softwareIds.clear();
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlStore method init.
@Override
public void init() {
this.checkClusterConnected();
this.sessions.createDatabase();
try {
// Open a new session connected with specified database
this.sessions.session().open();
} catch (Exception e) {
throw new BackendException("Failed to connect database '%s'", this.database);
}
this.checkOpened();
this.initTables();
LOG.debug("Store initialized: {}", this.store);
}
use of com.baidu.hugegraph.backend.BackendException 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);
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlStore method beginTx.
@Override
public void beginTx() {
this.checkOpened();
Session session = this.sessions.session();
try {
session.begin();
} catch (SQLException e) {
throw new BackendException("Failed to open transaction", e);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class LZ4Util method compress.
public static BytesBuffer compress(byte[] bytes, int blockSize, float bufferRatio) {
float ratio = bufferRatio <= 0.0F ? DEFAULT_BUFFER_RATIO : bufferRatio;
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4Compressor compressor = factory.fastCompressor();
int initBufferSize = Math.round(bytes.length / ratio);
BytesBuffer buf = new BytesBuffer(initBufferSize);
LZ4BlockOutputStream lz4Output = new LZ4BlockOutputStream(buf, blockSize, compressor);
try {
lz4Output.write(bytes);
lz4Output.close();
} catch (IOException e) {
throw new BackendException("Failed to compress", e);
}
/*
* If need to perform reading outside the method,
* remember to call forReadWritten()
*/
return buf;
}
Aggregations