Search in sources :

Example 26 with DBException

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

the class IgniteAbstractClient 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"));
            IgniteConfiguration igcfg = new IgniteConfiguration();
            igcfg.setIgniteInstanceName(CLIENT_NODE_NAME);
            String host = getProperties().getProperty(HOSTS_PROPERTY);
            if (host == null) {
                throw new DBException(String.format("Required property \"%s\" missing for Ignite Cluster", HOSTS_PROPERTY));
            }
            String ports = getProperties().getProperty(PORTS_PROPERTY, PORTS_DEFAULTS);
            if (ports == null) {
                throw new DBException(String.format("Required property \"%s\" missing for Ignite Cluster", PORTS_PROPERTY));
            }
            System.setProperty("IGNITE_QUIET", "false");
            TcpDiscoverySpi disco = new TcpDiscoverySpi();
            Collection<String> addrs = new LinkedHashSet<>();
            addrs.add(host + ":" + ports);
            ((TcpDiscoveryVmIpFinder) ipFinder).setAddresses(addrs);
            disco.setIpFinder(ipFinder);
            igcfg.setDiscoverySpi(disco);
            igcfg.setNetworkTimeout(2000);
            igcfg.setClientMode(true);
            Log4J2Logger logger = new Log4J2Logger(this.getClass().getClassLoader().getResource("log4j2.xml"));
            igcfg.setGridLogger(logger);
            log.info("Start Ignite client node.");
            cluster = Ignition.start(igcfg);
            log.info("Activate Ignite cluster.");
            cluster.active(true);
            cache = cluster.cache(DEFAULT_CACHE_NAME).withKeepBinary();
            if (cache == null) {
                throw new DBException(new IgniteCheckedException("Failed to find cache " + DEFAULT_CACHE_NAME));
            }
        } catch (Exception e) {
            throw new DBException(e);
        }
    }
// synchronized
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DBException(site.ycsb.DBException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Log4J2Logger(org.apache.ignite.logger.log4j2.Log4J2Logger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DBException(site.ycsb.DBException) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 27 with DBException

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

the class ElasticsearchRestClient 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 {
    final Properties props = getProperties();
    this.indexKey = props.getProperty("es.index.key", DEFAULT_INDEX_KEY);
    final int numberOfShards = parseIntegerProperty(props, "es.number_of_shards", NUMBER_OF_SHARDS);
    final int numberOfReplicas = parseIntegerProperty(props, "es.number_of_replicas", NUMBER_OF_REPLICAS);
    final Boolean newIndex = Boolean.parseBoolean(props.getProperty("es.new_index", "false"));
    final String[] nodeList = props.getProperty("es.hosts.list", DEFAULT_REMOTE_HOST).split(",");
    final List<HttpHost> esHttpHosts = new ArrayList<>(nodeList.length);
    for (String h : nodeList) {
        String[] nodes = h.split(":");
        esHttpHosts.add(new HttpHost(nodes[0], Integer.valueOf(nodes[1]), "http"));
    }
    restClient = RestClient.builder(esHttpHosts.toArray(new HttpHost[esHttpHosts.size()])).build();
    final Response existsResponse = performRequest(restClient, "HEAD", "/" + indexKey);
    final boolean exists = existsResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
    if (exists && newIndex) {
        final Response deleteResponse = performRequest(restClient, "DELETE", "/" + indexKey);
        final int statusCode = deleteResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            throw new DBException("delete [" + indexKey + "] failed with status [" + statusCode + "]");
        }
    }
    if (!exists || newIndex) {
        try (XContentBuilder builder = jsonBuilder()) {
            builder.startObject();
            builder.startObject("settings");
            builder.field("index.number_of_shards", numberOfShards);
            builder.field("index.number_of_replicas", numberOfReplicas);
            builder.endObject();
            builder.endObject();
            final Map<String, String> params = emptyMap();
            final StringEntity entity = new StringEntity(builder.string());
            final Response createResponse = performRequest(restClient, "PUT", "/" + indexKey, params, entity);
            final int statusCode = createResponse.getStatusLine().getStatusCode();
            if (statusCode != HttpStatus.SC_OK) {
                throw new DBException("create [" + indexKey + "] failed with status [" + statusCode + "]");
            }
        } catch (final IOException e) {
            throw new DBException(e);
        }
    }
    final Map<String, String> params = Collections.singletonMap("wait_for_status", "green");
    final Response healthResponse = performRequest(restClient, "GET", "/_cluster/health/" + indexKey, params);
    final int healthStatusCode = healthResponse.getStatusLine().getStatusCode();
    if (healthStatusCode != HttpStatus.SC_OK) {
        throw new DBException("cluster health [" + indexKey + "] failed with status [" + healthStatusCode + "]");
    }
}
Also used : DBException(site.ycsb.DBException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) Response(org.elasticsearch.client.Response) NStringEntity(org.apache.http.nio.entity.NStringEntity) StringEntity(org.apache.http.entity.StringEntity) HttpHost(org.apache.http.HttpHost) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 28 with DBException

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

the class HBaseClient1 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 {
    if ("true".equals(getProperties().getProperty("clientbuffering", "false"))) {
        this.clientSideBuffering = true;
    }
    if (getProperties().containsKey("writebuffersize")) {
        writeBufferSize = Long.parseLong(getProperties().getProperty("writebuffersize"));
    }
    if (getProperties().getProperty("durability") != null) {
        this.durability = Durability.valueOf(getProperties().getProperty("durability"));
    }
    if ("kerberos".equalsIgnoreCase(config.get("hbase.security.authentication"))) {
        config.set("hadoop.security.authentication", "Kerberos");
        UserGroupInformation.setConfiguration(config);
    }
    if ((getProperties().getProperty("principal") != null) && (getProperties().getProperty("keytab") != null)) {
        try {
            UserGroupInformation.loginUserFromKeytab(getProperties().getProperty("principal"), getProperties().getProperty("keytab"));
        } catch (IOException e) {
            System.err.println("Keytab file is not readable or not found");
            throw new DBException(e);
        }
    }
    String table = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT);
    try {
        THREAD_COUNT.getAndIncrement();
        synchronized (THREAD_COUNT) {
            if (connection == null) {
                // Initialize if not set up already.
                connection = ConnectionFactory.createConnection(config);
                // Terminate right now if table does not exist, since the client
                // will not propagate this error upstream once the workload
                // starts.
                final TableName tName = TableName.valueOf(table);
                try (Admin admin = connection.getAdmin()) {
                    if (!admin.tableExists(tName)) {
                        throw new DBException("Table " + tName + " does not exists");
                    }
                }
            }
        }
    } catch (java.io.IOException e) {
        throw new DBException(e);
    }
    if ((getProperties().getProperty("debug") != null) && (getProperties().getProperty("debug").compareTo("true") == 0)) {
        debug = true;
    }
    if ("false".equals(getProperties().getProperty("hbase.usepagefilter", "true"))) {
        usePageFilter = false;
    }
    columnFamily = getProperties().getProperty("columnfamily");
    if (columnFamily == null) {
        System.err.println("Error, must specify a columnfamily for HBase table");
        throw new DBException("No columnfamily specified");
    }
    columnFamilyBytes = Bytes.toBytes(columnFamily);
}
Also used : DBException(site.ycsb.DBException) TableName(org.apache.hadoop.hbase.TableName) IOException(java.io.IOException) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin)

Example 29 with DBException

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

the class HBaseClient1 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));
        int threadCount = THREAD_COUNT.decrementAndGet();
        if (threadCount <= 0) {
            // Means we are done so ok to shut down the Connection.
            synchronized (THREAD_COUNT) {
                if (connection != null) {
                    connection.close();
                    connection = null;
                }
            }
        }
    } catch (IOException e) {
        throw new DBException(e);
    }
}
Also used : DBException(site.ycsb.DBException) Measurements(site.ycsb.measurements.Measurements) IOException(java.io.IOException)

Example 30 with DBException

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

the class ZKClient method init.

public void init() throws DBException {
    Properties props = getProperties();
    String connectString = props.getProperty(CONNECT_STRING);
    if (connectString == null || connectString.length() == 0) {
        connectString = DEFAULT_CONNECT_STRING;
    }
    if (Boolean.parseBoolean(props.getProperty(WATCH_FLAG))) {
        watcher = new SimpleWatcher();
    } else {
        watcher = null;
    }
    long sessionTimeout;
    String sessionTimeoutString = props.getProperty(SESSION_TIMEOUT_PROPERTY);
    if (sessionTimeoutString != null) {
        sessionTimeout = Integer.parseInt(sessionTimeoutString);
    } else {
        sessionTimeout = DEFAULT_SESSION_TIMEOUT;
    }
    try {
        zk = new ZooKeeper(connectString, (int) sessionTimeout, new SimpleWatcher());
    } catch (IOException e) {
        throw new DBException("Creating connection failed.");
    }
}
Also used : DBException(site.ycsb.DBException) ZooKeeper(org.apache.zookeeper.ZooKeeper) IOException(java.io.IOException) 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