use of site.ycsb.DBException in project YCSB by brianfrankcooper.
the class GridDBClientTest method setUp.
/**
* Create properties for configuration to get client
* Create data table to test
*/
@Before
public void setUp() throws Exception {
Properties p = new Properties();
p.setProperty("notificationAddress", NOTIFICATION_ADDR);
p.setProperty("notificationPort", NOTIFICATION_PORT);
p.setProperty("clusterName", CLUSTER_NAME);
p.setProperty("userName", USER_NAME);
p.setProperty("user", USER_NAME);
p.setProperty("password", PASS);
p.setProperty("fieldcount", String.valueOf(FIELD_COUNT));
p.setProperty("fieldlength", FIELD_LENGTH);
Measurements.setProperties(p);
final CoreWorkload workload = new CoreWorkload();
workload.init(p);
getDB(p);
// Create data table to test
// List of columns
List<ColumnInfo> columnInfoList = new ArrayList<ColumnInfo>();
ColumnInfo keyInfo = new ColumnInfo("key", GSType.STRING);
columnInfoList.add(keyInfo);
for (int i = 0; i < FIELD_COUNT; i++) {
String columnName = String.format(VALUE_COLUMN_NAME_PREFIX + "%d", i);
ColumnInfo info = new ColumnInfo(columnName, GSType.STRING);
columnInfoList.add(info);
}
containerInfo = new ContainerInfo(null, ContainerType.COLLECTION, columnInfoList, true);
try {
GridStoreFactory.getInstance().setProperties(p);
store = GridStoreFactory.getInstance().getGridStore(p);
store.putContainer(TEST_TABLE, containerInfo, false);
} catch (GSException e) {
e.printStackTrace();
throw new DBException();
}
}
use of site.ycsb.DBException in project YCSB by brianfrankcooper.
the class NoSqlDbClient method getPropertyInt.
private int getPropertyInt(Properties properties, String key, int defaultValue) throws DBException {
String p = properties.getProperty(key);
int i = defaultValue;
if (p != null) {
try {
i = Integer.parseInt(p);
} catch (NumberFormatException e) {
throw new DBException("Illegal number format in " + key + " property");
}
}
return i;
}
use of site.ycsb.DBException in project YCSB by brianfrankcooper.
the class KuduYCSBClient method setupTable.
private void setupTable() throws DBException {
Properties prop = getProperties();
synchronized (KuduYCSBClient.class) {
if (tableSetup) {
return;
}
int numTablets = getIntFromProp(prop, PRE_SPLIT_NUM_TABLETS_OPT, 4);
if (numTablets > MAX_TABLETS) {
throw new DBException("Specified number of tablets (" + numTablets + ") must be equal " + "or below " + MAX_TABLETS);
}
int numReplicas = getIntFromProp(prop, TABLE_NUM_REPLICAS, DEFAULT_NUM_REPLICAS);
long recordCount = Long.parseLong(prop.getProperty(RECORD_COUNT_PROPERTY, DEFAULT_RECORD_COUNT));
if (recordCount == 0) {
recordCount = Integer.MAX_VALUE;
}
int blockSize = getIntFromProp(prop, BLOCK_SIZE_OPT, BLOCK_SIZE_DEFAULT);
int fieldCount = getIntFromProp(prop, CoreWorkload.FIELD_COUNT_PROPERTY, Integer.parseInt(CoreWorkload.FIELD_COUNT_PROPERTY_DEFAULT));
final String fieldprefix = prop.getProperty(CoreWorkload.FIELD_NAME_PREFIX, CoreWorkload.FIELD_NAME_PREFIX_DEFAULT);
List<ColumnSchema> columns = new ArrayList<ColumnSchema>(fieldCount + 1);
ColumnSchema keyColumn = new ColumnSchema.ColumnSchemaBuilder(KEY, STRING).key(true).desiredBlockSize(blockSize).build();
columns.add(keyColumn);
COLUMN_NAMES.add(KEY);
for (int i = 0; i < fieldCount; i++) {
String name = fieldprefix + i;
COLUMN_NAMES.add(name);
columns.add(new ColumnSchema.ColumnSchemaBuilder(name, STRING).desiredBlockSize(blockSize).build());
}
schema = new Schema(columns);
CreateTableOptions builder = new CreateTableOptions();
if (partitionSchema.equals("hashPartition")) {
builder.setRangePartitionColumns(new ArrayList<String>());
List<String> hashPartitionColumns = new ArrayList<>();
hashPartitionColumns.add(KEY);
builder.addHashPartitions(hashPartitionColumns, numTablets);
} else if (partitionSchema.equals("rangePartition")) {
if (!orderedinserts) {
// We need to use ordered keys to determine how to split range partitions.
throw new DBException("Must specify `insertorder=ordered` if using rangePartition schema.");
}
String maxKeyValue = String.valueOf(recordCount);
if (zeropadding < maxKeyValue.length()) {
throw new DBException(String.format("Invalid zeropadding value: %d, zeropadding needs to be larger " + "or equal to number of digits in the record number: %d.", zeropadding, maxKeyValue.length()));
}
List<String> rangePartitionColumns = new ArrayList<>();
rangePartitionColumns.add(KEY);
builder.setRangePartitionColumns(rangePartitionColumns);
// Add rangePartitions
long lowerNum = 0;
long upperNum = 0;
int remainder = (int) recordCount % numTablets;
for (int i = 0; i < numTablets; i++) {
lowerNum = upperNum;
upperNum = lowerNum + recordCount / numTablets;
if (i < remainder) {
++upperNum;
}
PartialRow lower = schema.newPartialRow();
lower.addString(KEY, CoreWorkload.buildKeyName(lowerNum, zeropadding, orderedinserts));
PartialRow upper = schema.newPartialRow();
upper.addString(KEY, CoreWorkload.buildKeyName(upperNum, zeropadding, orderedinserts));
builder.addRangePartition(lower, upper);
}
} else {
throw new DBException("Invalid partition_schema specified: " + partitionSchema + ", must specify `partition_schema=hashPartition` or `partition_schema=rangePartition`");
}
builder.setNumReplicas(numReplicas);
try {
client.createTable(tableName, schema, builder);
} catch (Exception e) {
if (!e.getMessage().contains("already exists")) {
throw new DBException("Couldn't create the table", e);
}
}
tableSetup = true;
}
}
use of site.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://") && !url.startsWith("mongodb+srv://")) {
System.err.println("ERROR: Invalid URL: '" + url + "'. Must be of the form " + "'mongodb://<host1>:<port1>,<host2>:<port2>/database?options' " + "or 'mongodb+srv://<host>/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;
}
}
}
use of site.ycsb.DBException in project YCSB by brianfrankcooper.
the class AsyncMongoDbClient method init.
/**
* Initialize any state for this DB. Called once per DB instance; there is one
* DB instance per client thread.
*/
@Override
public final void init() throws DBException {
final int count = INIT_COUNT.incrementAndGet();
synchronized (AsyncMongoDbClient.class) {
final Properties props = getProperties();
if (mongoClient != null) {
database = mongoClient.getDatabase(databaseName);
// the connections occupied.
if (count > mongoClient.getConfig().getMaxConnectionCount()) {
mongoClient.getConfig().setLockType(LockType.MUTEX);
}
return;
}
// Set insert batchsize, default 1 - to be YCSB-original equivalent
batchSize = Integer.parseInt(props.getProperty("mongodb.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", "mongodb://localhost:27017/ycsb?w=1");
if (!url.startsWith("mongodb://")) {
System.err.println("ERROR: Invalid URL: '" + url + "'. Must be of the form " + "'mongodb://<host1>:<port1>,<host2>:<port2>/database?" + "options'. See " + "http://docs.mongodb.org/manual/reference/connection-string/.");
System.exit(1);
}
MongoDbUri uri = new MongoDbUri(url);
try {
databaseName = uri.getDatabase();
if ((databaseName == null) || databaseName.isEmpty()) {
// Default database is "ycsb" if database is not
// specified in URL
databaseName = "ycsb";
}
mongoClient = MongoFactory.createClient(uri);
MongoClientConfiguration config = mongoClient.getConfig();
if (!url.toLowerCase().contains("locktype=")) {
// assumed...
config.setLockType(LockType.LOW_LATENCY_SPIN);
}
readPreference = config.getDefaultReadPreference();
writeConcern = config.getDefaultDurability();
database = mongoClient.getDatabase(databaseName);
System.out.println("mongo connection created with " + url);
} catch (final Exception e1) {
System.err.println("Could not initialize MongoDB connection pool for Loader: " + e1.toString());
e1.printStackTrace();
return;
}
}
}
Aggregations