use of com.yahoo.ycsb.DBException in project YCSB by brianfrankcooper.
the class HBaseClient method cleanup.
/**
* Cleanup any state for this DB.
* Called once per DB instance; there is one DB instance per client thread.
*/
public void cleanup() throws DBException {
// Get the measurements instance as this is the only client that should
// count clean up time like an update since autoflush is off.
Measurements measurements = Measurements.getMeasurements();
try {
long st = System.nanoTime();
if (hTable != null) {
hTable.flushCommits();
}
synchronized (THREAD_COUNT) {
int threadCount = THREAD_COUNT.decrementAndGet();
if (threadCount <= 0 && hConn != null) {
hConn.close();
}
}
long en = System.nanoTime();
measurements.measure("UPDATE", (int) ((en - st) / 1000));
} catch (IOException e) {
throw new DBException(e);
}
}
use of com.yahoo.ycsb.DBException in project YCSB by brianfrankcooper.
the class HBaseClient10 method cleanup.
/**
* Cleanup any state for this DB. Called once per DB instance; there is one DB
* instance per client thread.
*/
@Override
public void cleanup() throws DBException {
// Get the measurements instance as this is the only client that should
// count clean up time like an update if client-side buffering is
// enabled.
Measurements measurements = Measurements.getMeasurements();
try {
long st = System.nanoTime();
if (bufferedMutator != null) {
bufferedMutator.close();
}
if (currentTable != null) {
currentTable.close();
}
long en = System.nanoTime();
final String type = clientSideBuffering ? "UPDATE" : "CLEANUP";
measurements.measure(type, (int) ((en - st) / 1000));
threadCount.decrementAndGet();
if (threadCount.get() <= 0) {
// Means we are done so ok to shut down the Connection.
synchronized (CONNECTION_LOCK) {
if (connection != null) {
connection.close();
connection = null;
}
}
}
} catch (IOException e) {
throw new DBException(e);
}
}
use of com.yahoo.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 com.yahoo.ycsb.DBException in project YCSB by brianfrankcooper.
the class AccumuloClient method init.
@Override
public void init() throws DBException {
colFam = new Text(getProperties().getProperty("accumulo.columnFamily"));
inst = new ZooKeeperInstance(getProperties().getProperty("accumulo.instanceName"), getProperties().getProperty("accumulo.zooKeepers"));
try {
String principal = getProperties().getProperty("accumulo.username");
AuthenticationToken token = new PasswordToken(getProperties().getProperty("accumulo.password"));
connector = inst.getConnector(principal, token);
} catch (AccumuloException e) {
throw new DBException(e);
} catch (AccumuloSecurityException e) {
throw new DBException(e);
}
if (!(getProperties().getProperty("accumulo.pcFlag", "none").equals("none"))) {
System.err.println("Sorry, the ZK based producer/consumer implementation has been removed. " + "Please see YCSB issue #416 for work on adding a general solution to coordinated work.");
}
}
use of com.yahoo.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