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);
}
}
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);
}
}
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
}
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);
}
}
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);
}
}
Aggregations