use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class PerfExample1 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++) {
Random random = new Random();
int age = random.nextInt(70);
String name = "P" + random.nextInt();
Vertex vertex = graph.addVertex(T.label, "person", "name", name, "age", age);
personIds.add(vertex.id());
LOG.debug("Add person: {}", vertex);
}
LOG.debug("============== random software vertex ============");
for (int i = 0; i < SOFTWARE_NUM * multiple; i++) {
Random random = new Random();
int price = random.nextInt(10000) + 1;
String name = "S" + random.nextInt();
Vertex vertex = graph.addVertex(T.label, "software", "name", name, "lang", "java", "price", price);
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 HbaseStore method init.
@Override
public void init() {
this.checkConnectionOpened();
// Create namespace
try {
this.sessions.createNamespace();
} catch (NamespaceExistException ignored) {
// Ignore due to both schema & graph store would create namespace
} catch (IOException e) {
throw new BackendException("Failed to create namespace '%s' for '%s' store", e, this.namespace, this.store);
}
// Create tables
for (String table : this.tableNames()) {
try {
if (table.equals("g_oe") || table.equals("g_ie")) {
this.sessions.createPreSplitTable(table, HbaseTable.cfs(), this.edgeLogicPartitions);
} else if (table.equals("g_v")) {
this.sessions.createPreSplitTable(table, HbaseTable.cfs(), this.vertexLogicPartitions);
} else {
this.sessions.createTable(table, HbaseTable.cfs());
}
} catch (TableExistsException ignored) {
continue;
} catch (IOException e) {
throw new BackendException("Failed to create table '%s' for '%s' store", e, table, this.store);
}
}
LOG.debug("Store initialized: {}", this.store);
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class HbaseStore method truncate.
@Override
public void truncate() {
this.checkOpened();
// Total time may cost 3 * TRUNCATE_TIMEOUT, due to there are 3 stores
long timeout = this.sessions.config().get(HbaseOptions.TRUNCATE_TIMEOUT);
long start = System.currentTimeMillis();
BiFunction<String, Future<Void>, Void> wait = (table, future) -> {
long elapsed = System.currentTimeMillis() - start;
long remainingTime = timeout - elapsed / 1000L;
try {
return future.get(remainingTime, TimeUnit.SECONDS);
} catch (Exception e) {
throw new BackendException("Error when truncating table '%s' of '%s' store: %s", table, this.store, e.toString());
}
};
// Truncate tables
List<String> tables = this.tableNames();
Map<String, Future<Void>> futures = new HashMap<>(tables.size());
try {
// Disable tables async
for (String table : tables) {
futures.put(table, this.sessions.disableTableAsync(table));
}
for (Map.Entry<String, Future<Void>> entry : futures.entrySet()) {
wait.apply(entry.getKey(), entry.getValue());
}
} catch (Exception e) {
this.enableTables();
throw new BackendException("Failed to disable table for '%s' store", e, this.store);
}
try {
// Truncate tables async
for (String table : tables) {
futures.put(table, this.sessions.truncateTableAsync(table));
}
for (Map.Entry<String, Future<Void>> entry : futures.entrySet()) {
wait.apply(entry.getKey(), entry.getValue());
}
} catch (Exception e) {
this.enableTables();
throw new BackendException("Failed to truncate table for '%s' store", e, this.store);
}
LOG.debug("Store truncated: {}", this.store);
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class HbaseTable method newEntryIterator.
protected BackendEntryIterator newEntryIterator(Query query, RowIterator rows) {
return new BinaryEntryIterator<>(rows, query, (entry, row) -> {
E.checkState(!row.isEmpty(), "Can't parse empty HBase result");
byte[] id = row.getRow();
if (entry == null || !Bytes.prefixWith(id, entry.id().asBytes())) {
HugeType type = query.resultType();
// NOTE: only support BinaryBackendEntry currently
entry = new BinaryBackendEntry(type, id, this.enablePartition);
}
try {
this.parseRowColumns(row, entry, query, this.enablePartition);
} catch (IOException e) {
throw new BackendException("Failed to read HBase columns", e);
}
return entry;
});
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlSessions method createDatabase.
public void createDatabase() {
// Create database with non-database-session
LOG.debug("Create database: {}", this.database());
String sql = this.buildCreateDatabase(this.database());
try (Connection conn = this.openWithoutDB(0)) {
conn.createStatement().execute(sql);
} catch (SQLException e) {
if (!e.getMessage().endsWith("already exists")) {
throw new BackendException("Failed to create database '%s'", e, this.database());
}
// Ignore exception if database already exists
}
}
Aggregations