Skip to content

Commit

Permalink
Propagate error description for upgrade not allowed exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
klaren committed Sep 7, 2017
1 parent 4db6eda commit 1e849a0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
Expand Up @@ -24,7 +24,6 @@
import java.nio.ByteBuffer;
import java.util.Random;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.fs.StoreChannel;
import org.neo4j.kernel.impl.store.NotCurrentStoreVersionException;
Expand Down Expand Up @@ -135,10 +134,7 @@ private Long[] readRecordsWithNullDefaults( StoreChannel fileChannel, int count,
int wholeRecordsRead = bytesRead / RECORD_SIZE;
if ( wholeRecordsRead < RECORD_COUNT && !allowUpgrade )
{
throw new UpgradeNotAllowedByConfigurationException(
"Index version (managed by " + file + ") has changed " + "and cannot be upgraded unless " +
GraphDatabaseSettings.allow_upgrade.name() +
"=true is supplied in the configuration" );
throw new UpgradeNotAllowedByConfigurationException( "Index version (managed by " + file + ") has changed and needs to be upgraded" );
}

buf.flip();
Expand Down
Expand Up @@ -25,14 +25,19 @@ public class UpgradeNotAllowedByConfigurationException extends UpgradeNotAllowed
{
public UpgradeNotAllowedByConfigurationException( String msg )
{
super( msg );
super( String.format( "%s Detailed description: %s", baseMessage() , msg) );
}

public UpgradeNotAllowedByConfigurationException()
{
super( String.format(
"Failed to start Neo4j with an older data store version. "
+ "To enable automatic upgrade, please set configuration parameter \"%s=true\"",
GraphDatabaseSettings.allow_upgrade.name() ) );
super( baseMessage() );
}

private static String baseMessage()
{
return String.format(
"Neo4j cannot be started, because the database files require upgrading and upgrades are " +
"disabled in configuration. Please set '%s' to 'true' in your configuration file and try again.",
GraphDatabaseSettings.allow_upgrade.name() );
}
}
Expand Up @@ -47,11 +47,8 @@ public static void check( LogTailScanner tailScanner, Config config ) throws Upg
LogEntryVersion latestLogEntryVersion = tailScanner.getTailInformation().latestLogEntryVersion;
if ( latestLogEntryVersion != null && LogEntryVersion.moreRecentVersionExists( latestLogEntryVersion ) )
{
String message = String.format(
"The version your upgrading to is using a new transaction log format. This is a non-reversible " +
"upgrade and you wont be able to downgrade after starting. To allow upgrade, please set " +
"configuration parameter \"%s=true\"",
GraphDatabaseSettings.allow_upgrade.name() );
String message = "The version your upgrading to is using a new transaction log format. This is a " +
"non-reversible upgrade and you wont be able to downgrade after starting";

throw new UpgradeNotAllowedByConfigurationException( message );
}
Expand Down
5 changes: 3 additions & 2 deletions community/neo4j/src/test/java/db/DatabaseStartupTest.java
Expand Up @@ -81,8 +81,9 @@ public void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() th
// then
assertTrue( ex.getCause() instanceof LifecycleException );
assertTrue( ex.getCause().getCause() instanceof UpgradeNotAllowedByConfigurationException );
assertEquals( "Failed to start Neo4j with an older data store version. To enable automatic upgrade, " +
"please set configuration parameter \"" + allow_upgrade.name() + "=true\"",
assertEquals( "Neo4j cannot be started, because the database files require upgrading and upgrades " +
"are disabled in configuration. Please set '" + allow_upgrade.name() + "' to 'true' in your " +
"configuration file and try again.",
ex.getCause().getCause().getMessage());
}
}
Expand Down
Expand Up @@ -24,8 +24,6 @@
import org.neo4j.logging.Log;
import org.neo4j.server.ServerStartupException;

import static org.neo4j.graphdb.factory.GraphDatabaseSettings.allow_upgrade;

public class UpgradeDisallowedStartupException extends ServerStartupException
{
public UpgradeDisallowedStartupException( UpgradeNotAllowedException cause )
Expand All @@ -36,11 +34,10 @@ public UpgradeDisallowedStartupException( UpgradeNotAllowedException cause )
@Override
public void describeTo( Log log )
{
if ( getCause() instanceof UpgradeNotAllowedByConfigurationException )
Throwable cause = getCause();
if ( cause instanceof UpgradeNotAllowedByConfigurationException )
{
log.error( "Neo4j cannot be started, because the database files require upgrading and upgrades are " +
"disabled in configuration. Please set '%s' to 'true' in your configuration file and try again.",
allow_upgrade.name() );
log.error( cause.getMessage() );
}
else
{
Expand Down
Expand Up @@ -50,8 +50,7 @@ public void shouldDescribeUpgradeFailureInAFriendlyWay()
// then
logging.assertExactly( inLog( "console" )
.error( "Neo4j cannot be started, because the database files require upgrading and upgrades are " +
"disabled in configuration. Please set '%s' to 'true' in your configuration file and try " +
"again.", GraphDatabaseSettings.allow_upgrade.name() ) );

"disabled in configuration. Please set '" + GraphDatabaseSettings.allow_upgrade.name() +
"' to 'true' in your configuration file and try " + "again." ) );
}
}

0 comments on commit 1e849a0

Please sign in to comment.