Search in sources :

Example 71 with ByteIterator

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

the class RestWorkload method doTransactionInsert.

@Override
public void doTransactionInsert(DB db) {
    HashMap<String, ByteIterator> value = new HashMap<String, ByteIterator>();
    // Create random bytes of insert data with a specific size.
    value.put("data", new RandomByteIterator(fieldlengthgenerator.nextValue().longValue()));
    db.insert(null, getNextURL(2), value);
}
Also used : RandomByteIterator(site.ycsb.RandomByteIterator) ByteIterator(site.ycsb.ByteIterator) HashMap(java.util.HashMap) RandomByteIterator(site.ycsb.RandomByteIterator)

Example 72 with ByteIterator

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

the class CrailClient method insert.

@Override
public Status insert(String table, String key, Map<String, ByteIterator> values) {
    try {
        String path = table + "/" + key;
        CrailKeyValue file = client.create(path, CrailNodeType.KEYVALUE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, enumerateKeys).get().asKeyValue();
        CrailBufferedOutputStream stream = file.getBufferedOutputStream(1024);
        for (Entry<String, ByteIterator> entry : values.entrySet()) {
            byte[] fieldKey = entry.getKey().getBytes();
            int fieldKeyLength = fieldKey.length;
            byte[] fieldValue = entry.getValue().toArray();
            int fieldValueLength = fieldValue.length;
            stream.writeInt(fieldKeyLength);
            stream.write(fieldKey);
            stream.writeInt(fieldValueLength);
            stream.write(fieldValue);
        }
        file.syncDir();
        stream.close();
    } catch (Exception e) {
        LOG.error("Error during insert, table " + table + ", key " + key + ", exception " + e.getMessage());
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) CrailKeyValue(org.apache.crail.CrailKeyValue) CrailBufferedOutputStream(org.apache.crail.CrailBufferedOutputStream) DBException(site.ycsb.DBException)

Example 73 with ByteIterator

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

the class ElasticsearchClientTest method testUpdate.

/**
 * Test of update method, of class ElasticsearchClient.
 */
@Test
public void testUpdate() {
    int i;
    HashMap<String, ByteIterator> newValues = new HashMap<>(10);
    for (i = 1; i <= 10; i++) {
        newValues.put(FIELD_PREFIX + i, new StringByteIterator("newvalue" + i));
    }
    Status result = instance.update(MOCK_TABLE, MOCK_KEY1, newValues);
    assertEquals(Status.OK, result);
    // validate that the values changed
    HashMap<String, ByteIterator> resultParam = new HashMap<>(10);
    instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam);
    for (i = 1; i <= 10; i++) {
        assertEquals("newvalue" + i, resultParam.get(FIELD_PREFIX + i).toString());
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Test(org.junit.Test)

Example 74 with ByteIterator

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

the class HBaseClient2 method update.

/**
 * Update a record in the database. Any field/value pairs in the specified
 * values HashMap will be written into the record with the specified record
 * key, overwriting any existing values with the same field name.
 *
 * @param table
 *          The name of the table
 * @param key
 *          The record key of the record to write
 * @param values
 *          A HashMap of field/value pairs to update in the record
 * @return Zero on success, a non-zero error code on error
 */
@Override
public Status update(String table, String key, Map<String, ByteIterator> values) {
    // if this is a "new" table, init HTable object. Else, use existing one
    if (!tableName.equals(table)) {
        currentTable = null;
        try {
            getHTable(table);
            tableName = table;
        } catch (IOException e) {
            System.err.println("Error accessing HBase table: " + e);
            return Status.ERROR;
        }
    }
    if (debug) {
        System.out.println("Setting up put for key: " + key);
    }
    Put p = new Put(Bytes.toBytes(key));
    p.setDurability(durability);
    for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
        byte[] value = entry.getValue().toArray();
        if (debug) {
            System.out.println("Adding field/value " + entry.getKey() + "/" + Bytes.toStringBinary(value) + " to put request");
        }
        p.addColumn(columnFamilyBytes, Bytes.toBytes(entry.getKey()), value);
    }
    try {
        if (clientSideBuffering) {
            // removed Preconditions.checkNotNull, which throws NPE, in favor of NPE on next line
            bufferedMutator.mutate(p);
        } else {
            currentTable.put(p);
        }
    } catch (IOException e) {
        if (debug) {
            System.err.println("Error doing put: " + e);
        }
        return Status.ERROR;
    } catch (ConcurrentModificationException e) {
        // do nothing for now...hope this is rare
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Put(org.apache.hadoop.hbase.client.Put)

Example 75 with ByteIterator

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

the class IgniteClientTest method testReadNotPresent.

@Test
public void testReadNotPresent() throws Exception {
    cluster.cache(DEFAULT_CACHE_NAME).clear();
    final String key = "key";
    final Map<String, String> input = new HashMap<>();
    input.put("field0", "value1");
    input.put("field1", "value2A");
    input.put("field3", null);
    final Status sPut = client.insert(DEFAULT_CACHE_NAME, key, StringByteIterator.getByteIteratorMap(input));
    assertThat(sPut, is(Status.OK));
    assertThat(cluster.cache(DEFAULT_CACHE_NAME).size(), is(1));
    final Set<String> fld = new TreeSet<>();
    final String newKey = "newKey";
    final HashMap<String, ByteIterator> result1 = new HashMap<>();
    final Status sGet = client.read(DEFAULT_CACHE_NAME, newKey, fld, result1);
    assertThat(sGet, is(Status.NOT_FOUND));
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) Test(org.junit.Test)

Aggregations

ByteIterator (site.ycsb.ByteIterator)131 HashMap (java.util.HashMap)98 StringByteIterator (site.ycsb.StringByteIterator)92 Status (site.ycsb.Status)62 Test (org.junit.Test)53 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)34 DBException (site.ycsb.DBException)30 Map (java.util.Map)20 IOException (java.io.IOException)10 Put (org.apache.hadoop.hbase.client.Put)8 ArrayList (java.util.ArrayList)7 Vector (java.util.Vector)7 ByteBuffer (java.nio.ByteBuffer)6 HashSet (java.util.HashSet)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 NumericByteIterator (site.ycsb.NumericByteIterator)5 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)4 Properties (java.util.Properties)4 Assume.assumeNoException (org.junit.Assume.assumeNoException)4 DB (site.ycsb.DB)4