Search in sources :

Example 16 with DBException

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

the class CouchbaseClient method init.

@Override
public void init() throws DBException {
    Properties props = getProperties();
    String url = props.getProperty(URL_PROPERTY, "http://127.0.0.1:8091/pools");
    String bucket = props.getProperty(BUCKET_PROPERTY, "default");
    String password = props.getProperty(PASSWORD_PROPERTY, "");
    checkFutures = props.getProperty(CHECKF_PROPERTY, "true").equals("true");
    useJson = props.getProperty(JSON_PROPERTY, "true").equals("true");
    persistTo = parsePersistTo(props.getProperty(PERSIST_PROPERTY, "0"));
    replicateTo = parseReplicateTo(props.getProperty(REPLICATE_PROPERTY, "0"));
    designDoc = getProperties().getProperty(DESIGN_DOC_PROPERTY);
    viewName = getProperties().getProperty(VIEW_PROPERTY);
    stale = Stale.valueOf(getProperties().getProperty(STALE_PROPERTY, STALE_PROPERTY_DEFAULT).toUpperCase());
    Double scanproportion = Double.valueOf(props.getProperty(SCAN_PROPERTY, SCAN_PROPERTY_DEFAULT));
    Properties systemProperties = System.getProperties();
    systemProperties.put("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.SLF4JLogger");
    System.setProperties(systemProperties);
    try {
        client = new com.couchbase.client.CouchbaseClient(Arrays.asList(new URI(url)), bucket, password);
    } catch (Exception e) {
        throw new DBException("Could not create CouchbaseClient object.", e);
    }
    if (scanproportion > 0) {
        try {
            view = client.getView(designDoc, viewName);
        } catch (Exception e) {
            throw new DBException(String.format("%s=%s and %s=%s provided, unable to connect to view.", DESIGN_DOC_PROPERTY, designDoc, VIEW_PROPERTY, viewName), e.getCause());
        }
    }
}
Also used : DBException(com.yahoo.ycsb.DBException) Properties(java.util.Properties) URI(java.net.URI) DBException(com.yahoo.ycsb.DBException)

Example 17 with DBException

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

the class AsyncHBaseClient method init.

@Override
public void init() throws DBException {
    if (getProperties().getProperty(CLIENT_SIDE_BUFFERING_PROPERTY, "false").toLowerCase().equals("true")) {
        clientSideBuffering = true;
    }
    if (getProperties().getProperty(DURABILITY_PROPERTY, "true").toLowerCase().equals("false")) {
        durability = false;
    }
    final String columnFamily = getProperties().getProperty(COLUMN_FAMILY_PROPERTY);
    if (columnFamily == null || columnFamily.isEmpty()) {
        System.err.println("Error, must specify a columnfamily for HBase table");
        throw new DBException("No columnfamily specified");
    }
    columnFamilyBytes = columnFamily.getBytes();
    if ((getProperties().getProperty("debug") != null) && (getProperties().getProperty("debug").compareTo("true") == 0)) {
        debug = true;
    }
    joinTimeout = Integer.parseInt(getProperties().getProperty(JOIN_TIMEOUT_PROPERTY, JOIN_TIMEOUT_PROPERTY_DEFAULT));
    final boolean prefetchMeta = getProperties().getProperty(PREFETCH_META_PROPERTY, "false").toLowerCase().equals("true") ? true : false;
    try {
        synchronized (MUTEX) {
            ++threadCount;
            if (client == null) {
                final String configPath = getProperties().getProperty(CONFIG_PROPERTY);
                final Config config;
                if (configPath == null || configPath.isEmpty()) {
                    config = new Config();
                    final Iterator<Entry<Object, Object>> iterator = getProperties().entrySet().iterator();
                    while (iterator.hasNext()) {
                        final Entry<Object, Object> property = iterator.next();
                        config.overrideConfig((String) property.getKey(), (String) property.getValue());
                    }
                } else {
                    config = new Config(configPath);
                }
                client = new HBaseClient(config);
                // Terminate right now if table does not exist, since the client
                // will not propagate this error upstream once the workload
                // starts.
                String table = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT);
                try {
                    client.ensureTableExists(table).join(joinTimeout);
                } catch (InterruptedException e1) {
                    Thread.currentThread().interrupt();
                } catch (Exception e) {
                    throw new DBException(e);
                }
                if (prefetchMeta) {
                    try {
                        if (debug) {
                            System.out.println("Starting meta prefetch for table " + table);
                        }
                        client.prefetchMeta(table).join(joinTimeout);
                        if (debug) {
                            System.out.println("Completed meta prefetch for table " + table);
                        }
                    } catch (InterruptedException e) {
                        System.err.println("Interrupted during prefetch");
                        Thread.currentThread().interrupt();
                    } catch (Exception e) {
                        throw new DBException("Failed prefetch", e);
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new DBException("Failed instantiation of client", e);
    }
}
Also used : DBException(com.yahoo.ycsb.DBException) Entry(java.util.Map.Entry) Config(org.hbase.async.Config) HBaseClient(org.hbase.async.HBaseClient) IOException(java.io.IOException) DBException(com.yahoo.ycsb.DBException) IOException(java.io.IOException)

Example 18 with DBException

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

the class CassandraCQLClient 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 {
    // Keep track of number of calls to init (for later cleanup)
    INIT_COUNT.incrementAndGet();
    // cluster/session instance for all the threads.
    synchronized (INIT_COUNT) {
        // Check if the cluster has already been initialized
        if (cluster != null) {
            return;
        }
        try {
            debug = Boolean.parseBoolean(getProperties().getProperty("debug", "false"));
            trace = Boolean.valueOf(getProperties().getProperty(TRACING_PROPERTY, TRACING_PROPERTY_DEFAULT));
            String host = getProperties().getProperty(HOSTS_PROPERTY);
            if (host == null) {
                throw new DBException(String.format("Required property \"%s\" missing for CassandraCQLClient", HOSTS_PROPERTY));
            }
            String[] hosts = host.split(",");
            String port = getProperties().getProperty(PORT_PROPERTY, PORT_PROPERTY_DEFAULT);
            String username = getProperties().getProperty(USERNAME_PROPERTY);
            String password = getProperties().getProperty(PASSWORD_PROPERTY);
            String keyspace = getProperties().getProperty(KEYSPACE_PROPERTY, KEYSPACE_PROPERTY_DEFAULT);
            readConsistencyLevel = ConsistencyLevel.valueOf(getProperties().getProperty(READ_CONSISTENCY_LEVEL_PROPERTY, READ_CONSISTENCY_LEVEL_PROPERTY_DEFAULT));
            writeConsistencyLevel = ConsistencyLevel.valueOf(getProperties().getProperty(WRITE_CONSISTENCY_LEVEL_PROPERTY, WRITE_CONSISTENCY_LEVEL_PROPERTY_DEFAULT));
            if ((username != null) && !username.isEmpty()) {
                cluster = Cluster.builder().withCredentials(username, password).withPort(Integer.valueOf(port)).addContactPoints(hosts).build();
            } else {
                cluster = Cluster.builder().withPort(Integer.valueOf(port)).addContactPoints(hosts).build();
            }
            String maxConnections = getProperties().getProperty(MAX_CONNECTIONS_PROPERTY);
            if (maxConnections != null) {
                cluster.getConfiguration().getPoolingOptions().setMaxConnectionsPerHost(HostDistance.LOCAL, Integer.valueOf(maxConnections));
            }
            String coreConnections = getProperties().getProperty(CORE_CONNECTIONS_PROPERTY);
            if (coreConnections != null) {
                cluster.getConfiguration().getPoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, Integer.valueOf(coreConnections));
            }
            String connectTimoutMillis = getProperties().getProperty(CONNECT_TIMEOUT_MILLIS_PROPERTY);
            if (connectTimoutMillis != null) {
                cluster.getConfiguration().getSocketOptions().setConnectTimeoutMillis(Integer.valueOf(connectTimoutMillis));
            }
            String readTimoutMillis = getProperties().getProperty(READ_TIMEOUT_MILLIS_PROPERTY);
            if (readTimoutMillis != null) {
                cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.valueOf(readTimoutMillis));
            }
            Metadata metadata = cluster.getMetadata();
            System.err.printf("Connected to cluster: %s\n", metadata.getClusterName());
            for (Host discoveredHost : metadata.getAllHosts()) {
                System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n", discoveredHost.getDatacenter(), discoveredHost.getAddress(), discoveredHost.getRack());
            }
            session = cluster.connect(keyspace);
        } catch (Exception e) {
            throw new DBException(e);
        }
    }
// synchronized
}
Also used : DBException(com.yahoo.ycsb.DBException) Metadata(com.datastax.driver.core.Metadata) Host(com.datastax.driver.core.Host) DBException(com.yahoo.ycsb.DBException)

Example 19 with DBException

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

the class CloudSpannerClient method init.

@Override
public void init() throws DBException {
    synchronized (CLASS_LOCK) {
        if (dbClient != null) {
            return;
        }
        Properties properties = getProperties();
        String host = properties.getProperty(CloudSpannerProperties.HOST);
        String project = properties.getProperty(CloudSpannerProperties.PROJECT);
        String instance = properties.getProperty(CloudSpannerProperties.INSTANCE, "ycsb-instance");
        String database = properties.getProperty(CloudSpannerProperties.DATABASE, "ycsb-database");
        fieldCount = Integer.parseInt(properties.getProperty(CoreWorkload.FIELD_COUNT_PROPERTY, CoreWorkload.FIELD_COUNT_PROPERTY_DEFAULT));
        queriesForReads = properties.getProperty(CloudSpannerProperties.READ_MODE, "query").equals("query");
        batchInserts = Integer.parseInt(properties.getProperty(CloudSpannerProperties.BATCH_INSERTS, "1"));
        constructStandardQueriesAndFields(properties);
        int boundedStalenessSeconds = Integer.parseInt(properties.getProperty(CloudSpannerProperties.BOUNDED_STALENESS, "0"));
        timestampBound = (boundedStalenessSeconds <= 0) ? TimestampBound.strong() : TimestampBound.ofMaxStaleness(boundedStalenessSeconds, TimeUnit.SECONDS);
        try {
            spanner = getSpanner(properties, host, project);
            if (project == null) {
                project = spanner.getOptions().getProjectId();
            }
            dbClient = spanner.getDatabaseClient(DatabaseId.of(project, instance, database));
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "init()", e);
            throw new DBException(e);
        }
        LOGGER.log(Level.INFO, new StringBuilder().append("\nHost: ").append(spanner.getOptions().getHost()).append("\nProject: ").append(project).append("\nInstance: ").append(instance).append("\nDatabase: ").append(database).append("\nUsing queries for reads: ").append(queriesForReads).append("\nBatching inserts: ").append(batchInserts).append("\nBounded staleness seconds: ").append(boundedStalenessSeconds).toString());
    }
}
Also used : DBException(com.yahoo.ycsb.DBException) Properties(java.util.Properties) DBException(com.yahoo.ycsb.DBException)

Example 20 with DBException

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

the class ArangoDB3Client 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 (ArangoDB3Client.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);
        // 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).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 : MapBuilder(com.arangodb.util.MapBuilder) VPackBuilder(com.arangodb.velocypack.VPackBuilder) Properties(java.util.Properties) DBException(com.yahoo.ycsb.DBException) ArangoDBException(com.arangodb.ArangoDBException) IOException(java.io.IOException) ArangoDBException(com.arangodb.ArangoDBException)

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