Search in sources :

Example 31 with DBException

use of site.ycsb.DBException in project YCSB by brianfrankcooper.

the class AzureCosmosClient method initAzureCosmosClient.

private void initAzureCosmosClient() throws DBException {
    // Connection properties
    String primaryKey = this.getStringProperty("azurecosmos.primaryKey", null);
    if (primaryKey == null || primaryKey.isEmpty()) {
        throw new DBException("Missing primary key required to connect to the database.");
    }
    String uri = this.getStringProperty("azurecosmos.uri", null);
    if (primaryKey == null || primaryKey.isEmpty()) {
        throw new DBException("Missing uri required to connect to the database.");
    }
    AzureCosmosClient.userAgent = this.getStringProperty("azurecosmos.userAgent", DEFAULT_USER_AGENT);
    AzureCosmosClient.useUpsert = this.getBooleanProperty("azurecosmos.useUpsert", DEFAULT_USE_UPSERT);
    AzureCosmosClient.databaseName = this.getStringProperty("azurecosmos.databaseName", DEFAULT_DATABASE_NAME);
    AzureCosmosClient.maxDegreeOfParallelism = this.getIntProperty("azurecosmos.maxDegreeOfParallelism", DEFAULT_MAX_DEGREE_OF_PARALLELISM);
    AzureCosmosClient.maxBufferedItemCount = this.getIntProperty("azurecosmos.maxBufferedItemCount", DEFAULT_MAX_BUFFERED_ITEM_COUNT);
    AzureCosmosClient.preferredPageSize = this.getIntProperty("azurecosmos.preferredPageSize", DEFAULT_PREFERRED_PAGE_SIZE);
    AzureCosmosClient.includeExceptionStackInLog = this.getBooleanProperty("azurecosmos.includeExceptionStackInLog", DEFAULT_INCLUDE_EXCEPTION_STACK_IN_LOG);
    ConsistencyLevel consistencyLevel = ConsistencyLevel.valueOf(this.getStringProperty("azurecosmos.consistencyLevel", DEFAULT_CONSISTENCY_LEVEL.toString().toUpperCase()));
    boolean useGateway = this.getBooleanProperty("azurecosmos.useGateway", DEFAULT_USE_GATEWAY);
    ThrottlingRetryOptions retryOptions = new ThrottlingRetryOptions();
    int maxRetryAttemptsOnThrottledRequests = this.getIntProperty("azurecosmos.maxRetryAttemptsOnThrottledRequests", -1);
    if (maxRetryAttemptsOnThrottledRequests != -1) {
        retryOptions.setMaxRetryAttemptsOnThrottledRequests(maxRetryAttemptsOnThrottledRequests);
    }
    // Direct connection config options.
    DirectConnectionConfig directConnectionConfig = new DirectConnectionConfig();
    int directMaxConnectionsPerEndpoint = this.getIntProperty("azurecosmos.directMaxConnectionsPerEndpoint", -1);
    if (directMaxConnectionsPerEndpoint != -1) {
        directConnectionConfig.setMaxConnectionsPerEndpoint(directMaxConnectionsPerEndpoint);
    }
    int directIdleConnectionTimeoutInSeconds = this.getIntProperty("azurecosmos.directIdleConnectionTimeoutInSeconds", -1);
    if (directIdleConnectionTimeoutInSeconds != -1) {
        directConnectionConfig.setIdleConnectionTimeout(Duration.ofSeconds(directIdleConnectionTimeoutInSeconds));
    }
    // Gateway connection config options.
    GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
    int gatewayMaxConnectionPoolSize = this.getIntProperty("azurecosmos.gatewayMaxConnectionPoolSize", -1);
    if (gatewayMaxConnectionPoolSize != -1) {
        gatewayConnectionConfig.setMaxConnectionPoolSize(gatewayMaxConnectionPoolSize);
    }
    int gatewayIdleConnectionTimeoutInSeconds = this.getIntProperty("azurecosmos.gatewayIdleConnectionTimeoutInSeconds", -1);
    if (gatewayIdleConnectionTimeoutInSeconds != -1) {
        gatewayConnectionConfig.setIdleConnectionTimeout(Duration.ofSeconds(gatewayIdleConnectionTimeoutInSeconds));
    }
    try {
        LOGGER.info("Creating Cosmos DB client {}, useGateway={}, consistencyLevel={}," + " maxRetryAttemptsOnThrottledRequests={}, maxRetryWaitTimeInSeconds={}" + " useUpsert={}, maxDegreeOfParallelism={}, maxBufferedItemCount={}, preferredPageSize={}", uri, useGateway, consistencyLevel.toString(), retryOptions.getMaxRetryAttemptsOnThrottledRequests(), retryOptions.getMaxRetryWaitTime().toMillis() / 1000, AzureCosmosClient.useUpsert, AzureCosmosClient.maxDegreeOfParallelism, AzureCosmosClient.maxBufferedItemCount, AzureCosmosClient.preferredPageSize);
        CosmosClientBuilder builder = new CosmosClientBuilder().endpoint(uri).key(primaryKey).throttlingRetryOptions(retryOptions).consistencyLevel(consistencyLevel).userAgentSuffix(userAgent);
        if (useGateway) {
            builder = builder.gatewayMode(gatewayConnectionConfig);
        } else {
            builder = builder.directMode(directConnectionConfig);
        }
        AzureCosmosClient.client = builder.buildClient();
        LOGGER.info("Azure Cosmos DB connection created to {}", uri);
    } catch (IllegalArgumentException e) {
        if (!AzureCosmosClient.includeExceptionStackInLog) {
            e = null;
        }
        throw new DBException("Illegal argument passed in. Check the format of your parameters.", e);
    }
    AzureCosmosClient.containerCache = new ConcurrentHashMap<>();
    // Verify the database exists
    try {
        AzureCosmosClient.database = AzureCosmosClient.client.getDatabase(databaseName);
        AzureCosmosClient.database.read();
    } catch (CosmosException e) {
        if (!AzureCosmosClient.includeExceptionStackInLog) {
            e = null;
        }
        throw new DBException("Invalid database name (" + AzureCosmosClient.databaseName + ") or failed to read database.", e);
    }
}
Also used : ConsistencyLevel(com.azure.cosmos.ConsistencyLevel) DBException(site.ycsb.DBException) CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) DirectConnectionConfig(com.azure.cosmos.DirectConnectionConfig) ThrottlingRetryOptions(com.azure.cosmos.ThrottlingRetryOptions) CosmosException(com.azure.cosmos.CosmosException) GatewayConnectionConfig(com.azure.cosmos.GatewayConnectionConfig)

Example 32 with DBException

use of site.ycsb.DBException in project YCSB by brianfrankcooper.

the class AzureClient method init.

@Override
public void init() throws DBException {
    Properties props = getProperties();
    String protocol = props.getProperty(PROTOCOL, PROTOCOL_DEFAULT);
    if (protocol != "https" && protocol != "http") {
        throw new DBException("Protocol must be 'http' or 'https'!\n");
    }
    String table = props.getProperty(TABLE, TABLE_DEFAULT);
    partitionKey = props.getProperty(PARTITIONKEY, PARTITIONKEY_DEFAULT);
    batchSize = Integer.parseInt(props.getProperty(BATCHSIZE, BATCHSIZE_DEFAULT));
    if (batchSize < 1 || batchSize > BATCHSIZE_UPPERBOUND) {
        throw new DBException(String.format("Batchsize must be between 1 and %d!\n", BATCHSIZE_UPPERBOUND));
    }
    String account = props.getProperty(ACCOUNT);
    String key = props.getProperty(KEY);
    String tableEndPoint = props.getProperty(TABLE_ENDPOINT);
    String storageConnectionString = getStorageConnectionString(protocol, account, key, tableEndPoint);
    try {
        storageAccount = CloudStorageAccount.parse(storageConnectionString);
    } catch (Exception e) {
        throw new DBException("Could not connect to the account.\n", e);
    }
    tableClient = storageAccount.createCloudTableClient();
    try {
        cloudTable = tableClient.getTableReference(table);
        cloudTable.createIfNotExists();
    } catch (Exception e) {
        throw new DBException("Could not connect to the table.\n", e);
    }
}
Also used : DBException(site.ycsb.DBException) Properties(java.util.Properties) DBException(site.ycsb.DBException)

Example 33 with DBException

use of site.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));
            Boolean useSSL = Boolean.parseBoolean(getProperties().getProperty(USE_SSL_CONNECTION, DEFAULT_USE_SSL_CONNECTION));
            if ((username != null) && !username.isEmpty()) {
                Cluster.Builder clusterBuilder = Cluster.builder().withCredentials(username, password).withPort(Integer.valueOf(port)).addContactPoints(hosts);
                if (useSSL) {
                    clusterBuilder = clusterBuilder.withSSL();
                }
                cluster = clusterBuilder.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();
            logger.info("Connected to cluster: {}\n", metadata.getClusterName());
            for (Host discoveredHost : metadata.getAllHosts()) {
                logger.info("Datacenter: {}; Host: {}; Rack: {}\n", discoveredHost.getDatacenter(), discoveredHost.getAddress(), discoveredHost.getRack());
            }
            session = cluster.connect(keyspace);
        } catch (Exception e) {
            throw new DBException(e);
        }
    }
// synchronized
}
Also used : DBException(site.ycsb.DBException) Metadata(com.datastax.driver.core.Metadata) Cluster(com.datastax.driver.core.Cluster) Host(com.datastax.driver.core.Host) DBException(site.ycsb.DBException)

Example 34 with DBException

use of site.ycsb.DBException in project YCSB by brianfrankcooper.

the class MemcachedClient method init.

@Override
public void init() throws DBException {
    try {
        client = createMemcachedClient();
        checkOperationStatus = Boolean.parseBoolean(getProperties().getProperty(CHECK_OPERATION_STATUS_PROPERTY, CHECK_OPERATION_STATUS_DEFAULT));
        objectExpirationTime = Integer.parseInt(getProperties().getProperty(OBJECT_EXPIRATION_TIME_PROPERTY, DEFAULT_OBJECT_EXPIRATION_TIME));
        shutdownTimeoutMillis = Integer.parseInt(getProperties().getProperty(SHUTDOWN_TIMEOUT_MILLIS_PROPERTY, DEFAULT_SHUTDOWN_TIMEOUT_MILLIS));
    } catch (Exception e) {
        throw new DBException(e);
    }
}
Also used : DBException(site.ycsb.DBException) IOException(java.io.IOException) DBException(site.ycsb.DBException)

Example 35 with DBException

use of site.ycsb.DBException in project YCSB by brianfrankcooper.

the class NoSqlDbClient method init.

@Override
public void init() throws DBException {
    Properties properties = getProperties();
    /* Mandatory properties */
    String storeName = properties.getProperty("storeName", "kvstore");
    String[] helperHosts = properties.getProperty("helperHost", "localhost:5000").split(",");
    KVStoreConfig config = new KVStoreConfig(storeName, helperHosts);
    /* Optional properties */
    String p;
    p = properties.getProperty("consistency");
    if (p != null) {
        if (p.equalsIgnoreCase("ABSOLUTE")) {
            config.setConsistency(Consistency.ABSOLUTE);
        } else if (p.equalsIgnoreCase("NONE_REQUIRED")) {
            config.setConsistency(Consistency.NONE_REQUIRED);
        } else {
            throw new DBException("Illegal value in consistency property");
        }
    }
    p = properties.getProperty("durability");
    if (p != null) {
        if (p.equalsIgnoreCase("COMMIT_NO_SYNC")) {
            config.setDurability(Durability.COMMIT_NO_SYNC);
        } else if (p.equalsIgnoreCase("COMMIT_SYNC")) {
            config.setDurability(Durability.COMMIT_SYNC);
        } else if (p.equalsIgnoreCase("COMMIT_WRITE_NO_SYNC")) {
            config.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
        } else {
            throw new DBException("Illegal value in durability property");
        }
    }
    int maxActiveRequests = getPropertyInt(properties, "requestLimit.maxActiveRequests", RequestLimitConfig.DEFAULT_MAX_ACTIVE_REQUESTS);
    int requestThresholdPercent = getPropertyInt(properties, "requestLimit.requestThresholdPercent", RequestLimitConfig.DEFAULT_REQUEST_THRESHOLD_PERCENT);
    int nodeLimitPercent = getPropertyInt(properties, "requestLimit.nodeLimitPercent", RequestLimitConfig.DEFAULT_NODE_LIMIT_PERCENT);
    RequestLimitConfig requestLimitConfig;
    /*
     * It is said that the constructor could throw NodeRequestLimitException in
     * Javadoc, the exception is not provided
     */
    // try {
    requestLimitConfig = new RequestLimitConfig(maxActiveRequests, requestThresholdPercent, nodeLimitPercent);
    // } catch (NodeRequestLimitException e) {
    // throw new DBException(e);
    // }
    config.setRequestLimit(requestLimitConfig);
    p = properties.getProperty("requestTimeout");
    if (p != null) {
        long timeout = 1;
        try {
            timeout = Long.parseLong(p);
        } catch (NumberFormatException e) {
            throw new DBException("Illegal number format in requestTimeout property");
        }
        try {
            // TODO Support other TimeUnit
            config.setRequestTimeout(timeout, TimeUnit.SECONDS);
        } catch (IllegalArgumentException e) {
            throw new DBException(e);
        }
    }
    try {
        store = KVStoreFactory.getStore(config);
    } catch (FaultException e) {
        throw new DBException(e);
    }
}
Also used : KVStoreConfig(oracle.kv.KVStoreConfig) DBException(site.ycsb.DBException) RequestLimitConfig(oracle.kv.RequestLimitConfig) FaultException(oracle.kv.FaultException) Properties(java.util.Properties)

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