@Test public void readRelGroupWithHugeTypeInV2_2_10() throws IOException { assertCanReadRelGroup( new PhysicalLogCommandReaderV2_2_10() ); }
private IndexCommandHeader readIndexCommandHeader( ReadableChannel channel ) throws IOException { byte firstHeaderByte = channel.get(); byte valueType = (byte) ((firstHeaderByte & 0x1C) >> 2); byte entityType = (byte) ((firstHeaderByte & 0x2) >> 1); boolean entityIdNeedsLong = (firstHeaderByte & 0x1) > 0; byte secondHeaderByte = channel.get(); boolean startNodeNeedsLong = (secondHeaderByte & 0x80) > 0; boolean endNodeNeedsLong = (secondHeaderByte & 0x40) > 0; int indexNameId = getUnsignedShort( channel ); int keyId = getUnsignedShort( channel ); return new IndexCommandHeader( valueType, entityType, entityIdNeedsLong, indexNameId, startNodeNeedsLong, endNodeNeedsLong, keyId ); }
private <T> int readDynamicRecords( ReadableChannel channel, T target, DynamicRecordAdder<T> adder ) throws IOException { int numberOfRecords = channel.getInt(); assert numberOfRecords >= 0; while ( numberOfRecords > 0 ) { DynamicRecord read = readDynamicRecord( channel ); if ( read == null ) { return -1; } adder.add( target, read ); numberOfRecords--; } return numberOfRecords; }
private Command visitIndexDefineCommand( ReadableChannel channel ) throws IOException { readIndexCommandHeader( channel ); MutableObjectIntMap<String> indexNames = readMap( channel ); MutableObjectIntMap<String> keys = readMap( channel ); IndexDefineCommand command = new IndexDefineCommand(); command.init( indexNames, keys ); return command; }
private Command visitSchemaRuleCommand( ReadableChannel channel ) throws IOException { Collection<DynamicRecord> recordsBefore = new ArrayList<>(); readDynamicRecords( channel, recordsBefore, COLLECTION_DYNAMIC_RECORD_ADDER ); Collection<DynamicRecord> recordsAfter = new ArrayList<>(); readDynamicRecords( channel, recordsAfter, COLLECTION_DYNAMIC_RECORD_ADDER ); byte isCreated = channel.get(); if ( 1 == isCreated ) { for ( DynamicRecord record : recordsAfter ) { record.setCreated(); } } SchemaRule rule = Iterables.first( recordsAfter ).inUse() ? readSchemaRule( recordsAfter ) : readSchemaRule( recordsBefore ); return new Command.SchemaRuleCommand( recordsBefore, recordsAfter, rule ); }
private Command visitIndexAddNodeCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); Number entityId = header.entityIdNeedsLong ? channel.getLong() : channel.getInt(); Object value = readIndexValue( header.valueType, channel ); AddNodeCommand command = new AddNodeCommand(); command.init( header.indexNameId, entityId.longValue(), header.keyId, value ); return command; }
PropertyBlock block = readPropertyBlock( channel ); if ( block == null ) int deletedRecords = readDynamicRecords( channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER ); if ( deletedRecords == -1 ) while ( deletedRecords-- > 0 ) DynamicRecord read = readDynamicRecord( channel ); if ( read == null )
private PropertyBlock readPropertyBlock( ReadableChannel channel ) throws IOException { PropertyBlock toReturn = new PropertyBlock(); byte blockSize = channel.get(); // the size is stored in bytes // 1 assert blockSize > 0 && blockSize % 8 == 0 : blockSize + " is not a valid block size value"; // Read in blocks long[] blocks = readLongs( channel, blockSize / 8 ); assert blocks.length == blockSize / 8 : blocks.length + " longs were read in while i asked for what corresponds to " + blockSize; assert PropertyType.getPropertyTypeOrThrow( blocks[0] ).calculateNumberOfBlocksUsed( blocks[0] ) == blocks.length : blocks.length + " is not a valid number of blocks for type " + PropertyType.getPropertyTypeOrThrow( blocks[0] ); /* * Ok, now we may be ready to return, if there are no DynamicRecords. So * we start building the Object */ toReturn.setValueBlocks( blocks ); /* * Read in existence of DynamicRecords. Remember, this has already been * read in the buffer with the blocks, above. */ if ( readDynamicRecords( channel, toReturn, PROPERTY_BLOCK_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return toReturn; }
private Command visitIndexDeleteCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); DeleteCommand command = new DeleteCommand(); command.init( header.indexNameId, header.entityType ); return command; }
readDynamicRecords( channel, dynamicLabelRecords, COLLECTION_DYNAMIC_RECORD_ADDER ); record.setLabelField( labelField, dynamicLabelRecords ); record.setInUse( inUse );
private Command visitNodeCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); NodeRecord before = readNodeRecord( id, channel ); if ( before == null ) { return null; } NodeRecord after = readNodeRecord( id, channel ); if ( after == null ) { return null; } if ( !before.inUse() && after.inUse() ) { after.setCreated(); } return new Command.NodeCommand( before, after ); }
private Command visitIndexRemoveCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); Number entityId = header.entityIdNeedsLong ? channel.getLong() : channel.getInt(); Object value = readIndexValue( header.valueType, channel ); RemoveCommand command = new RemoveCommand(); command.init( header.indexNameId, header.entityType, entityId.longValue(), header.keyId, value ); return command; }
PropertyBlock block = readPropertyBlock( channel ); if ( block == null ) int deletedRecords = readDynamicRecords( channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER ); if ( deletedRecords == -1 ) while ( deletedRecords-- > 0 ) DynamicRecord read = readDynamicRecord( channel ); if ( read == null )
private Command visitIndexDefineCommand( ReadableChannel channel ) throws IOException { readIndexCommandHeader( channel ); MutableObjectIntMap<String> indexNames = readMap( channel ); MutableObjectIntMap<String> keys = readMap( channel ); IndexDefineCommand command = new IndexDefineCommand(); command.init( indexNames, keys ); return command; }
private Command visitSchemaRuleCommand( ReadableChannel channel ) throws IOException { Collection<DynamicRecord> recordsBefore = new ArrayList<>(); readDynamicRecords( channel, recordsBefore, COLLECTION_DYNAMIC_RECORD_ADDER ); Collection<DynamicRecord> recordsAfter = new ArrayList<>(); readDynamicRecords( channel, recordsAfter, COLLECTION_DYNAMIC_RECORD_ADDER ); byte isCreated = channel.get(); if ( 1 == isCreated ) { for ( DynamicRecord record : recordsAfter ) { record.setCreated(); } } SchemaRule rule = Iterables.first( recordsAfter ).inUse() ? readSchemaRule( recordsAfter ) : readSchemaRule( recordsBefore ); return new Command.SchemaRuleCommand( recordsBefore, recordsAfter, rule ); }
private PropertyBlock readPropertyBlock( ReadableChannel channel ) throws IOException { PropertyBlock toReturn = new PropertyBlock(); byte blockSize = channel.get(); // the size is stored in bytes // 1 assert blockSize > 0 && blockSize % 8 == 0 : blockSize + " is not a valid block size value"; // Read in blocks long[] blocks = readLongs( channel, blockSize / 8 ); assert blocks.length == blockSize / 8 : blocks.length + " longs were read in while i asked for what corresponds to " + blockSize; assert PropertyType.getPropertyTypeOrThrow( blocks[0] ).calculateNumberOfBlocksUsed( blocks[0] ) == blocks.length : blocks.length + " is not a valid number of blocks for type " + PropertyType.getPropertyTypeOrThrow( blocks[0] ); /* * Ok, now we may be ready to return, if there are no DynamicRecords. So * we start building the Object */ toReturn.setValueBlocks( blocks ); /* * Read in existence of DynamicRecords. Remember, this has already been * read in the buffer with the blocks, above. */ if ( readDynamicRecords( channel, toReturn, PROPERTY_BLOCK_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return toReturn; }
private Command visitIndexCreateCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); Map<String,String> config = read2bMap( channel ); CreateCommand command = new CreateCommand(); command.init( header.indexNameId, header.entityType, config ); return command; }
private Command visitPropertyKeyTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int) int id = channel.getInt(); 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 new Command.PropertyKeyTokenCommand( null, record ); }
private Command visitNodeCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); NodeRecord before = readNodeRecord( id, channel ); if ( before == null ) { return null; } NodeRecord after = readNodeRecord( id, channel ); if ( after == null ) { return null; } if ( !before.inUse() && after.inUse() ) { after.setCreated(); } return new Command.NodeCommand( before, after ); }
private Command visitIndexAddRelationshipCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); Number entityId = header.entityIdNeedsLong ? channel.getLong() : channel.getInt(); Object value = readIndexValue( header.valueType, channel ); Number startNode = header.startNodeNeedsLong ? channel.getLong() : channel.getInt(); Number endNode = header.endNodeNeedsLong ? channel.getLong() : channel.getInt(); AddRelationshipCommand command = new AddRelationshipCommand(); command.init( header.indexNameId, entityId.longValue(), header.keyId, value, startNode.longValue(), endNode.longValue() ); return command; }