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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations