@Override public void closeWriter() throws JasDBStorageException { this.writer.closeWriter(); this.index.close(); }
@Override public long getDiskSize() throws JasDBStorageException { return this.writer.getDiskSize(); }
@Override public long getSize() { return this.writer.getSize(); }
@Override public RecordResult readRecord(UUIDKey documentId) throws JasDBStorageException { try { return writer.readRecord(() -> getRecordPointer(documentId)); } catch(RecordNotFoundException e) { return new RecordResultImpl(-1, null, 0, RECORD_FLAG.EMPTY); } }
@Override public RecordIterator readAllRecords(int limit) throws DatastoreException { return writer.readAllRecords(limit); }
@Override public boolean isOpen() { return this.writer.isOpen(); }
@Override public void removeRecord(UUIDKey documentId) throws JasDBStorageException { writer.removeRecord(() -> getRecordPointer(documentId), p -> { try { index.removeFromIndex(documentId); } catch (JasDBStorageException e) { LOG.error("Unable to remove record from index", e); } }); }
@Override public void updateRecord(UUIDKey documentId, ClonableDataStream dataStream) throws JasDBStorageException { long updatedDocumentPointer = writer.updateRecord(RecordStreamUtil.toString(dataStream), () -> getRecordPointer(documentId), (oldp, newp) -> { if(oldp != newp) { Key newKey = documentId.cloneKey(false).addKey(keyInfo.getKeyNameMapper(), "RECORD_POINTER", new LongKey(newp)); try { index.updateKey(documentId, newKey); } catch (JasDBStorageException e) { LOG.error("", e); } } }); }
@Override public void writeRecord(UUIDKey documentId, ClonableDataStream dataStream) throws JasDBStorageException { String recordContents = RecordStreamUtil.toString(dataStream); writer.writeRecord(recordContents, p -> { try { index.insertIntoIndex(documentId.cloneKey(false).addKey(keyInfo.getKeyNameMapper(), "RECORD_POINTER", new LongKey(p))); } catch(JasDBStorageException e) { try { removeRecord(documentId); } catch (JasDBStorageException e1) { LOG.error("", e); } throw new RuntimeJasDBException("Unable to write record already exists", e); } }); }
@Override public void openWriter() throws JasDBStorageException { this.keyInfo = new KeyInfoImpl(new SimpleIndexField("__ID", new UUIDKeyType()), new SimpleIndexField("RECORD_POINTER", new LongKeyType())); this.index = new BTreeIndex(indexLocation, keyInfo); this.writer.openWriter(); this.index.openIndex(); }
private void loadNextRecord() { try { RecordResultImpl foundRecord; do { foundRecord = recordWriter.readRecord(() -> Optional.of(nextRecordPointer)); nextRecordPointer = nextRecordPointer + foundRecord.getRecordSize(); } while(foundRecord.getRecordFlag() != RECORD_FLAG.ACTIVE && foundRecord.getRecordFlag() != RECORD_FLAG.EMPTY); if(foundRecord.getRecordFlag() == RECORD_FLAG.ACTIVE) { foundRecords++; nextLoadedRecord = foundRecord; } else { nextLoadedRecord = null; } } catch(JasDBStorageException e) { LOG.error("Unable to find next record, error accessing storage", e); } }
public void verify(Function<RecordResult, UUIDKey> f) { try { RecordIterator recordResults = writer.readAllRecords(); for(RecordResult result : recordResults) { UUIDKey key = f.apply(result);