private PropertyKeyTokenRecord readPropertyKeyTokenRecord( int id, ReadableChannel channel ) throws IOException { // in_use(byte)+count(int)+key_blockId(int) byte inUseFlag = channel.get(); boolean inUse = false; if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() ) { inUse = true; } else if ( inUseFlag != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseFlag ); } PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( id ); record.setInUse( inUse ); record.setPropertyCount( channel.getInt() ); record.setNameId( channel.getInt() ); if ( readDynamicRecords( channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return record; }
@Test public void shouldApplyPropertyKeyTokenCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final PropertyKeyTokenRecord before = new PropertyKeyTokenRecord( 42 ); final PropertyKeyTokenRecord after = new PropertyKeyTokenRecord( 42 ); after.setInUse( true ); after.setNameId( 323 ); final Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand( before, after ); final NamedToken token = new NamedToken( "token", 21 ); when( propertyKeyTokenStore.getToken( (int) command.getKey() ) ).thenReturn( token ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( propertyKeyTokenStore, times( 1 ) ).setHighestPossibleIdInUse( after.getId() ); verify( propertyKeyTokenStore, times( 1 ) ).updateRecord( after ); verify( cacheAccess, times( 1 ) ).addPropertyKeyToken( token ); }
@Override public PropertyKeyTokenRecord clone() { PropertyKeyTokenRecord propertyKeyTokenRecord = new PropertyKeyTokenRecord( getIntId() ); propertyKeyTokenRecord.setInUse( inUse() ); if ( isCreated() ) { propertyKeyTokenRecord.setCreated(); } propertyKeyTokenRecord.setNameId( getNameId() ); propertyKeyTokenRecord.addNameRecords( getNameRecords() ); propertyKeyTokenRecord.setPropertyCount( getPropertyCount() ); return propertyKeyTokenRecord; } }
@Override protected void writeRecordData( PropertyKeyTokenRecord record, PageCursor cursor ) { cursor.putInt( record.getPropertyCount() ); cursor.putInt( record.getNameId() ); } }
private PropertyKeyTokenRecord createPropertyKeyTokenRecord( int id ) { PropertyKeyTokenRecord propertyKeyTokenRecord = new PropertyKeyTokenRecord( id ); propertyKeyTokenRecord.setInUse( true ); propertyKeyTokenRecord.setNameId( 333 ); propertyKeyTokenRecord.addNameRecord( new DynamicRecord( 43 ) ); return propertyKeyTokenRecord; } }
@Override public PropertyKeyTokenRecord newRecord() { return new PropertyKeyTokenRecord( -1 ); }
@Test void shouldReportDynamicBlockNotInUse() { // given PropertyKeyTokenRecord key = inUse( new PropertyKeyTokenRecord( 42 ) ); DynamicRecord name = addKeyName( notInUse( new DynamicRecord( 6 ) ) ); key.setNameId( (int) name.getId() ); // when PropertyKeyTokenConsistencyReport report = check( key ); // then verify( report ).nameBlockNotInUse( name ); verifyNoMoreInteractions( report ); }
private int createNewPropertyKeyId( String stringKey ) { int keyId = (int) propertyKeyTokenStore.nextId(); PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = propertyKeyTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); propertyKeyTokenStore.updateRecord( record ); tokenHolders.propertyKeyTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }
@Test public void shouldApplyPropertyKeyTokenCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final PropertyKeyTokenRecord before = new PropertyKeyTokenRecord( 42 ); final PropertyKeyTokenRecord after = new PropertyKeyTokenRecord( 42 ); after.setInUse( true ); after.setNameId( 323 ); final Command command = new PropertyKeyTokenCommand( before, after ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( propertyKeyTokenStore, times( 1 ) ).updateRecord( after ); }
public void create( PropertyKeyTokenRecord token ) { token.setCreated(); update( new PropertyKeyTokenRecord( token.getIntId() ), token ); }
private void writePropertyKeyTokenRecord( WritableChannel channel, PropertyKeyTokenRecord record ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int)+nr_key_records(int) byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue(); channel.put( inUse ); channel.putInt( record.getPropertyCount() ).putInt( record.getNameId() ); if ( record.isLight() ) { channel.putInt( 0 ); } else { writeDynamicRecords( channel, record.getNameRecords() ); } } }
private PropertyBlock propertyBlockWith( DynamicRecord dynamicRecord ) { PropertyBlock propertyBlock = new PropertyBlock(); PropertyKeyTokenRecord key = new PropertyKeyTokenRecord( 10 ); propertyBlock.setSingleBlock( key.getId() | (((long) PropertyType.STRING.intValue()) << 24) | (dynamicRecord .getId() << 28) ); propertyBlock.addValueRecord( dynamicRecord ); return propertyBlock; } }
@Override public Generator<PropertyKeyTokenRecord> propertyKeyToken() { return ( recordSize, format, recordId ) -> new PropertyKeyTokenRecord( toIntExact( recordId ) ).initialize( random.nextBoolean(), random.nextInt( tokenBits ), abs( random.nextInt() ) ); }
public void update( PropertyKeyTokenRecord before, PropertyKeyTokenRecord after ) { after.setInUse( true ); add( before, after ); }
PropertyKey( PropertyKeyTokenRecord record ) { this.id = record.getIntId(); }
public static PropertyBlock propertyBlock( PropertyKeyTokenRecord key, PropertyType type, long value ) { PropertyBlock block = new PropertyBlock(); block.setSingleBlock( key.getId() | (((long) type.intValue()) << 24) | (value << 28) ); return block; }
public void create( PropertyKeyTokenRecord token ) { token.setCreated(); update( token ); }
@Override public PropertyKeyTokenRecord newUnused( long key, Void additionalData ) { return andMarkAsCreated( new PropertyKeyTokenRecord( toIntExact( key ) ) ); }
@Test void shouldReportEmptyName() { // given PropertyKeyTokenRecord key = inUse( new PropertyKeyTokenRecord( 42 ) ); DynamicRecord name = addKeyName( inUse( new DynamicRecord( 6 ) ) ); key.setNameId( (int) name.getId() ); // when PropertyKeyTokenConsistencyReport report = check( key ); // then verify( report ).emptyName( name ); verifyNoMoreInteractions( report ); } }
private GraphDatabaseAPI databaseWithManyPropertyKeys( int propertyKeyCount ) { PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); StoreFactory storeFactory = new StoreFactory( testDirectory.databaseLayout(), Config.defaults(), new DefaultIdGeneratorFactory( fileSystemRule.get() ), pageCache, fileSystemRule.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY ); NeoStores neoStores = storeFactory.openAllNeoStores( true ); PropertyKeyTokenStore store = neoStores.getPropertyKeyTokenStore(); for ( int i = 0; i < propertyKeyCount; i++ ) { PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( (int) store.nextId() ); record.setInUse( true ); Collection<DynamicRecord> nameRecords = store.allocateNameRecords( PropertyStore.encodeString( key( i ) ) ); record.addNameRecords( nameRecords ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); store.updateRecord( record ); } neoStores.close(); return database(); }