use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreRuntimeException in project bookkeeper by apache.
the class MVCCStoreImpl method put.
private PutResult<K, V> put(long revision, WriteBatch batch, PutOp<K, V> op) {
// parameters
final K key = op.key();
final V val = op.value();
// raw key & value
final byte[] rawKey = keyCoder.encode(key);
final ByteBuf rawValBuf = valCoder.encodeBuf(val);
MVCCRecord record;
try {
record = getKeyRecord(key, rawKey);
} catch (StateStoreRuntimeException e) {
rawValBuf.release();
throw e;
}
// result
final PutResultImpl<K, V> result = resultFactory.newPutResult(revision);
MVCCRecord oldRecord = null;
try {
if (null != record) {
// validate the update revision before applying the update to the record
if (record.compareModRev(revision) >= 0) {
result.code(Code.SMALLER_REVISION);
return result;
}
if (ValueType.BYTES != record.getValueType()) {
result.code(Code.ILLEGAL_OP);
return result;
}
if (op.option().prevKv()) {
// make a copy before modification
oldRecord = record.duplicate();
}
record.setVersion(record.getVersion() + 1);
} else {
record = MVCCRecord.newRecord();
record.setCreateRev(revision);
record.setVersion(0);
}
record.setValue(rawValBuf, ValueType.BYTES);
record.setModRev(revision);
// write the mvcc record back
batch.put(dataCfHandle, rawKey, recordCoder.encode(record));
// finalize the result
result.code(Code.OK);
if (null != oldRecord) {
KeyValueImpl<K, V> prevKV = oldRecord.asKVRecord(recordFactory, key, valCoder);
result.prevKv(prevKV);
}
return result;
} catch (StateStoreRuntimeException e) {
result.close();
throw e;
} finally {
if (null != record) {
record.recycle();
}
if (null != oldRecord) {
oldRecord.recycle();
}
}
}
use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreRuntimeException in project bookkeeper by apache.
the class MVCCStoreImpl method processPut.
synchronized PutResult<K, V> processPut(long revision, PutOp<K, V> op) {
checkStoreOpen();
WriteBatch batch = new WriteBatch();
PutResult<K, V> result = null;
try {
result = put(revision, batch, op);
executeBatch(batch);
return result;
} catch (StateStoreRuntimeException e) {
if (null != result) {
result.close();
}
throw e;
} finally {
RocksUtils.close(batch);
}
}
use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreRuntimeException in project bookkeeper by apache.
the class MVCCStoreImpl method processDelete.
synchronized DeleteResult<K, V> processDelete(long revision, DeleteOp<K, V> op) {
checkStoreOpen();
WriteBatch batch = new WriteBatch();
DeleteResult<K, V> result = null;
try {
result = delete(revision, batch, op, true);
executeBatch(batch);
return result;
} catch (StateStoreRuntimeException e) {
if (null != result) {
result.close();
}
throw e;
} finally {
RocksUtils.close(batch);
}
}
Aggregations