Skip to content

Commit

Permalink
Fix generation for record formats
Browse files Browse the repository at this point in the history
Commit makes sure that RecordFormats#generation() returns unique increasing
value for all existing RecordFormats implementations.
It also changes StoreVersions to be an enum so generations can be tested
easier.
  • Loading branch information
lutovich committed May 30, 2016
1 parent 28ba247 commit 0be650f
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 68 deletions.
Expand Up @@ -24,39 +24,61 @@
/**
* All known store formats are collected here.
*/
public class StoreVersions
public enum StoreVersion
{
// Community formats
public static final String STANDARD_V2_0 = "v0.A.1";
public static final String STANDARD_V2_1 = "v0.A.3";
public static final String STANDARD_V2_2 = "v0.A.5";
public static final String STANDARD_V2_3 = "v0.A.6";
public static final String STANDARD_V3_0 = "v0.A.7";
STANDARD_V2_0( "v0.A.1", true ),
STANDARD_V2_1( "v0.A.3", true ),
STANDARD_V2_2( "v0.A.5", true ),
STANDARD_V2_3( "v0.A.6", true ),
STANDARD_V3_0( "v0.A.7", true ),

// Enterprise formats
public static final String HIGH_LIMIT_V3_0 = "vE.H.0";
HIGH_LIMIT_V3_0( "vE.H.0", false );

private static final StoreVersion[] ALL_STORE_VERSIONS = values();

private final String string;
private final boolean isCommunity;

StoreVersion( String string, boolean isCommunity )
{
this.string = string;
this.isCommunity = isCommunity;
}

public String string()
{
return string;
}

/**
*
* @param storeVersion string
* @param version string
* @return true if the store version is a known community format, false otherwise
*/
public static boolean isCommunityStoreVersion( @Nonnull String storeVersion )
public static boolean isCommunityStoreVersion( @Nonnull String version )
{
return STANDARD_V2_0.equals( storeVersion ) ||
STANDARD_V2_1.equals( storeVersion ) ||
STANDARD_V2_2.equals( storeVersion ) ||
STANDARD_V2_3.equals( storeVersion ) ||
STANDARD_V3_0.equals( storeVersion );
for ( StoreVersion storeVersion : ALL_STORE_VERSIONS )
{
if ( storeVersion.string.equals( version ) && storeVersion.isCommunity )
{
return true;
}
}
return false;
}

/**
*
* @param storeVersion string
* @param version string
* @return true if the store version is a known enterprise format, false otherwise
*/
public static boolean isEnterpriseStoreVersion( @Nonnull String storeVersion )
public static boolean isEnterpriseStoreVersion( @Nonnull String version )
{
return HIGH_LIMIT_V3_0.equals( storeVersion );
for ( StoreVersion storeVersion : ALL_STORE_VERSIONS )
{
if ( storeVersion.string.equals( version ) && !storeVersion.isCommunity )
{
return true;
}
}
return false;
}
}
Expand Up @@ -23,7 +23,7 @@
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.format.StoreVersions;
import org.neo4j.kernel.impl.store.format.StoreVersion;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
Expand All @@ -35,8 +35,8 @@

public class StandardV2_0 extends BaseRecordFormats
{
public static final String STORE_VERSION = StoreVersion.STANDARD_V2_0.string();
public static final RecordFormats RECORD_FORMATS = new StandardV2_0();
public static final String STORE_VERSION = StoreVersions.STANDARD_V2_0;

public StandardV2_0()
{
Expand Down
Expand Up @@ -23,7 +23,7 @@
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.format.StoreVersions;
import org.neo4j.kernel.impl.store.format.StoreVersion;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
Expand All @@ -35,8 +35,8 @@

public class StandardV2_1 extends BaseRecordFormats
{
public static final String STORE_VERSION = StoreVersion.STANDARD_V2_1.string();
public static final RecordFormats RECORD_FORMATS = new StandardV2_1();
public static final String STORE_VERSION = StoreVersions.STANDARD_V2_1;

public StandardV2_1()
{
Expand Down
Expand Up @@ -23,7 +23,7 @@
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.format.StoreVersions;
import org.neo4j.kernel.impl.store.format.StoreVersion;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
Expand All @@ -35,12 +35,12 @@

public class StandardV2_2 extends BaseRecordFormats
{
public static final String STORE_VERSION = StoreVersion.STANDARD_V2_2.string();
public static final RecordFormats RECORD_FORMATS = new StandardV2_2();
public static final String STORE_VERSION = StoreVersions.STANDARD_V2_2;

public StandardV2_2()
{
super( STORE_VERSION, 5, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3,
super( STORE_VERSION, 4, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3,
Capability.VERSION_TRAILERS );
}

Expand Down
Expand Up @@ -23,7 +23,7 @@
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.format.StoreVersions;
import org.neo4j.kernel.impl.store.format.StoreVersion;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
Expand All @@ -35,12 +35,12 @@

public class StandardV2_3 extends BaseRecordFormats
{
public static final String STORE_VERSION = StoreVersion.STANDARD_V2_3.string();
public static final RecordFormats RECORD_FORMATS = new StandardV2_3();
public static final String STORE_VERSION = StoreVersions.STANDARD_V2_3;

public StandardV2_3()
{
super( STORE_VERSION, 4, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3 );
super( STORE_VERSION, 5, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3 );
}

@Override
Expand Down
Expand Up @@ -23,7 +23,7 @@
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.format.StoreVersions;
import org.neo4j.kernel.impl.store.format.StoreVersion;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
Expand All @@ -35,13 +35,13 @@

public class StandardV3_0 extends BaseRecordFormats
{
public static final String STORE_VERSION = StoreVersion.STANDARD_V3_0.string();
public static final RecordFormats RECORD_FORMATS = new StandardV3_0();
public static final String STORE_VERSION = StoreVersions.STANDARD_V3_0;
public static final String NAME = "standard";

public StandardV3_0()
{
super( STORE_VERSION, 5, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_5 );
super( STORE_VERSION, 6, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_5 );
}

@Override
Expand Down
Expand Up @@ -27,10 +27,10 @@
import org.neo4j.kernel.impl.store.format.Capability;
import org.neo4j.kernel.impl.store.format.RecordFormatSelector;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.StoreVersions;
import org.neo4j.kernel.impl.store.format.StoreVersion;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader.DatabaseNotCleanlyShutDownException;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreVersionException;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreFormatException;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreVersionException;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradeMissingStoreFilesException;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradingStoreVersionNotFoundException;
import org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result;
Expand Down Expand Up @@ -90,8 +90,8 @@ public RecordFormats checkUpgradeable( File storeDirectory )

// If we are trying to open an enterprise store when configured to use community format, then inform the user
// of the config setting to change since downgrades aren't possible but the store can still be opened.
if ( StoreVersions.isEnterpriseStoreVersion( result.actualVersion ) &&
StoreVersions.isCommunityStoreVersion( format.storeVersion() ) )
if ( StoreVersion.isEnterpriseStoreVersion( result.actualVersion ) &&
StoreVersion.isCommunityStoreVersion( format.storeVersion() ) )
{
throw new StoreUpgrader.UnexpectedUpgradingStoreFormatException();
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.function.BiConsumer;

Expand All @@ -39,7 +40,6 @@
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.api.store.StorePropertyCursor;
import org.neo4j.kernel.impl.locking.LockService;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.store.CountsComputer;
import org.neo4j.kernel.impl.store.MetaDataStore;
Expand Down Expand Up @@ -597,10 +597,9 @@ public void moveMigratedFiles( File migrationDir, File storeDir, String versionT
public void rebuildCounts( File storeDir, String versionToMigrateFrom, String versionToMigrateTo ) throws
IOException
{
switch ( versionToMigrateFrom )
if ( Objects.equals( versionToMigrateFrom, StandardV2_1.STORE_VERSION ) ||
Objects.equals( versionToMigrateFrom, StandardV2_2.STORE_VERSION ) )
{
case StandardV2_1.STORE_VERSION:
case StandardV2_2.STORE_VERSION:
// create counters from scratch
Iterable<StoreFile> countsStoreFiles =
Iterables.iterable( StoreFile.COUNTS_STORE_LEFT, StoreFile.COUNTS_STORE_RIGHT );
Expand All @@ -609,9 +608,6 @@ public void rebuildCounts( File storeDir, String versionToMigrateFrom, String ve
File neoStore = new File( storeDir, DEFAULT_NAME );
long lastTxId = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_ID );
rebuildCountsFromScratch( storeDir, lastTxId, pageCache, selectForVersion( versionToMigrateTo ) );
break;
default:
// OK, don't rebuild for other versions
}
}

Expand Down
Expand Up @@ -26,31 +26,36 @@
import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith( Parameterized.class )
public class StoreVersionsTest
public class StoreVersionTest
{
@Parameterized.Parameter( 0 )
public String version;

@Parameterized.Parameters( name = "{0}" )
public static Collection<String> versions()
{
return Arrays.asList( StoreVersions.STANDARD_V2_0, StoreVersions.STANDARD_V2_1, StoreVersions.STANDARD_V2_2,
StoreVersions.STANDARD_V2_3, StoreVersions.STANDARD_V3_0 );
return Arrays.asList(
StoreVersion.STANDARD_V2_0.string(),
StoreVersion.STANDARD_V2_1.string(),
StoreVersion.STANDARD_V2_2.string(),
StoreVersion.STANDARD_V2_3.string(),
StoreVersion.STANDARD_V3_0.string() );
}

@Test
public void shouldBeCommunityFormat()
{
assertTrue( "Expected community format", StoreVersions.isCommunityStoreVersion( version ) );
assertTrue( "Expected community format", StoreVersion.isCommunityStoreVersion( version ) );
}

@Test
public void shouldNotBeLabeledEnterpriseFormat()
{
assertFalse( "Expected non-enterprise format", StoreVersions.isEnterpriseStoreVersion( version ) );
assertFalse( "Expected non-enterprise format", StoreVersion.isEnterpriseStoreVersion( version ) );
}

@RunWith( Parameterized.class )
Expand All @@ -62,19 +67,19 @@ public static class EnterpriseVersions
@Parameterized.Parameters( name = "{0}" )
public static Collection<String> versions()
{
return Arrays.asList( StoreVersions.HIGH_LIMIT_V3_0 );
return Arrays.asList( StoreVersion.HIGH_LIMIT_V3_0.string() );
}

@Test
public void shouldBeCommunityFormat()
{
assertFalse( "Expected non-community format", StoreVersions.isCommunityStoreVersion( version ) );
assertFalse( "Expected non-community format", StoreVersion.isCommunityStoreVersion( version ) );
}

@Test
public void shouldNotBeLabeledEnterpriseFormat()
{
assertTrue( "Expected enterprise format", StoreVersions.isEnterpriseStoreVersion( version ) );
assertTrue( "Expected enterprise format", StoreVersion.isEnterpriseStoreVersion( version ) );
}
}
}
Expand Up @@ -148,17 +148,24 @@ public static void prepareSampleLegacyDatabase( String version, FileSystemAbstra

public static File findFormatStoreDirectoryForVersion( String version, File targetDir ) throws IOException
{
switch ( version )
if ( version.equals( StandardV2_3.STORE_VERSION ) )
{
case StandardV2_3.STORE_VERSION:
return find23FormatStoreDirectory( targetDir );
case StandardV2_2.STORE_VERSION:
}
else if ( version.equals( StandardV2_2.STORE_VERSION ) )
{
return find22FormatStoreDirectory( targetDir );
case StandardV2_1.STORE_VERSION:
}
else if ( version.equals( StandardV2_1.STORE_VERSION ) )
{
return find21FormatStoreDirectory( targetDir );
case StandardV2_0.STORE_VERSION:
}
else if ( version.equals( StandardV2_0.STORE_VERSION ) )
{
return find20FormatStoreDirectory( targetDir );
default:
}
else
{
throw new IllegalArgumentException( "Unknown version" );
}
}
Expand Down
Expand Up @@ -37,7 +37,7 @@
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.StoreVersions;
import org.neo4j.kernel.impl.store.format.StoreVersion;
import org.neo4j.kernel.impl.store.format.standard.StandardV2_0;
import org.neo4j.kernel.impl.store.format.standard.StandardV2_1;
import org.neo4j.kernel.impl.store.format.standard.StandardV2_2;
Expand Down Expand Up @@ -211,7 +211,7 @@ public static class UnsupportedVersions
@Parameterized.Parameters( name = "{0}" )
public static Collection<String> versions()
{
return Arrays.asList( "v0.9.5", "v0.A.4", StoreVersions.HIGH_LIMIT_V3_0 );
return Arrays.asList( "v0.9.5", "v0.A.4", StoreVersion.HIGH_LIMIT_V3_0.string() );
}

@Rule
Expand Down Expand Up @@ -260,14 +260,14 @@ public void shouldCommunicateWhatCausesInabilityToUpgrade()
catch ( StoreUpgrader.UnexpectedUpgradingStoreVersionException e )
{
// then
assertFalse( StoreVersions.isEnterpriseStoreVersion( version ) );
assertFalse( StoreVersion.isEnterpriseStoreVersion( version ) );
File expectedFile = new File( workingDirectory, neostoreFilename ).getAbsoluteFile();
assertEquals( String.format( MESSAGE, expectedFile, version ), e.getMessage() );
}
catch ( StoreUpgrader.UnexpectedUpgradingStoreFormatException e )
{
// then
assertTrue( StoreVersions.isEnterpriseStoreVersion( version ) );
assertTrue( StoreVersion.isEnterpriseStoreVersion( version ) );
assertEquals( String.format( StoreUpgrader.UnexpectedUpgradingStoreFormatException.MESSAGE,
GraphDatabaseSettings.record_format.name() ), e.getMessage() );
}
Expand Down

0 comments on commit 0be650f

Please sign in to comment.