@Override public void removeRecord(Supplier<Optional<Long>> recordPointerSupplier, Consumer<Long> postRemoveAction) throws DatastoreException { lock.lock(); try { long recordPointer = recordPointerSupplier.get().orElseThrow(() -> new RecordNotFoundException("Unable to remove record, could not be found")); ByteBuffer recordHeader = ByteBuffer.allocate(RECORD_HEADER_SIZE); int read = channel.read(recordHeader, recordPointer); if(read != -1) { recordHeader.putInt(HEADER_RECORD_FLAG, RECORD_FLAG.DELETED.getFlag()); recordHeader.flip(); channel.write(recordHeader, recordPointer); LOG.debug("Flagged record: {} for deletion", recordPointer); decrementRecordCount(); } if(postRemoveAction != null) { LOG.debug("Executing post remove action for record: {}", recordPointer); postRemoveAction.accept(recordPointer); } } catch(IOException e) { LOG.error("Unable to remove record from storage", e); } finally { lock.unlock(); } }
lock.lock(); try { long recordPointer = recordPointerSupplier.get().orElseThrow(() -> new RecordNotFoundException("Record not Found, cannot update")); long updatedRecordPointer;
@Override public RecordResultImpl readRecord(Supplier<Optional<Long>> recordPointerSupplier) throws DatastoreException { try { long recordPosition = recordPointerSupplier.get().orElseThrow(() -> new RecordNotFoundException("Unable to read record, could not be found")); LOG.debug("Reading record at position: {}", recordPosition);
private Optional<Long> getRecordPointer(UUIDKey documentId) { try { IndexSearchResultIterator resultIterator = index.searchIndex(new EqualsCondition(documentId), Index.NO_SEARCH_LIMIT); if (!resultIterator.isEmpty()) { Key key = resultIterator.next(); LongKey longKey = (LongKey) key.getKey(keyInfo.getKeyNameMapper(), "RECORD_POINTER"); return Optional.of(longKey.getKey()); } else { throw new RecordNotFoundException("Unable to read record: " + documentId + ", could not be found"); } } catch(JasDBStorageException e) { LOG.error("Unable lookup data record for document: {}", documentId); } return Optional.empty(); }