Skip to content

Commit

Permalink
Prepared Schema Store for new format
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Feb 9, 2017
1 parent d9b57fc commit 711cd32
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 197 deletions.
Expand Up @@ -90,7 +90,6 @@
import org.neo4j.kernel.impl.store.SchemaStore;
import org.neo4j.kernel.impl.store.StoreAccess;
import org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator;
import org.neo4j.kernel.impl.store.record.AbstractSchemaRule;
import org.neo4j.kernel.impl.store.record.ConstraintRule;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.IndexRule;
Expand Down Expand Up @@ -1066,7 +1065,7 @@ public static Collection<DynamicRecord> serializeRule( SchemaRule rule, DynamicR
public static Collection<DynamicRecord> serializeRule( SchemaRule rule, Collection<DynamicRecord> records )
{
RecordSerializer serializer = new RecordSerializer();
serializer.append( (AbstractSchemaRule)rule );
serializer.append( rule );

byte[] data = serializer.serialize();
ReusableRecordsAllocator dynamicRecordAllocator = new ReusableRecordsAllocator( data.length, records );
Expand Down
Expand Up @@ -37,7 +37,7 @@ public enum Type { GENERAL, UNIQUE }

public interface Supplier
{
NewIndexDescriptor getNewIndexDescriptor();
NewIndexDescriptor getIndexDescriptor();
}

private final LabelSchemaDescriptor schema;
Expand Down Expand Up @@ -81,7 +81,7 @@ public String userDescription( TokenNameLookup tokenNameLookup )
*/
public boolean isSame( Supplier supplier )
{
return this.equals( supplier.getNewIndexDescriptor() );
return this.equals( supplier.getIndexDescriptor() );
}

@Override
Expand Down
Expand Up @@ -34,7 +34,7 @@
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.store.id.IdType;
import org.neo4j.kernel.impl.store.record.AbstractSchemaRule;
import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.RecordSerializer;
import org.neo4j.logging.LogProvider;
Expand Down Expand Up @@ -71,7 +71,7 @@ public <FAILURE extends Exception> void accept( Processor<FAILURE> processor, Dy
public List<DynamicRecord> allocateFrom( SchemaRule rule )
{
RecordSerializer serializer = new RecordSerializer();
serializer = serializer.append( (AbstractSchemaRule)rule );
serializer = serializer.append( rule );
List<DynamicRecord> records = new ArrayList<>();
DynamicRecord record = getRecord( rule.getId(), nextRecord(), CHECK );
ReusableRecordsAllocator recordAllocator = new ReusableRecordsAllocator( this.getRecordSize(), record );
Expand All @@ -94,6 +94,6 @@ static SchemaRule readSchemaRule( long id, Collection<DynamicRecord> records, by
throws MalformedSchemaRuleException
{
ByteBuffer scratchBuffer = concatData( records, buffer );
return AbstractSchemaRule.deserialize( id, scratchBuffer );
return SchemaRuleDeserializer2_0to3_1.deserialize( id, scratchBuffer );
}
}

This file was deleted.

Expand Up @@ -29,37 +29,24 @@
import org.neo4j.kernel.api.schema_new.SchemaProcessor;
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor;
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory;
import org.neo4j.storageengine.api.schema.SchemaRule;

import static org.neo4j.kernel.api.schema_new.SchemaUtil.noopTokenNameLookup;
import static org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt;
import static org.neo4j.storageengine.api.schema.SchemaRule.Kind.NODE_PROPERTY_EXISTENCE_CONSTRAINT;
import static org.neo4j.storageengine.api.schema.SchemaRule.Kind.RELATIONSHIP_PROPERTY_EXISTENCE_CONSTRAINT;
import static org.neo4j.storageengine.api.schema.SchemaRule.Kind.UNIQUENESS_CONSTRAINT;

public class ConstraintRule extends AbstractSchemaRule implements ConstraintDescriptor.Supplier
public class ConstraintRule implements SchemaRule, ConstraintDescriptor.Supplier
{
private final long id;
private final Optional<Long> ownedIndexRule;
private final ConstraintDescriptor descriptor;

public static ConstraintRule readUniquenessConstraintRule( long id, int labelId, ByteBuffer buffer )
{
return new ConstraintRule( id,
ConstraintDescriptorFactory.uniqueForLabel( labelId, readPropertyKeys( buffer ) ),
readOwnedIndexRule( buffer ) );
}

public static ConstraintRule readNodePropertyExistenceConstraintRule( long id, int labelId, ByteBuffer buffer )
{
return new ConstraintRule( id,
ConstraintDescriptorFactory.existsForLabel( labelId, readPropertyKey( buffer ) ),
Optional.empty() );
}

public static ConstraintRule readRelPropertyExistenceConstraintRule( long id, int relTypeId, ByteBuffer buffer )
@Override
public final long getId()
{
return new ConstraintRule( id,
ConstraintDescriptorFactory.existsForRelType( relTypeId, readPropertyKey( buffer ) ),
Optional.empty() );
return this.id;
}

public static ConstraintRule constraintRule(
Expand All @@ -74,29 +61,9 @@ public static ConstraintRule constraintRule(
return new ConstraintRule( id, descriptor, Optional.of( ownedIndexRule ) );
}

private static int readPropertyKey( ByteBuffer buffer )
{
return buffer.getInt();
}

private static int[] readPropertyKeys( ByteBuffer buffer )
{
int[] keys = new int[buffer.get()];
for ( int i = 0; i < keys.length; i++ )
{
keys[i] = safeCastLongToInt( buffer.getLong() );
}
return keys;
}

private static Optional<Long> readOwnedIndexRule( ByteBuffer buffer )
{
return Optional.of( buffer.getLong() );
}

private ConstraintRule( long id, ConstraintDescriptor descriptor, Optional<Long> ownedIndexRule )
ConstraintRule( long id, ConstraintDescriptor descriptor, Optional<Long> ownedIndexRule )
{
super( id );
this.id = id;
this.descriptor = descriptor;
this.ownedIndexRule = ownedIndexRule;
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.neo4j.kernel.api.schema_new.SchemaComputer;
import org.neo4j.kernel.api.schema_new.SchemaProcessor;
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor;
import org.neo4j.storageengine.api.schema.SchemaRule;
import org.neo4j.string.UTF8;

import static org.neo4j.kernel.api.schema_new.SchemaUtil.noopTokenNameLookup;
Expand All @@ -41,9 +42,11 @@
/**
* A {@link Label} can have zero or more index rules which will have data specified in the rules indexed.
*/
public class IndexRule extends AbstractSchemaRule
public class IndexRule implements SchemaRule, NewIndexDescriptor.Supplier
{
private static final long NO_OWNING_CONSTRAINT = -1;
static final long NO_OWNING_CONSTRAINT = -1;

private final long id;
private final SchemaIndexProvider.Descriptor providerDescriptor;
private final NewIndexDescriptor descriptor;
/**
Expand All @@ -52,16 +55,6 @@ public class IndexRule extends AbstractSchemaRule
*/
private final long owningConstraint;

static IndexRule readIndexRule( long id, boolean constraintIndex, int label, ByteBuffer serialized )
{
SchemaIndexProvider.Descriptor providerDescriptor = readProviderDescriptor( serialized );
int[] propertyKeyIds = readPropertyKeys( serialized );
NewIndexDescriptor descriptor = constraintIndex ?
uniqueForLabel( label, propertyKeyIds ) : forLabel( label, propertyKeyIds );
long owningConstraint = constraintIndex ? readOwningConstraint( serialized ) : NO_OWNING_CONSTRAINT;
return new IndexRule( id, providerDescriptor, descriptor, owningConstraint );
}

public static IndexRule indexRule( long id, NewIndexDescriptor descriptor,
SchemaIndexProvider.Descriptor providerDescriptor )
{
Expand All @@ -75,37 +68,10 @@ public static IndexRule constraintIndexRule( long id, NewIndexDescriptor descrip
return new IndexRule( id, providerDescriptor, descriptor, owningConstraint );
}

private static SchemaIndexProvider.Descriptor readProviderDescriptor( ByteBuffer serialized )
{
String providerKey = getDecodedStringFrom( serialized );
String providerVersion = getDecodedStringFrom( serialized );
return new SchemaIndexProvider.Descriptor( providerKey, providerVersion );
}

private static int[] readPropertyKeys( ByteBuffer serialized )
{
// Currently only one key is supported although the data format supports multiple
int count = serialized.getShort();
assert count >= 1;

// Changed from being a long to an int 2013-09-10, but keeps reading a long to not change the store format.
int[] props = new int[count];
for ( int i = 0; i < count; i++ )
{
props[i] = safeCastLongToInt( serialized.getLong() );
}
return props;
}

private static long readOwningConstraint( ByteBuffer serialized )
{
return serialized.getLong();
}

private IndexRule( long id, SchemaIndexProvider.Descriptor providerDescriptor,
IndexRule( long id, SchemaIndexProvider.Descriptor providerDescriptor,
NewIndexDescriptor descriptor, long owningConstraint )
{
super( id );
this.id = id;
if ( providerDescriptor == null )
{
throw new IllegalArgumentException( "null provider descriptor prohibited" );
Expand Down Expand Up @@ -149,6 +115,12 @@ public IndexRule withOwningConstraint( long constraintId )
return constraintIndexRule( id, descriptor, providerDescriptor, constraintId );
}

@Override
public long getId()
{
return id;
}

@Override
public int length()
{
Expand Down

0 comments on commit 711cd32

Please sign in to comment.