Search in sources :

Example 11 with DBException

use of com.yahoo.ycsb.DBException in project YCSB by brianfrankcooper.

the class MongoDbClient method init.

/**
   * Initialize any state for this DB. Called once per DB instance; there is one
   * DB instance per client thread.
   */
@Override
public void init() throws DBException {
    INIT_COUNT.incrementAndGet();
    synchronized (INCLUDE) {
        if (mongoClient != null) {
            return;
        }
        Properties props = getProperties();
        // Set insert batchsize, default 1 - to be YCSB-original equivalent
        batchSize = Integer.parseInt(props.getProperty("batchsize", "1"));
        // Set is inserts are done as upserts. Defaults to false.
        useUpsert = Boolean.parseBoolean(props.getProperty("mongodb.upsert", "false"));
        // Just use the standard connection format URL
        // http://docs.mongodb.org/manual/reference/connection-string/
        // to configure the client.
        String url = props.getProperty("mongodb.url", null);
        boolean defaultedUrl = false;
        if (url == null) {
            defaultedUrl = true;
            url = "mongodb://localhost:27017/ycsb?w=1";
        }
        url = OptionsSupport.updateUrl(url, props);
        if (!url.startsWith("mongodb://")) {
            System.err.println("ERROR: Invalid URL: '" + url + "'. Must be of the form " + "'mongodb://<host1>:<port1>,<host2>:<port2>/database?options'. " + "http://docs.mongodb.org/manual/reference/connection-string/");
            System.exit(1);
        }
        try {
            MongoClientURI uri = new MongoClientURI(url);
            String uriDb = uri.getDatabase();
            if (!defaultedUrl && (uriDb != null) && !uriDb.isEmpty() && !"admin".equals(uriDb)) {
                databaseName = uriDb;
            } else {
                // If no database is specified in URI, use "ycsb"
                databaseName = "ycsb";
            }
            readPreference = uri.getOptions().getReadPreference();
            writeConcern = uri.getOptions().getWriteConcern();
            mongoClient = new MongoClient(uri);
            database = mongoClient.getDatabase(databaseName).withReadPreference(readPreference).withWriteConcern(writeConcern);
            System.out.println("mongo client connection created with " + url);
        } catch (Exception e1) {
            System.err.println("Could not initialize MongoDB connection pool for Loader: " + e1.toString());
            e1.printStackTrace();
            return;
        }
    }
}
Also used : MongoClient(com.mongodb.MongoClient) MongoClientURI(com.mongodb.MongoClientURI) Properties(java.util.Properties) DBException(com.yahoo.ycsb.DBException)

Example 12 with DBException

use of com.yahoo.ycsb.DBException in project YCSB by brianfrankcooper.

the class KuduYCSBClient method init.

@Override
public void init() throws DBException {
    String tableName = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT);
    initClient(tableName, getProperties());
    this.session = client.newSession();
    if (getProperties().getProperty(SYNC_OPS_OPT) != null && getProperties().getProperty(SYNC_OPS_OPT).equals("false")) {
        this.session.setFlushMode(KuduSession.FlushMode.AUTO_FLUSH_BACKGROUND);
        this.session.setMutationBufferSpace(100);
    } else {
        this.session.setFlushMode(KuduSession.FlushMode.AUTO_FLUSH_SYNC);
    }
    try {
        this.kuduTable = client.openTable(tableName);
    } catch (Exception e) {
        throw new DBException("Could not open a table because of:", e);
    }
}
Also used : DBException(com.yahoo.ycsb.DBException) DBException(com.yahoo.ycsb.DBException) TimeoutException(com.stumbleupon.async.TimeoutException)

Example 13 with DBException

use of com.yahoo.ycsb.DBException in project YCSB by brianfrankcooper.

the class JdbcDBClient method init.

@Override
public void init() throws DBException {
    if (initialized) {
        System.err.println("Client connection already initialized.");
        return;
    }
    props = getProperties();
    String urls = props.getProperty(CONNECTION_URL, DEFAULT_PROP);
    String user = props.getProperty(CONNECTION_USER, DEFAULT_PROP);
    String passwd = props.getProperty(CONNECTION_PASSWD, DEFAULT_PROP);
    String driver = props.getProperty(DRIVER_CLASS);
    this.jdbcFetchSize = getIntProperty(props, JDBC_FETCH_SIZE);
    this.batchSize = getIntProperty(props, DB_BATCH_SIZE);
    this.autoCommit = getBoolProperty(props, JDBC_AUTO_COMMIT, true);
    this.batchUpdates = getBoolProperty(props, JDBC_BATCH_UPDATES, false);
    try {
        if (driver != null) {
            Class.forName(driver);
        }
        int shardCount = 0;
        conns = new ArrayList<Connection>(3);
        final String[] urlArr = urls.split(",");
        for (String url : urlArr) {
            System.out.println("Adding shard node URL: " + url);
            Connection conn = DriverManager.getConnection(url, user, passwd);
            // Since there is no explicit commit method in the DB interface, all
            // operations should auto commit, except when explicitly told not to
            // (this is necessary in cases such as for PostgreSQL when running a
            // scan workload with fetchSize)
            conn.setAutoCommit(autoCommit);
            shardCount++;
            conns.add(conn);
        }
        System.out.println("Using shards: " + shardCount + ", batchSize:" + batchSize + ", fetchSize: " + jdbcFetchSize);
        cachedStatements = new ConcurrentHashMap<StatementType, PreparedStatement>();
        this.dbFlavor = DBFlavor.fromJdbcUrl(urlArr[0]);
    } catch (ClassNotFoundException e) {
        System.err.println("Error in initializing the JDBS driver: " + e);
        throw new DBException(e);
    } catch (SQLException e) {
        System.err.println("Error in database operation: " + e);
        throw new DBException(e);
    } catch (NumberFormatException e) {
        System.err.println("Invalid value for fieldcount property. " + e);
        throw new DBException(e);
    }
    initialized = true;
}
Also used : DBException(com.yahoo.ycsb.DBException)

Example 14 with DBException

use of com.yahoo.ycsb.DBException in project YCSB by brianfrankcooper.

the class S3Client method init.

/**
  * Initialize any state for the storage.
  * Called once per S3 instance; If the client is not null it is re-used.
  */
@Override
public void init() throws DBException {
    final int count = INIT_COUNT.incrementAndGet();
    synchronized (S3Client.class) {
        Properties propsCL = getProperties();
        int recordcount = Integer.parseInt(propsCL.getProperty("recordcount"));
        int operationcount = Integer.parseInt(propsCL.getProperty("operationcount"));
        int numberOfOperations = 0;
        if (recordcount > 0) {
            if (recordcount > operationcount) {
                numberOfOperations = recordcount;
            } else {
                numberOfOperations = operationcount;
            }
        } else {
            numberOfOperations = operationcount;
        }
        if (count <= numberOfOperations) {
            String accessKeyId = null;
            String secretKey = null;
            String endPoint = null;
            String region = null;
            String maxErrorRetry = null;
            String maxConnections = null;
            String protocol = null;
            BasicAWSCredentials s3Credentials;
            ClientConfiguration clientConfig;
            if (s3Client != null) {
                System.out.println("Reusing the same client");
                return;
            }
            try {
                InputStream propFile = S3Client.class.getClassLoader().getResourceAsStream("s3.properties");
                Properties props = new Properties(System.getProperties());
                props.load(propFile);
                accessKeyId = props.getProperty("s3.accessKeyId");
                if (accessKeyId == null) {
                    accessKeyId = propsCL.getProperty("s3.accessKeyId");
                }
                System.out.println(accessKeyId);
                secretKey = props.getProperty("s3.secretKey");
                if (secretKey == null) {
                    secretKey = propsCL.getProperty("s3.secretKey");
                }
                System.out.println(secretKey);
                endPoint = props.getProperty("s3.endPoint");
                if (endPoint == null) {
                    endPoint = propsCL.getProperty("s3.endPoint", "s3.amazonaws.com");
                }
                System.out.println(endPoint);
                region = props.getProperty("s3.region");
                if (region == null) {
                    region = propsCL.getProperty("s3.region", "us-east-1");
                }
                System.out.println(region);
                maxErrorRetry = props.getProperty("s3.maxErrorRetry");
                if (maxErrorRetry == null) {
                    maxErrorRetry = propsCL.getProperty("s3.maxErrorRetry", "15");
                }
                maxConnections = props.getProperty("s3.maxConnections");
                if (maxConnections == null) {
                    maxConnections = propsCL.getProperty("s3.maxConnections");
                }
                protocol = props.getProperty("s3.protocol");
                if (protocol == null) {
                    protocol = propsCL.getProperty("s3.protocol", "HTTPS");
                }
                sse = props.getProperty("s3.sse");
                if (sse == null) {
                    sse = propsCL.getProperty("s3.sse", "false");
                }
                String ssec = props.getProperty("s3.ssec");
                if (ssec == null) {
                    ssec = propsCL.getProperty("s3.ssec", null);
                } else {
                    ssecKey = new SSECustomerKey(ssec);
                }
            } catch (Exception e) {
                System.err.println("The file properties doesn't exist " + e.toString());
                e.printStackTrace();
            }
            try {
                System.out.println("Inizializing the S3 connection");
                s3Credentials = new BasicAWSCredentials(accessKeyId, secretKey);
                clientConfig = new ClientConfiguration();
                clientConfig.setMaxErrorRetry(Integer.parseInt(maxErrorRetry));
                if (protocol.equals("HTTP")) {
                    clientConfig.setProtocol(Protocol.HTTP);
                } else {
                    clientConfig.setProtocol(Protocol.HTTPS);
                }
                if (maxConnections != null) {
                    clientConfig.setMaxConnections(Integer.parseInt(maxConnections));
                }
                s3Client = new AmazonS3Client(s3Credentials, clientConfig);
                s3Client.setRegion(Region.getRegion(Regions.fromName(region)));
                s3Client.setEndpoint(endPoint);
                System.out.println("Connection successfully initialized");
            } catch (Exception e) {
                System.err.println("Could not connect to S3 storage: " + e.toString());
                e.printStackTrace();
                throw new DBException(e);
            }
        } else {
            System.err.println("The number of threads must be less or equal than the operations");
            throw new DBException(new Error("The number of threads must be less or equal than the operations"));
        }
    }
}
Also used : DBException(com.yahoo.ycsb.DBException) SSECustomerKey(com.amazonaws.services.s3.model.SSECustomerKey) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Properties(java.util.Properties) ClientConfiguration(com.amazonaws.ClientConfiguration) DBException(com.yahoo.ycsb.DBException)

Example 15 with DBException

use of com.yahoo.ycsb.DBException in project YCSB by brianfrankcooper.

the class RadosClient method init.

public void init() throws DBException {
    Properties props = getProperties();
    String configfile = props.getProperty(CONFIG_FILE_PROPERTY);
    if (configfile == null) {
        configfile = CONFIG_FILE_DEFAULT;
    }
    String id = props.getProperty(ID_PROPERTY);
    if (id == null) {
        id = ID_DEFAULT;
    }
    String pool = props.getProperty(POOL_PROPERTY);
    if (pool == null) {
        pool = POOL_DEFAULT;
    }
    // try {
    // } catch (UnsatisfiedLinkError e) {
    //   throw new DBException("RADOS library is not loaded.");
    // }
    rados = new Rados(id);
    try {
        rados.confReadFile(new File(configfile));
        rados.connect();
        ioctx = rados.ioCtxCreate(pool);
    } catch (RadosException e) {
        throw new DBException(e.getMessage() + ": " + e.getReturnValue());
    }
    isInited = true;
}
Also used : DBException(com.yahoo.ycsb.DBException) Rados(com.ceph.rados.Rados) RadosException(com.ceph.rados.exceptions.RadosException) Properties(java.util.Properties) File(java.io.File)

Aggregations

DBException (com.yahoo.ycsb.DBException)32 Properties (java.util.Properties)15 IOException (java.io.IOException)10 TimeoutException (com.stumbleupon.async.TimeoutException)2 Measurements (com.yahoo.ycsb.measurements.Measurements)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 ArangoConfigure (com.arangodb.ArangoConfigure)1 ArangoDBException (com.arangodb.ArangoDBException)1 ArangoDriver (com.arangodb.ArangoDriver)1 ArangoException (com.arangodb.ArangoException)1 ArangoHost (com.arangodb.ArangoHost)1 MapBuilder (com.arangodb.util.MapBuilder)1 VPackBuilder (com.arangodb.velocypack.VPackBuilder)1 Rados (com.ceph.rados.Rados)1