Search in sources :

Example 1 with FaultException

use of oracle.kv.FaultException in project YCSB by brianfrankcooper.

the class NoSqlDbClient method update.

@Override
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
    for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
        Key kvKey = createKey(table, key, entry.getKey());
        Value kvValue = Value.createValue(entry.getValue().toArray());
        try {
            store.put(kvKey, kvValue);
        } catch (FaultException e) {
            System.err.println(e);
            return Status.ERROR;
        }
    }
    return Status.OK;
}
Also used : FaultException(oracle.kv.FaultException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) Value(oracle.kv.Value) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Key(oracle.kv.Key)

Example 2 with FaultException

use of oracle.kv.FaultException 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)

Example 3 with FaultException

use of oracle.kv.FaultException in project YCSB by brianfrankcooper.

the class NoSqlDbClient method read.

@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    Key kvKey = createKey(table, key);
    SortedMap<Key, ValueVersion> kvResult;
    try {
        kvResult = store.multiGet(kvKey, null, null);
    } catch (FaultException e) {
        System.err.println(e);
        return Status.ERROR;
    }
    for (Map.Entry<Key, ValueVersion> entry : kvResult.entrySet()) {
        /* If fields is null, read all fields */
        String field = getFieldFromKey(entry.getKey());
        if (fields != null && !fields.contains(field)) {
            continue;
        }
        result.put(field, new ByteArrayByteIterator(entry.getValue().getValue().getValue()));
    }
    return Status.OK;
}
Also used : FaultException(oracle.kv.FaultException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ValueVersion(oracle.kv.ValueVersion) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Key(oracle.kv.Key)

Aggregations

FaultException (oracle.kv.FaultException)3 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 Key (oracle.kv.Key)2 ByteIterator (com.yahoo.ycsb.ByteIterator)1 DBException (com.yahoo.ycsb.DBException)1 Properties (java.util.Properties)1 KVStoreConfig (oracle.kv.KVStoreConfig)1 RequestLimitConfig (oracle.kv.RequestLimitConfig)1 Value (oracle.kv.Value)1 ValueVersion (oracle.kv.ValueVersion)1