use of com.arangodb.ArangoConfigure in project YCSB by brianfrankcooper.
the class ArangoDBClient method init.
/**
* Initialize any state for this DB. Called once per DB instance; there is
* one DB instance per client thread.
*
* Actually, one client process will share one DB instance here.(Coincide to
* mongoDB driver)
*/
@Override
public void init() throws DBException {
INIT_COUNT.incrementAndGet();
synchronized (ArangoDBClient.class) {
if (arangoDriver != null) {
return;
}
Properties props = getProperties();
// Set the DB address
String ip = props.getProperty("arangodb.ip", "localhost");
String portStr = props.getProperty("arangodb.port", "8529");
int port = Integer.parseInt(portStr);
// If clear db before run
String dropDBBeforeRunStr = props.getProperty("arangodb.dropDBBeforeRun", "false");
dropDBBeforeRun = Boolean.parseBoolean(dropDBBeforeRunStr);
// Set the sync mode
String waitForSyncStr = props.getProperty("arangodb.waitForSync", "false");
waitForSync = Boolean.parseBoolean(waitForSyncStr);
// Set if transaction for update
String transactionUpdateStr = props.getProperty("arangodb.transactionUpdate", "false");
transactionUpdate = Boolean.parseBoolean(transactionUpdateStr);
// Init ArangoDB connection
try {
ArangoConfigure arangoConfigure = new ArangoConfigure();
arangoConfigure.setArangoHost(new ArangoHost(ip, port));
arangoConfigure.init();
arangoDriver = new ArangoDriver(arangoConfigure);
} catch (Exception e) {
logger.error("Failed to initialize ArangoDB", e);
System.exit(-1);
}
// Init the database
if (dropDBBeforeRun) {
// Try delete first
try {
arangoDriver.deleteDatabase(databaseName);
} catch (ArangoException e) {
if (e.getErrorNumber() != ErrorNums.ERROR_ARANGO_DATABASE_NOT_FOUND) {
logger.error("Failed to delete database: {} with ex: {}", databaseName, e.toString());
System.exit(-1);
} else {
logger.info("Fail to delete DB, already deleted: {}", databaseName);
}
}
}
try {
arangoDriver.createDatabase(databaseName);
logger.info("Database created: " + databaseName);
} catch (ArangoException e) {
if (e.getErrorNumber() != ErrorNums.ERROR_ARANGO_DUPLICATE_NAME) {
logger.error("Failed to create database: {} with ex: {}", databaseName, e.toString());
System.exit(-1);
} else {
logger.info("DB already exists: {}", databaseName);
}
}
// Always set the default db
arangoDriver.setDefaultDatabase(databaseName);
logger.info("ArangoDB client connection created to {}:{}", ip, port);
// Log the configuration
logger.info("Arango Configuration: dropDBBeforeRun: {}; address: {}:{}; databaseName: {};" + " waitForSync: {}; transactionUpdate: {};", dropDBBeforeRun, ip, port, databaseName, waitForSync, transactionUpdate);
}
}
Aggregations