/** * Utility methods for reading records. These are not on the interface itself since it should be * an explicit choice when to create the record instances passed into it. * Also for mocking purposes it's less confusing and error prone having only a single method. */ static <R extends AbstractBaseRecord> R getRecord( RecordStore<R> store, long id, RecordLoad mode ) { R record = store.newRecord(); store.getRecord( id, record, mode ); return record; }
public void warmUpCache() { int recordsPerPage = store.getRecordsPerPage(); long id = 0; long half = store.getHighId() / 2; RECORD record = store.newRecord(); while ( id < half ) { store.getRecord( id, record, FORCE ); id += recordsPerPage - 1; } } }
private static <RECORD extends AbstractBaseRecord> void migrate( RecordStore<RECORD> from, RecordStore<RECORD> to ) { to.setHighestPossibleIdInUse( from.getHighestPossibleIdInUse() ); from.scanAllRecords( record -> { to.prepareForCommit( record ); to.updateRecord( record ); return false; } ); }
@Override protected long position() { return store.getHighId() * store.getRecordSize(); } }
private static void breakTheChain( RecordStore<RelationshipRecord> relationshipStore ) { RelationshipRecord record = relationshipStore.getRecord( 10, relationshipStore.newRecord(), NORMAL ); long relationshipTowardsEndOfChain = record.getFirstNode(); while ( record.inUse() && !record.isFirstInFirstChain() ) { record = relationshipStore.getRecord( relationshipTowardsEndOfChain, relationshipStore.newRecord(), FORCE ); relationshipTowardsEndOfChain = record.getFirstPrevRel(); } relationshipStore.updateRecord( new RelationshipRecord( relationshipTowardsEndOfChain, 0, 0, 0 ) ); }
public static <RECORD extends AbstractBaseRecord> int numberOfRecordsInUse( RecordStore<RECORD> store ) { int inUse = 0; for ( long id = store.getNumberOfReservedLowIds(); id < store.getHighId(); id++ ) { RECORD record = store.getRecord( id, store.newRecord(), RecordLoad.FORCE ); if ( record.inUse() ) { inUse++; } } return inUse; }
private static <T extends AbstractBaseRecord> T[] readAllRecords( Class<T> type, RecordStore<T> store ) { @SuppressWarnings( "unchecked" ) T[] records = (T[]) Array.newInstance( type, (int) store.getHighId() ); for ( int i = 0; i < records.length; i++ ) { records[i] = store.getRecord( i, store.newRecord(), FORCE ); } return records; } }
int relationshipTypeCount = 50; RecordStore<RelationshipGroupRecord> groupStore = stores.getTemporaryRelationshipGroupStore(); RelationshipGroupRecord groupRecord = groupStore.newRecord(); RecordStore<NodeRecord> nodeStore = stores.getNodeStore(); NodeRecord nodeRecord = nodeStore.newRecord(); long cursor = 0; for ( int typeId = relationshipTypeCount - 1; typeId >= 0; typeId-- ) groupRecord.setId( groupStore.nextId() ); groupStore.updateRecord( groupRecord ); nodeStore.updateRecord( nodeRecord ); nodeStore.setHighestPossibleIdInUse( nodeId );
@Test public void shouldReportRelationshipTypeInconsistencies() throws Exception { // given StoreAccess access = fixture.directStoreAccess().nativeStores(); RecordStore<RelationshipTypeTokenRecord> relTypeStore = access.getRelationshipTypeTokenStore(); RelationshipTypeTokenRecord record = relTypeStore.getRecord( (int) relTypeStore.nextId(), relTypeStore.newRecord(), FORCE ); record.setNameId( 20 ); record.setInUse( true ); relTypeStore.updateRecord( record ); // when ConsistencySummaryStatistics stats = check(); // then access.close(); on( stats ).verify( RecordType.RELATIONSHIP_TYPE, 1 ) .andThatsAllFolks(); }
protected R getHeavy( S store, int id ) { R record = store.getRecord( id, store.newRecord(), NORMAL ); store.ensureHeavy( record ); return record; }
@Override public R getRecord( long id, R target, RecordLoad mode ) throws InvalidRecordException { return actual.getRecord( id, target, mode ); }
@Override public long getHighId() { return actual.getHighId(); }
private <RECORD extends AbstractBaseRecord> void createRecordIn( RecordStore<RECORD> store ) { RECORD record = store.newRecord(); record.setId( store.nextId() ); record.setInUse( true ); if ( record instanceof PropertyRecord ) { // Special hack for property store, since it's not enough to simply set a record as in use there PropertyBlock block = new PropertyBlock(); ((PropertyStore)store).encodeValue( block, 0, Values.of( 10 ) ); ((PropertyRecord) record).addPropertyBlock( block ); } store.updateRecord( record ); }
private byte[] newRecordBuffer() { return new byte[schemaStore.getRecordSize() * 4]; } }
@Override public void updateRecord( R record ) { actual.updateRecord( record ); }
byte[] recData = null; int len; RecordStore rs = RecordStore.openRecordStore("StoryDataBase1", true); if (rs.getNumRecords() > 0) { recData = new byte[rs.getRecordSize(1)]; len = rs.getRecord(1, recData, 0); String value = new String(recData, 0, len); if(value == null) { .... } else { ... } }
static RecordIdIterator allInReversed( RecordStore<? extends AbstractBaseRecord> store, Configuration config ) { return backwards( store.getNumberOfReservedLowIds(), store.getHighId(), config ); }
@SuppressWarnings( "unchecked" ) @Test public void shouldProcessAllTheRecordsInAStore() throws Exception { // given RecordStore<NodeRecord> nodeStore = stores.builder().build().getNodeStore(); ConsistencyReport.Reporter reporter = mock( ConsistencyReport.Reporter.class ); StoreProcessor processor = new StoreProcessor( CheckDecorator.NONE, reporter, Stage.SEQUENTIAL_FORWARD, CacheAccess.EMPTY ); nodeStore.updateRecord( node( 0, false, 0, 0 ) ); nodeStore.updateRecord( node( 1, false, 0, 0 ) ); nodeStore.updateRecord( node( 2, false, 0, 0 ) ); nodeStore.setHighestPossibleIdInUse( 2 ); // when processor.applyFiltered( nodeStore ); // then verify( reporter, times( 3 ) ).forNode( any( NodeRecord.class ), any( RecordCheck.class ) ); }
@Override public long nextId() { return actual.nextId(); }
boolean lastInChain = count == 0; group.setId( nextId == -1 ? nextId = store.nextId() : nextId ); if ( !lastInChain ) group.setNext( nextId = store.nextId() ); store.prepareForCommit( batch[j] );