Search in sources :

Example 1 with KeyValueIterator

use of alluxio.client.keyvalue.KeyValueIterator in project alluxio by Alluxio.

the class KeyValueStoreOperations method getKeyValuePairs.

private boolean getKeyValuePairs(KeyValueStoreReader reader) throws Exception {
    LOG.info("Getting key-value pairs...");
    // API: KeyValueStoreReader#size
    if (reader.size() != mNumKeyValuePairs) {
        LOG.error("The key-value store has the wrong numbers of key-value pairs");
        return false;
    }
    // API: KeyValueStoreReader#get
    for (Map.Entry<ByteBuffer, ByteBuffer> pair : mKeyValuePairs.entrySet()) {
        ByteBuffer expectedValue = pair.getValue();
        ByteBuffer gotValue = reader.get(pair.getKey());
        if (!expectedValue.equals(gotValue)) {
            LOG.error("The value returned from the key-value store iterator is unexpected");
            return false;
        }
    }
    // API: KeyValueStoreReader#iterator
    KeyValueIterator iterator = reader.iterator();
    while (iterator.hasNext()) {
        KeyValuePair kv = iterator.next();
        ByteBuffer expectedValue = mKeyValuePairs.get(kv.getKey());
        ByteBuffer gotValue = kv.getValue();
        if (!expectedValue.equals(gotValue)) {
            LOG.error("The value returned from the key-value store iterator is not expected");
            return false;
        }
    }
    return true;
}
Also used : KeyValuePair(alluxio.client.keyvalue.KeyValuePair) KeyValueIterator(alluxio.client.keyvalue.KeyValueIterator) HashMap(java.util.HashMap) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer)

Example 2 with KeyValueIterator

use of alluxio.client.keyvalue.KeyValueIterator in project alluxio by Alluxio.

the class SameKeyValueStoresTest method areTheSameStores.

private boolean areTheSameStores(KeyValueStoreReader reader1, KeyValueStoreReader reader2) throws Exception {
    // The two stores are the same if the number of key-value pairs are the same, and the stores
    // have the same value for all the keys in store1.
    int size1 = reader1.size();
    int size2 = reader2.size();
    if (size1 != size2) {
        LOG.error("store {} has {} pairs while another has {} pairs", mStoreUri1, size1, size2);
        return false;
    }
    KeyValueIterator iterator = reader1.iterator();
    while (iterator.hasNext()) {
        KeyValuePair pair1 = iterator.next();
        byte[] key1 = BufferUtils.newByteArrayFromByteBuffer(pair1.getKey());
        byte[] value1 = BufferUtils.newByteArrayFromByteBuffer(pair1.getValue());
        byte[] value2 = reader2.get(key1);
        if (value2 == null) {
            LOG.error("store {} has value for key {} while another has no value for the same key", mStoreUri1, FormatUtils.byteArrayToHexString(key1));
            return false;
        }
        if (!ByteBuffer.wrap(value1).equals(ByteBuffer.wrap(value2))) {
            LOG.error("value for key {} are different in the two stores", FormatUtils.byteArrayToHexString(key1));
            return false;
        }
    }
    return true;
}
Also used : KeyValuePair(alluxio.client.keyvalue.KeyValuePair) KeyValueIterator(alluxio.client.keyvalue.KeyValueIterator)

Example 3 with KeyValueIterator

use of alluxio.client.keyvalue.KeyValueIterator in project alluxio by Alluxio.

the class ShowKeyValueStore method main.

/**
   * @param args two parameters, the first is the key-value store URI, the second is the scope of
   *    the store to be shown ("key" to show only keys, "value" to show only values, and "all" to
   *    show both keys and values)
   * @throws Exception if any exception happens
   */
public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        System.out.println("Usage: java -cp " + RuntimeConstants.ALLUXIO_JAR + " " + ShowKeyValueStore.class.getName() + " <key-value store URI>" + " <scope, be one of key/value/all>");
        System.exit(-1);
    }
    KeyValueStoreReader reader = KeyValueSystem.Factory.create().openStore(new AlluxioURI(args[0]));
    KeyValueIterator iterator = reader.iterator();
    while (iterator.hasNext()) {
        show(iterator.next(), args[1]);
    }
    reader.close();
}
Also used : KeyValueIterator(alluxio.client.keyvalue.KeyValueIterator) KeyValueStoreReader(alluxio.client.keyvalue.KeyValueStoreReader) AlluxioURI(alluxio.AlluxioURI)

Aggregations

KeyValueIterator (alluxio.client.keyvalue.KeyValueIterator)3 KeyValuePair (alluxio.client.keyvalue.KeyValuePair)2 AlluxioURI (alluxio.AlluxioURI)1 KeyValueStoreReader (alluxio.client.keyvalue.KeyValueStoreReader)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1