Skip to content

Commit

Permalink
No subclassing of old RecordFormats and introduces generation
Browse files Browse the repository at this point in the history
Generation is used to prevent downgrades.
  • Loading branch information
tinwelint committed Mar 1, 2016
1 parent 233cf2f commit db19ccc
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 68 deletions.
Expand Up @@ -30,6 +30,23 @@
*/
public abstract class BaseRecordFormats implements RecordFormats
{
private final int generation;
private final Capability[] capabilities;
private final String storeVersion;

protected BaseRecordFormats( String storeVersion, int generation, Capability... capabilities )
{
this.storeVersion = storeVersion;
this.generation = generation;
this.capabilities = capabilities;
}

@Override
public String storeVersion()
{
return storeVersion;
}

@Override
public boolean equals( Object obj )
{
Expand Down Expand Up @@ -70,12 +87,24 @@ public String toString()
return "RecordFormat:" + getClass().getSimpleName() + "[" + storeVersion() + "]";
}

@Override
public int generation()
{
return generation;
}

@Override
public boolean hasStore( StoreType store )
{
return true;
}

@Override
public Capability[] capabilities()
{
return capabilities;
}

@Override
public boolean hasCapability( Capability capability )
{
Expand Down
Expand Up @@ -30,6 +30,10 @@
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord;

/**
* The record formats that a store version uses. Contains all formats for all different stores as well as
* accessors for which {@link Capability capabilities} a format has as to be able to compare between formats.
*/
public interface RecordFormats
{
abstract class Factory extends Service
Expand All @@ -44,6 +48,12 @@ public Factory( String key, String... altKeys )

String storeVersion();

/**
* @return format generation, with the intent of usage being that a store can migrate to a newer or
* same generation, but not to an older generation.
*/
int generation();

RecordFormat<NodeRecord> node();

RecordFormat<RelationshipGroupRecord> relationshipGroup();
Expand Down
Expand Up @@ -20,21 +20,27 @@
package org.neo4j.kernel.impl.store.format.lowlimit;

import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.store.format.BaseRecordFormats;
import org.neo4j.kernel.impl.store.format.Capability;
import org.neo4j.kernel.impl.store.format.RecordFormat;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord;
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord;

public class LowLimitV1_9 extends LowLimitV2_0
public class LowLimitV1_9 extends BaseRecordFormats
{
public static final RecordFormats RECORD_FORMATS = new LowLimitV1_9();
private static final String STORE_VERSION = "v0.A.0";

@Override
public String storeVersion()
public LowLimitV1_9()
{
return STORE_VERSION;
super( STORE_VERSION, 1, Capability.LUCENE_3, Capability.VERSION_TRAILERS );
}

@Override
Expand All @@ -43,27 +49,54 @@ public RecordFormat<NodeRecord> node()
return new NodeRecordFormatV1_9();
}

@Override
public RecordFormat<RelationshipRecord> relationship()
{
return new RelationshipRecordFormatV1_9();
}

@Override
public RecordFormat<DynamicRecord> dynamic()
{
return new DynamicRecordFormatV1_9();
}

@Override
public boolean hasStore( StoreType store )
public RecordFormat<RelationshipGroupRecord> relationshipGroup()
{
boolean excluded =
!super.hasStore( store ) ||
store == StoreType.LABEL_TOKEN ||
store == StoreType.LABEL_TOKEN_NAME ||
store == StoreType.NODE_LABEL ||
store == StoreType.SCHEMA;
return excluded;
return new NoRecordFormat<>();
}

@Override
public Capability[] capabilities()
public RecordFormat<PropertyRecord> property()
{
return new PropertyRecordFormat();
}

@Override
public RecordFormat<LabelTokenRecord> labelToken()
{
return new LabelTokenRecordFormat();
}

@Override
public RecordFormat<PropertyKeyTokenRecord> propertyKeyToken()
{
return new PropertyKeyTokenRecordFormat();
}

@Override
public RecordFormat<RelationshipTypeTokenRecord> relationshipTypeToken()
{
return new RelationshipTypeTokenRecordFormat();
}

@Override
public boolean hasStore( StoreType store )
{
return new Capability[] { Capability.LUCENE_3, Capability.VERSION_TRAILERS };
return store != StoreType.LABEL_TOKEN &&
store != StoreType.LABEL_TOKEN_NAME &&
store != StoreType.NODE_LABEL &&
store != StoreType.SCHEMA;
}
}
Expand Up @@ -20,22 +20,27 @@
package org.neo4j.kernel.impl.store.format.lowlimit;

import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.store.format.BaseRecordFormats;
import org.neo4j.kernel.impl.store.format.Capability;
import org.neo4j.kernel.impl.store.format.RecordFormat;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord;
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord;

public class LowLimitV2_0 extends LowLimitV2_1
public class LowLimitV2_0 extends BaseRecordFormats
{
public static final RecordFormats RECORD_FORMATS = new LowLimitV2_0();
public static final String STORE_VERSION = "v0.A.1";

@Override
public String storeVersion()
public LowLimitV2_0()
{
return STORE_VERSION;
super( STORE_VERSION, 2, Capability.SCHEMA, Capability.LUCENE_3, Capability.VERSION_TRAILERS );
}

@Override
Expand All @@ -47,7 +52,8 @@ public RecordFormat<NodeRecord> node()
@Override
public RecordFormat<RelationshipRecord> relationship()
{
return new RelationshipRecordFormatV2_0();
// Yes, uses the same relationship record format as 1.9
return new RelationshipRecordFormatV1_9();
}

@Override
Expand All @@ -57,17 +63,38 @@ public RecordFormat<RelationshipGroupRecord> relationshipGroup()
}

@Override
public boolean hasStore( StoreType store )
public RecordFormat<PropertyRecord> property()
{
return new PropertyRecordFormat();
}

@Override
public RecordFormat<LabelTokenRecord> labelToken()
{
return new LabelTokenRecordFormat();
}

@Override
public RecordFormat<PropertyKeyTokenRecord> propertyKeyToken()
{
boolean excluded =
!super.hasStore( store ) ||
store == StoreType.RELATIONSHIP_GROUP;
return !excluded;
return new PropertyKeyTokenRecordFormat();
}

@Override
public Capability[] capabilities()
public RecordFormat<RelationshipTypeTokenRecord> relationshipTypeToken()
{
return new RelationshipTypeTokenRecordFormat();
}

@Override
public RecordFormat<DynamicRecord> dynamic()
{
return new DynamicRecordFormat();
}

@Override
public boolean hasStore( StoreType store )
{
return new Capability[] { Capability.SCHEMA, Capability.LUCENE_3, Capability.VERSION_TRAILERS };
return store != StoreType.RELATIONSHIP_GROUP;
}
}
Expand Up @@ -19,24 +19,75 @@
*/
package org.neo4j.kernel.impl.store.format.lowlimit;

import org.neo4j.kernel.impl.store.format.BaseRecordFormats;
import org.neo4j.kernel.impl.store.format.Capability;
import org.neo4j.kernel.impl.store.format.RecordFormat;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord;
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord;

public class LowLimitV2_1 extends LowLimitV2_2
public class LowLimitV2_1 extends BaseRecordFormats
{
public static final RecordFormats RECORD_FORMATS = new LowLimitV2_1();
public static final String STORE_VERSION = "v0.A.3";

public LowLimitV2_1()
{
super( STORE_VERSION, 3, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3,
Capability.VERSION_TRAILERS );
}

@Override
public RecordFormat<NodeRecord> node()
{
return new NodeRecordFormat();
}

@Override
public RecordFormat<RelationshipGroupRecord> relationshipGroup()
{
return new RelationshipGroupRecordFormat();
}

@Override
public RecordFormat<RelationshipRecord> relationship()
{
return new RelationshipRecordFormat();
}

@Override
public RecordFormat<PropertyRecord> property()
{
return new PropertyRecordFormat();
}

@Override
public RecordFormat<LabelTokenRecord> labelToken()
{
return new LabelTokenRecordFormat();
}

@Override
public RecordFormat<PropertyKeyTokenRecord> propertyKeyToken()
{
return new PropertyKeyTokenRecordFormat();
}

@Override
public String storeVersion()
public RecordFormat<RelationshipTypeTokenRecord> relationshipTypeToken()
{
return STORE_VERSION;
return new RelationshipTypeTokenRecordFormat();
}

@Override
public Capability[] capabilities()
public RecordFormat<DynamicRecord> dynamic()
{
return new Capability[] { Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3,
Capability.VERSION_TRAILERS };
return new DynamicRecordFormat();
}
}

0 comments on commit db19ccc

Please sign in to comment.