use of site.ycsb.DBException in project YCSB by brianfrankcooper.
the class JdbcDBClient method init.
@Override
public void init() throws DBException {
if (initialized) {
System.err.println("Client connection already initialized.");
return;
}
props = getProperties();
String urls = props.getProperty(CONNECTION_URL, DEFAULT_PROP);
String user = props.getProperty(CONNECTION_USER, DEFAULT_PROP);
String passwd = props.getProperty(CONNECTION_PASSWD, DEFAULT_PROP);
String driver = props.getProperty(DRIVER_CLASS);
this.jdbcFetchSize = getIntProperty(props, JDBC_FETCH_SIZE);
this.batchSize = getIntProperty(props, DB_BATCH_SIZE);
this.autoCommit = getBoolProperty(props, JDBC_AUTO_COMMIT, true);
this.batchUpdates = getBoolProperty(props, JDBC_BATCH_UPDATES, false);
try {
// TODO: check product name and version rather than driver name
if (driver != null) {
if (driver.contains("sqlserver")) {
sqlserverScans = true;
sqlansiScans = false;
}
if (driver.contains("oracle")) {
sqlserverScans = false;
sqlansiScans = true;
}
if (driver.contains("postgres")) {
sqlserverScans = false;
sqlansiScans = true;
}
Class.forName(driver);
}
int shardCount = 0;
conns = new ArrayList<Connection>(3);
// for a longer explanation see the README.md
// semicolons aren't present in JDBC urls, so we use them to delimit
// multiple JDBC connections to shard across.
final String[] urlArr = urls.split(";");
for (String url : urlArr) {
System.out.println("Adding shard node URL: " + url);
Connection conn = DriverManager.getConnection(url, user, passwd);
// Since there is no explicit commit method in the DB interface, all
// operations should auto commit, except when explicitly told not to
// (this is necessary in cases such as for PostgreSQL when running a
// scan workload with fetchSize)
conn.setAutoCommit(autoCommit);
shardCount++;
conns.add(conn);
}
System.out.println("Using shards: " + shardCount + ", batchSize:" + batchSize + ", fetchSize: " + jdbcFetchSize);
cachedStatements = new ConcurrentHashMap<StatementType, PreparedStatement>();
this.dbFlavor = DBFlavor.fromJdbcUrl(urlArr[0]);
} catch (ClassNotFoundException e) {
System.err.println("Error in initializing the JDBS driver: " + e);
throw new DBException(e);
} catch (SQLException e) {
System.err.println("Error in database operation: " + e);
throw new DBException(e);
} catch (NumberFormatException e) {
System.err.println("Invalid value for fieldcount property. " + e);
throw new DBException(e);
}
initialized = true;
}
use of site.ycsb.DBException in project YCSB by brianfrankcooper.
the class JdbcDBClientTest method setupWithBatch.
public static void setupWithBatch(int batchSize, boolean autoCommit) {
try {
jdbcConnection = DriverManager.getConnection(TEST_DB_URL);
jdbcDBClient = new JdbcDBClient();
Properties p = new Properties();
p.setProperty(JdbcDBClient.CONNECTION_URL, TEST_DB_URL);
p.setProperty(JdbcDBClient.DRIVER_CLASS, TEST_DB_DRIVER);
p.setProperty(JdbcDBClient.CONNECTION_USER, TEST_DB_USER);
p.setProperty(JdbcDBClient.DB_BATCH_SIZE, Integer.toString(batchSize));
p.setProperty(JdbcDBClient.JDBC_BATCH_UPDATES, "true");
p.setProperty(JdbcDBClient.JDBC_AUTO_COMMIT, Boolean.toString(autoCommit));
jdbcDBClient.setProperties(p);
jdbcDBClient.init();
} catch (SQLException e) {
e.printStackTrace();
fail("Could not create local Database");
} catch (DBException e) {
e.printStackTrace();
fail("Could not create JdbcDBClient instance");
}
}
use of site.ycsb.DBException in project YCSB by brianfrankcooper.
the class KuduYCSBClient method cleanup.
@Override
public void cleanup() throws DBException {
try {
this.session.close();
this.client.close();
} catch (Exception e) {
throw new DBException("Couldn't cleanup the session", e);
}
}
use of site.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);
}
}
use of site.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());
}
}
Aggregations