Search in sources :

Example 11 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project YCSB by brianfrankcooper.

the class HBaseClient10 method read.

/**
   * Read a record from the database. Each field/value pair from the result will
   * be stored in a HashMap.
   *
   * @param table
   *          The name of the table
   * @param key
   *          The record key of the record to read.
   * @param fields
   *          The list of fields to read, or null for all of them
   * @param result
   *          A HashMap of field/value pairs for the result
   * @return Zero on success, a non-zero error code on error
   */
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    // 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;
        }
    }
    Result r = null;
    try {
        if (debug) {
            System.out.println("Doing read from HBase columnfamily " + columnFamily);
            System.out.println("Doing read for key: " + key);
        }
        Get g = new Get(Bytes.toBytes(key));
        if (fields == null) {
            g.addFamily(columnFamilyBytes);
        } else {
            for (String field : fields) {
                g.addColumn(columnFamilyBytes, Bytes.toBytes(field));
            }
        }
        r = currentTable.get(g);
    } catch (IOException e) {
        if (debug) {
            System.err.println("Error doing get: " + e);
        }
        return Status.ERROR;
    } catch (ConcurrentModificationException e) {
        // do nothing for now...need to understand HBase concurrency model better
        return Status.ERROR;
    }
    if (r.isEmpty()) {
        return Status.NOT_FOUND;
    }
    while (r.advance()) {
        final Cell c = r.current();
        result.put(Bytes.toString(CellUtil.cloneQualifier(c)), new ByteArrayByteIterator(CellUtil.cloneValue(c)));
        if (debug) {
            System.out.println("Result for field: " + Bytes.toString(CellUtil.cloneQualifier(c)) + " is: " + Bytes.toString(CellUtil.cloneValue(c)));
        }
    }
    return Status.OK;
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) Get(org.apache.hadoop.hbase.client.Get) IOException(java.io.IOException) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result)

Example 12 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project YCSB by brianfrankcooper.

the class HBaseClient10 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, HashMap<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) {
            Preconditions.checkNotNull(bufferedMutator);
            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) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Put(org.apache.hadoop.hbase.client.Put)

Example 13 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project hazelcast by hazelcast.

the class TransactionalMultiMapProxySupport method removeAllInternal.

protected Collection<MultiMapRecord> removeAllInternal(Data key) {
    checkObjectNotNull(key);
    long timeout = tx.getTimeoutMillis();
    long ttl = extendTimeout(timeout);
    Collection<MultiMapRecord> coll = txMap.get(key);
    final MultiMapTransactionLogRecord logRecord;
    if (coll == null) {
        MultiMapResponse response = lockAndGet(key, timeout, ttl);
        if (response == null) {
            throw new ConcurrentModificationException("Transaction couldn't obtain lock " + getThreadId());
        }
        coll = createCollection(response.getRecordCollection(getNodeEngine()));
        logRecord = new MultiMapTransactionLogRecord(getPartitionId(key), key, name, ttl, getThreadId());
        tx.add(logRecord);
    } else {
        logRecord = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key));
    }
    txMap.put(key, createCollection());
    TxnRemoveAllOperation operation = new TxnRemoveAllOperation(name, key, coll);
    logRecord.addOperation(operation);
    return coll;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) ConcurrentModificationException(java.util.ConcurrentModificationException) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse)

Example 14 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project hazelcast by hazelcast.

the class TransactionalMultiMapProxySupport method putInternal.

protected boolean putInternal(Data key, Data value) {
    checkObjectNotNull(key);
    checkObjectNotNull(value);
    Collection<MultiMapRecord> coll = txMap.get(key);
    long recordId = -1;
    long timeout = tx.getTimeoutMillis();
    long ttl = extendTimeout(timeout);
    final MultiMapTransactionLogRecord logRecord;
    if (coll == null) {
        MultiMapResponse response = lockAndGet(key, timeout, ttl);
        if (response == null) {
            throw new ConcurrentModificationException("Transaction couldn't obtain lock " + getThreadId());
        }
        recordId = response.getNextRecordId();
        coll = createCollection(response.getRecordCollection(getNodeEngine()));
        txMap.put(key, coll);
        logRecord = new MultiMapTransactionLogRecord(getPartitionId(key), key, name, ttl, getThreadId());
        tx.add(logRecord);
    } else {
        logRecord = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key));
    }
    MultiMapRecord record = new MultiMapRecord(config.isBinary() ? value : toObjectIfNeeded(value));
    if (coll.add(record)) {
        if (recordId == -1) {
            recordId = nextId(key);
        }
        record.setRecordId(recordId);
        TxnPutOperation operation = new TxnPutOperation(name, key, value, recordId);
        logRecord.addOperation(operation);
        return true;
    }
    return false;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) ConcurrentModificationException(java.util.ConcurrentModificationException) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse)

Example 15 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project hazelcast by hazelcast.

the class TransactionalMultiMapProxySupport method removeInternal.

protected boolean removeInternal(Data key, Data value) {
    checkObjectNotNull(key);
    checkObjectNotNull(value);
    Collection<MultiMapRecord> coll = txMap.get(key);
    long timeout = tx.getTimeoutMillis();
    long ttl = extendTimeout(timeout);
    final MultiMapTransactionLogRecord logRecord;
    if (coll == null) {
        MultiMapResponse response = lockAndGet(key, timeout, ttl);
        if (response == null) {
            throw new ConcurrentModificationException("Transaction couldn't obtain lock " + getThreadId());
        }
        coll = createCollection(response.getRecordCollection(getNodeEngine()));
        txMap.put(key, coll);
        logRecord = new MultiMapTransactionLogRecord(getPartitionId(key), key, name, ttl, getThreadId());
        tx.add(logRecord);
    } else {
        logRecord = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key));
    }
    MultiMapRecord record = new MultiMapRecord(config.isBinary() ? value : toObjectIfNeeded(value));
    Iterator<MultiMapRecord> iterator = coll.iterator();
    long recordId = -1;
    while (iterator.hasNext()) {
        MultiMapRecord r = iterator.next();
        if (r.equals(record)) {
            iterator.remove();
            recordId = r.getRecordId();
            break;
        }
    }
    if (recordId != -1) {
        TxnRemoveOperation operation = new TxnRemoveOperation(name, key, recordId, value);
        logRecord.addOperation(operation);
        return recordId != -1;
    }
    return false;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) ConcurrentModificationException(java.util.ConcurrentModificationException) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse)

Aggregations

ConcurrentModificationException (java.util.ConcurrentModificationException)89 Iterator (java.util.Iterator)24 HashSet (java.util.HashSet)19 Set (java.util.Set)18 ResultSet (java.sql.ResultSet)16 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)11 HashMap (java.util.HashMap)9 GameLocal (org.apache.openejb.test.entity.cmr.manytomany.GameLocal)8 PlatformLocal (org.apache.openejb.test.entity.cmr.manytomany.PlatformLocal)8 ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)8 SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)8 List (java.util.List)7 Test (org.junit.Test)7 Map (java.util.Map)6 AbstractList (java.util.AbstractList)5 NoSuchElementException (java.util.NoSuchElementException)5 Collection (java.util.Collection)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 MultiMapRecord (com.hazelcast.multimap.impl.MultiMapRecord)3