Skip to content

Commit

Permalink
Force count store rebuild during store migration
Browse files Browse the repository at this point in the history
Count store version was incremented but there was no migration added
and as result first DB after start will fail to open old count stores and
will rebuild it.
That way of doing count store migration is incorrect and produce
unexpected exceptions that confuse users.
  • Loading branch information
MishaDemianenko committed May 16, 2017
1 parent 4da5424 commit 66c1408
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Expand Up @@ -67,12 +67,15 @@
import org.neo4j.kernel.impl.store.format.CapabilityType;
import org.neo4j.kernel.impl.store.format.FormatFamily;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.StoreVersion;
import org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat;
import org.neo4j.kernel.impl.store.format.standard.NodeRecordFormat;
import org.neo4j.kernel.impl.store.format.standard.RelationshipRecordFormat;
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;
import org.neo4j.kernel.impl.store.format.standard.StandardV2_3;
import org.neo4j.kernel.impl.store.format.standard.StandardV3_0;
import org.neo4j.kernel.impl.store.id.ReadOnlyIdGeneratorFactory;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PrimitiveRecord;
Expand Down Expand Up @@ -766,8 +769,7 @@ public void moveMigratedFiles( File migrationDir, File storeDir, String versionT
public void rebuildCounts( File storeDir, String versionToMigrateFrom, String versionToMigrateTo ) throws
IOException
{
if ( StandardV2_1.STORE_VERSION.equals( versionToMigrateFrom ) ||
StandardV2_2.STORE_VERSION.equals( versionToMigrateFrom ) )
if ( countStoreRebuildRequired( versionToMigrateFrom ) )
{
// create counters from scratch
Iterable<StoreFile> countsStoreFiles =
Expand All @@ -780,6 +782,17 @@ public void rebuildCounts( File storeDir, String versionToMigrateFrom, String ve
}
}

boolean countStoreRebuildRequired( String versionToMigrateFrom )
{
return StandardV2_1.STORE_VERSION.equals( versionToMigrateFrom ) ||
StandardV2_2.STORE_VERSION.equals( versionToMigrateFrom ) ||
StandardV2_3.STORE_VERSION.equals( versionToMigrateFrom ) ||
StandardV3_0.STORE_VERSION.equals( versionToMigrateFrom ) ||
StoreVersion.HIGH_LIMIT_V3_0_0.versionString().equals( versionToMigrateFrom ) ||
StoreVersion.HIGH_LIMIT_V3_0_6.versionString().equals( versionToMigrateFrom ) ||
StoreVersion.HIGH_LIMIT_V3_1_0.versionString().equals( versionToMigrateFrom );
}

private void updateOrAddNeoStoreFieldsAsPartOfMigration( File migrationDir, File storeDir,
String versionToMigrateTo, LogPosition lastClosedTxLogPosition ) throws IOException
{
Expand Down
Expand Up @@ -23,13 +23,16 @@
import org.junit.Test;

import java.io.File;
import java.io.IOException;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier;
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.logging.NullLogService;
import org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory;
import org.neo4j.kernel.impl.store.format.StoreVersion;
Expand All @@ -41,6 +44,7 @@
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
Expand Down Expand Up @@ -92,4 +96,36 @@ public void shouldNotDoActualStoreMigrationBetween3_0_5_and_next() throws Except
verifyNoMoreInteractions( monitor );
}
}

@Test
public void detectObsoleteCountStoresToRebuildDuringMigration() throws IOException
{
TestStoreMigrator storeMigrator = new TestStoreMigrator( new DefaultFileSystemAbstraction(),
mock( PageCache.class ), Config.empty(), NullLogService.getInstance(), mock( SchemaIndexProvider.class ) );
assertTrue( storeMigrator.countStoreRebuildRequired( StoreVersion.STANDARD_V2_1.versionString() ) );
assertTrue( storeMigrator.countStoreRebuildRequired( StoreVersion.STANDARD_V2_2.versionString() ) );
assertTrue( storeMigrator.countStoreRebuildRequired( StoreVersion.STANDARD_V2_3.versionString() ) );
assertTrue( storeMigrator.countStoreRebuildRequired( StoreVersion.STANDARD_V3_0.versionString() ) );
assertFalse( storeMigrator.countStoreRebuildRequired( StoreVersion.STANDARD_V3_2.versionString() ) );
assertTrue( storeMigrator.countStoreRebuildRequired( StoreVersion.HIGH_LIMIT_V3_0_0.versionString() ) );
assertTrue( storeMigrator.countStoreRebuildRequired( StoreVersion.HIGH_LIMIT_V3_0_6.versionString() ) );
assertTrue( storeMigrator.countStoreRebuildRequired( StoreVersion.HIGH_LIMIT_V3_1_0.versionString() ) );
assertFalse( storeMigrator.countStoreRebuildRequired( StoreVersion.HIGH_LIMIT_V3_2_0.versionString() ) );
}

private class TestStoreMigrator extends StoreMigrator
{

TestStoreMigrator( FileSystemAbstraction fileSystem, PageCache pageCache, Config config, LogService logService,
SchemaIndexProvider schemaIndexProvider )
{
super( fileSystem, pageCache, config, logService, schemaIndexProvider );
}

@Override
public boolean countStoreRebuildRequired( String versionToMigrateFrom )
{
return super.countStoreRebuildRequired( versionToMigrateFrom );
}
}
}

0 comments on commit 66c1408

Please sign in to comment.