Search in sources :

Example 1 with KVStoreConfig

use of oracle.kv.KVStoreConfig 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);
    }
}
Also used : KVStoreConfig(oracle.kv.KVStoreConfig) DBException(com.yahoo.ycsb.DBException) RequestLimitConfig(oracle.kv.RequestLimitConfig) FaultException(oracle.kv.FaultException) Properties(java.util.Properties)

Aggregations

DBException (com.yahoo.ycsb.DBException)1 Properties (java.util.Properties)1 FaultException (oracle.kv.FaultException)1 KVStoreConfig (oracle.kv.KVStoreConfig)1 RequestLimitConfig (oracle.kv.RequestLimitConfig)1