Search in sources :

Example 41 with DBException

use of site.ycsb.DBException 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 {
    synchronized (ArangoDBClient.class) {
        Properties props = getProperties();
        collectionName = props.getProperty("table", "usertable");
        // Set the DB address
        String ip = props.getProperty("arangodb.ip", "localhost");
        String portStr = props.getProperty("arangodb.port", "8529");
        int port = Integer.parseInt(portStr);
        // Set network protocol
        String protocolStr = props.getProperty("arangodb.protocol", "VST");
        Protocol protocol = Protocol.valueOf(protocolStr);
        // 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 {
            arangoDB = new ArangoDB.Builder().host(ip).port(port).useProtocol(protocol).build();
        } catch (Exception e) {
            logger.error("Failed to initialize ArangoDB", e);
            System.exit(-1);
        }
        if (INIT_COUNT.getAndIncrement() == 0) {
            // Init the database
            if (dropDBBeforeRun) {
                // Try delete first
                try {
                    arangoDB.db(databaseName).drop();
                } catch (ArangoDBException e) {
                    logger.info("Fail to delete DB: {}", databaseName);
                }
            }
            try {
                arangoDB.createDatabase(databaseName);
                logger.info("Database created: " + databaseName);
            } catch (ArangoDBException e) {
                logger.error("Failed to create database: {} with ex: {}", databaseName, e.toString());
            }
            try {
                arangoDB.db(databaseName).createCollection(collectionName);
                logger.info("Collection created: " + collectionName);
            } catch (ArangoDBException e) {
                logger.error("Failed to create collection: {} with ex: {}", collectionName, e.toString());
            }
            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);
        }
    }
}
Also used : ArangoDB(com.arangodb.ArangoDB) Properties(java.util.Properties) Protocol(com.arangodb.Protocol) ArangoDBException(com.arangodb.ArangoDBException) IOException(java.io.IOException) DBException(site.ycsb.DBException) ArangoDBException(com.arangodb.ArangoDBException)

Aggregations

DBException (site.ycsb.DBException)41 Properties (java.util.Properties)20 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)4 TimeoutException (com.stumbleupon.async.TimeoutException)3 ColumnInfo (com.toshiba.mwcloud.gs.ColumnInfo)2 AerospikeException (com.aerospike.client.AerospikeException)1 ClientPolicy (com.aerospike.client.policy.ClientPolicy)1 MongoClientConfiguration (com.allanbank.mongodb.MongoClientConfiguration)1 MongoDbUri (com.allanbank.mongodb.MongoDbUri)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 SSECustomerKey (com.amazonaws.services.s3.model.SSECustomerKey)1 ArangoDB (com.arangodb.ArangoDB)1 ArangoDBException (com.arangodb.ArangoDBException)1 Protocol (com.arangodb.Protocol)1 ConsistencyLevel (com.azure.cosmos.ConsistencyLevel)1 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)1 CosmosException (com.azure.cosmos.CosmosException)1 DirectConnectionConfig (com.azure.cosmos.DirectConnectionConfig)1