| | |
| | | { |
| | | try |
| | | { |
| | | Database tree = getOrOpenTree(treeName); |
| | | DatabaseEntry dbKey = db(key); |
| | | DatabaseEntry dbValue = new DatabaseEntry(); |
| | | |
| | | boolean isDefined = tree.get(txn, dbKey, dbValue, RMW) == SUCCESS; |
| | | final Database tree = getOrOpenTree(treeName); |
| | | final DatabaseEntry dbKey = db(key); |
| | | final DatabaseEntry dbValue = new DatabaseEntry(); |
| | | for (;;) |
| | | { |
| | | final boolean isDefined = tree.get(txn, dbKey, dbValue, RMW) == SUCCESS; |
| | | final ByteSequence oldValue = valueToBytes(dbValue, isDefined); |
| | | final ByteSequence newValue = f.computeNewValue(oldValue); |
| | | if (!Objects.equals(newValue, oldValue)) |
| | | if (Objects.equals(newValue, oldValue)) |
| | | { |
| | | return false; |
| | | } |
| | | if (newValue == null) |
| | | { |
| | | return tree.delete(txn, dbKey) == SUCCESS; |
| | | } |
| | | |
| | | setData(dbValue, newValue); |
| | | if (isDefined) |
| | | { |
| | | return tree.put(txn, dbKey, dbValue) == SUCCESS; |
| | | } |
| | | return false; |
| | | else if (tree.putNoOverwrite(txn, dbKey, dbValue) == SUCCESS) |
| | | { |
| | | return true; |
| | | } |
| | | // else retry due to phantom read: another thread inserted a record |
| | | } |
| | | } |
| | | catch (DatabaseException e) |
| | | { |