Skip to content

Commit

Permalink
Reformatted weird looking lines
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint authored and davidegrohmann committed Dec 18, 2015
1 parent 93af592 commit 804d078
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 261 deletions.
Expand Up @@ -20,11 +20,6 @@
package org.neo4j.kernel.impl.transaction.command; package org.neo4j.kernel.impl.transaction.command;


import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collection;

import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException;
import org.neo4j.kernel.impl.store.AbstractDynamicStore;
import org.neo4j.kernel.impl.store.PropertyType; import org.neo4j.kernel.impl.store.PropertyType;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.NeoStoreRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord;
Expand All @@ -35,12 +30,9 @@
import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.kernel.impl.store.record.Record;
import org.neo4j.kernel.impl.store.record.RelationshipRecord; import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord; import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord;
import org.neo4j.kernel.impl.store.record.SchemaRule;
import org.neo4j.kernel.impl.transaction.command.CommandReaderFactory.DynamicRecordAdder; import org.neo4j.kernel.impl.transaction.command.CommandReaderFactory.DynamicRecordAdder;
import org.neo4j.kernel.impl.transaction.log.ReadableLogChannel; import org.neo4j.kernel.impl.transaction.log.ReadableLogChannel;


import static org.neo4j.helpers.Exceptions.launderedException;
import static org.neo4j.helpers.collection.IteratorUtil.first;
import static org.neo4j.kernel.impl.transaction.command.CommandReaderFactory.PROPERTY_BLOCK_DYNAMIC_RECORD_ADDER; import static org.neo4j.kernel.impl.transaction.command.CommandReaderFactory.PROPERTY_BLOCK_DYNAMIC_RECORD_ADDER;
import static org.neo4j.kernel.impl.transaction.command.CommandReaderFactory.PROPERTY_DELETED_DYNAMIC_RECORD_ADDER; import static org.neo4j.kernel.impl.transaction.command.CommandReaderFactory.PROPERTY_DELETED_DYNAMIC_RECORD_ADDER;
import static org.neo4j.kernel.impl.transaction.command.CommandReaderFactory.PROPERTY_INDEX_DYNAMIC_RECORD_ADDER; import static org.neo4j.kernel.impl.transaction.command.CommandReaderFactory.PROPERTY_INDEX_DYNAMIC_RECORD_ADDER;
Expand All @@ -52,26 +44,31 @@ protected Command read( byte commandType, ReadableLogChannel channel ) throws IO
{ {
switch ( commandType ) switch ( commandType )
{ {
case NeoCommandType.NODE_COMMAND: return visitNodeCommand( channel ); case NeoCommandType.NODE_COMMAND:
case NeoCommandType.PROP_COMMAND: return visitPropertyCommand( channel ); return visitNodeCommand( channel );
case NeoCommandType.PROP_INDEX_COMMAND: return visitPropertyKeyTokenCommand( channel ); case NeoCommandType.PROP_COMMAND:
case NeoCommandType.REL_COMMAND: return visitRelationshipCommand( channel ); return visitPropertyCommand( channel );
case NeoCommandType.REL_TYPE_COMMAND: return visitRelationshipTypeTokenCommand( channel ); case NeoCommandType.PROP_INDEX_COMMAND:
case NeoCommandType.NEOSTORE_COMMAND: return visitNeoStoreCommand( channel ); return visitPropertyKeyTokenCommand( channel );
default: throw unknownCommandType( commandType, channel ); case NeoCommandType.REL_COMMAND:
return visitRelationshipCommand( channel );
case NeoCommandType.REL_TYPE_COMMAND:
return visitRelationshipTypeTokenCommand( channel );
case NeoCommandType.NEOSTORE_COMMAND:
return visitNeoStoreCommand( channel );
default:
throw unknownCommandType( commandType, channel );
} }
} }


private Command visitNodeCommand( ReadableLogChannel channel ) throws IOException private Command visitNodeCommand( ReadableLogChannel channel ) throws IOException
{ {
long id = channel.getLong(); long id = channel.getLong();

NodeRecord record = readNodeRecord( id, channel ); NodeRecord record = readNodeRecord( id, channel );
if ( record == null ) if ( record == null )
{ {
return null; return null;
} }

Command.NodeCommand command = new Command.NodeCommand(); Command.NodeCommand command = new Command.NodeCommand();
command.init( record, record ); command.init( record, record );
return command; return command;
Expand Down Expand Up @@ -100,7 +97,6 @@ record = new RelationshipRecord( id, channel.getLong(), channel.getLong(), chann
record.setSecondPrevRel( channel.getLong() ); record.setSecondPrevRel( channel.getLong() );
record.setSecondNextRel( channel.getLong() ); record.setSecondNextRel( channel.getLong() );
record.setNextProp( channel.getLong() ); record.setNextProp( channel.getLong() );

/* /*
* Logs for version 1.9 do not contain the proper values for the following two flags. Also, * Logs for version 1.9 do not contain the proper values for the following two flags. Also,
* the defaults won't do, because the pointers for prev in the fist record will not be interpreted * the defaults won't do, because the pointers for prev in the fist record will not be interpreted
Expand All @@ -127,13 +123,11 @@ protected Command visitPropertyCommand( ReadableLogChannel channel ) throws IOEx
{ {
// ID // ID
long id = channel.getLong(); // 8 long id = channel.getLong(); // 8

PropertyRecord record = readPropertyRecord( id, channel ); PropertyRecord record = readPropertyRecord( id, channel );
if ( record == null ) if ( record == null )
{ {
return null; return null;
} }

Command.PropertyCommand command = new Command.PropertyCommand(); Command.PropertyCommand command = new Command.PropertyCommand();
command.init( record, record ); command.init( record, record );
return command; return command;
Expand All @@ -145,8 +139,7 @@ private Command visitRelationshipTypeTokenCommand( ReadableLogChannel channel )
int id = channel.getInt(); int id = channel.getInt();
byte inUseFlag = channel.get(); byte inUseFlag = channel.get();
boolean inUse = false; boolean inUse = false;
if ( (inUseFlag & Record.IN_USE.byteValue()) == if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() )
Record.IN_USE.byteValue() )
{ {
inUse = true; inUse = true;
} }
Expand Down Expand Up @@ -178,8 +171,7 @@ private Command visitPropertyKeyTokenCommand( ReadableLogChannel channel ) throw
int id = channel.getInt(); int id = channel.getInt();
byte inUseFlag = channel.get(); byte inUseFlag = channel.get();
boolean inUse = false; boolean inUse = false;
if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() )
.byteValue() )
{ {
inUse = true; inUse = true;
} }
Expand Down Expand Up @@ -211,8 +203,7 @@ private Command visitNeoStoreCommand( ReadableLogChannel channel ) throws IOExce
return command; return command;
} }


private NodeRecord readNodeRecord( long id, ReadableLogChannel channel ) private NodeRecord readNodeRecord( long id, ReadableLogChannel channel ) throws IOException
throws IOException
{ {
byte inUseFlag = channel.get(); byte inUseFlag = channel.get();
boolean inUse = false; boolean inUse = false;
Expand All @@ -234,38 +225,30 @@ record = new NodeRecord( id, false, channel.getLong(), channel.getLong() );
record = new NodeRecord( id, false, Record.NO_NEXT_RELATIONSHIP.intValue(), record = new NodeRecord( id, false, Record.NO_NEXT_RELATIONSHIP.intValue(),
Record.NO_NEXT_PROPERTY.intValue() ); Record.NO_NEXT_PROPERTY.intValue() );
} }

record.setInUse( inUse ); record.setInUse( inUse );
return record; return record;
} }



private DynamicRecord readDynamicRecord( ReadableLogChannel channel ) throws IOException private DynamicRecord readDynamicRecord( ReadableLogChannel channel ) throws IOException
{ {
// id+type+in_use(byte)+nr_of_bytes(int)+next_block(long) // id+type+in_use(byte)+nr_of_bytes(int)+next_block(long)
long id = channel.getLong(); long id = channel.getLong();
assert id >= 0 && id <= (1l << 36) - 1 : id assert id >= 0 && id <= (1l << 36) - 1 : id + " is not a valid dynamic record id";
+ " is not a valid dynamic record id";
int type = channel.getInt(); int type = channel.getInt();
byte inUseFlag = channel.get(); byte inUseFlag = channel.get();
boolean inUse = (inUseFlag & Record.IN_USE.byteValue()) != 0; boolean inUse = (inUseFlag & Record.IN_USE.byteValue()) != 0;

DynamicRecord record = new DynamicRecord( id ); DynamicRecord record = new DynamicRecord( id );
record.setInUse( inUse, type ); record.setInUse( inUse, type );
if ( inUse ) if ( inUse )
{ {
record.setStartRecord( (inUseFlag & Record.FIRST_IN_CHAIN.byteValue()) != 0 ); record.setStartRecord( (inUseFlag & Record.FIRST_IN_CHAIN.byteValue()) != 0 );
int nrOfBytes = channel.getInt(); int nrOfBytes = channel.getInt();
assert nrOfBytes >= 0 && nrOfBytes < ((1 << 24) - 1) : nrOfBytes assert nrOfBytes >= 0 && nrOfBytes < ((1 << 24) - 1) : nrOfBytes
+ + " is not valid for a number of bytes field of " + "a dynamic record";
" is not valid for a number of bytes field of " +
"a dynamic record";
long nextBlock = channel.getLong(); long nextBlock = channel.getLong();
assert (nextBlock >= 0 && nextBlock <= (1l << 36 - 1)) assert (nextBlock >= 0 && nextBlock <= (1l << 36 - 1))
|| (nextBlock == Record.NO_NEXT_BLOCK.intValue()) : nextBlock || (nextBlock == Record.NO_NEXT_BLOCK.intValue()) : nextBlock
+ + " is not valid for a next record field of " + "a dynamic record";
" is not valid for a next record field of " +
"a dynamic record";
record.setNextBlock( nextBlock ); record.setNextBlock( nextBlock );
byte data[] = new byte[nrOfBytes]; byte data[] = new byte[nrOfBytes];
channel.get( data, nrOfBytes ); channel.get( data, nrOfBytes );
Expand All @@ -292,7 +275,6 @@ private <T> int readDynamicRecords( ReadableLogChannel channel, T target, Dynami
return numberOfRecords; return numberOfRecords;
} }



private PropertyRecord readPropertyRecord( long id, ReadableLogChannel channel ) throws IOException private PropertyRecord readPropertyRecord( long id, ReadableLogChannel channel ) throws IOException
{ {
// in_use(byte)+type(int)+key_indexId(int)+prop_blockId(long)+ // in_use(byte)+type(int)+key_indexId(int)+prop_blockId(long)+
Expand Down Expand Up @@ -337,18 +319,13 @@ else if ( primitiveId != -1 )
} }
record.addPropertyBlock( block ); record.addPropertyBlock( block );
} }

if ( readDynamicRecords( channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER ) == -1 ) if ( readDynamicRecords( channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER ) == -1 )
{ {
return null; return null;
} }

if ( (inUse && !record.inUse()) || (!inUse && record.inUse()) ) if ( (inUse && !record.inUse()) || (!inUse && record.inUse()) )
{ {
throw new IllegalStateException( "Weird, inUse was read in as " throw new IllegalStateException( "Weird, inUse was read in as " + inUse + " but the record is " + record );
+ inUse
+ " but the record is "
+ record );
} }
return record; return record;
} }
Expand All @@ -357,24 +334,19 @@ private PropertyBlock readPropertyBlock( ReadableLogChannel channel ) throws IOE
{ {
PropertyBlock toReturn = new PropertyBlock(); PropertyBlock toReturn = new PropertyBlock();
byte blockSize = channel.get(); // the size is stored in bytes // 1 byte blockSize = channel.get(); // the size is stored in bytes // 1
assert blockSize > 0 && blockSize % 8 == 0 : blockSize assert blockSize > 0 && blockSize % 8 == 0 : blockSize + " is not a valid block size value";
+ " is not a valid block size value";
// Read in blocks // Read in blocks
long[] blocks = readLongs( channel, blockSize / 8 ); long[] blocks = readLongs( channel, blockSize / 8 );
assert blocks.length == blockSize / 8 : blocks.length assert blocks.length == blockSize / 8 : blocks.length
+ " longs were read in while i asked for what corresponds to " + " longs were read in while i asked for what corresponds to " + blockSize;
+ blockSize;
assert PropertyType.getPropertyType( blocks[0], false ).calculateNumberOfBlocksUsed( assert PropertyType.getPropertyType( blocks[0], false ).calculateNumberOfBlocksUsed(
blocks[0] ) == blocks.length : blocks.length blocks[0] ) == blocks.length : blocks.length + " is not a valid number of blocks for type "
+ " is not a valid number of blocks for type " + PropertyType.getPropertyType( blocks[0], false );
+ PropertyType.getPropertyType(
blocks[0], false );
/* /*
* Ok, now we may be ready to return, if there are no DynamicRecords. So * Ok, now we may be ready to return, if there are no DynamicRecords. So
* we start building the Object * we start building the Object
*/ */
toReturn.setValueBlocks( blocks ); toReturn.setValueBlocks( blocks );

/* /*
* Read in existence of DynamicRecords. Remember, this has already been * Read in existence of DynamicRecords. Remember, this has already been
* read in the buffer with the blocks, above. * read in the buffer with the blocks, above.
Expand All @@ -383,7 +355,6 @@ private PropertyBlock readPropertyBlock( ReadableLogChannel channel ) throws IOE
{ {
return null; return null;
} }

return toReturn; return toReturn;
} }


Expand All @@ -396,22 +367,4 @@ private long[] readLongs( ReadableLogChannel channel, int count ) throws IOExcep
} }
return result; return result;
} }

private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore )
{
assert first( recordsBefore ).inUse() : "Asked to deserialize schema records that were not in use.";

SchemaRule rule;
ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] );
try
{
rule = SchemaRule.Kind.deserialize( first( recordsBefore ).getId(), deserialized );
}
catch ( MalformedSchemaRuleException e )
{
// TODO This is bad. We should probably just shut down if that happens
throw launderedException( e );
}
return rule;
}
} }

0 comments on commit 804d078

Please sign in to comment.