Skip to content

Commit

Permalink
Make it possible to run the ConsistencyCheckTool without having it do…
Browse files Browse the repository at this point in the history
… System.exit(1) on failure
  • Loading branch information
chrisvest committed Jun 1, 2016
1 parent cc371ea commit adb5cd2
Showing 1 changed file with 20 additions and 12 deletions.
Expand Up @@ -52,18 +52,24 @@ public class ConsistencyCheckTool

public static void main( String[] args ) throws IOException
{
ConsistencyCheckTool tool = new ConsistencyCheckTool( new ConsistencyCheckService(),
new DefaultFileSystemAbstraction(), System.err );
try
{
tool.run( args );
runConsistencyCheckTool( args );
}
catch ( ToolFailureException e )
{
e.exitTool();
}
}

public static ConsistencyCheckService.Result runConsistencyCheckTool( String[] args )
throws ToolFailureException, IOException
{
ConsistencyCheckTool tool = new ConsistencyCheckTool( new ConsistencyCheckService(),
new DefaultFileSystemAbstraction(), System.err );
return tool.run( args );
}

private final ConsistencyCheckService consistencyCheckService;
private final PrintStream systemError;
private final FileSystemAbstraction fs;
Expand All @@ -76,7 +82,7 @@ public static void main( String[] args ) throws IOException
this.systemError = systemError;
}

void run( String... args ) throws ToolFailureException, IOException
ConsistencyCheckService.Result run( String... args ) throws ToolFailureException, IOException
{
Args arguments = Args.withFlags( PROP_OWNER, VERBOSE ).parse( args );

Expand All @@ -89,7 +95,7 @@ void run( String... args ) throws ToolFailureException, IOException
LogProvider logProvider = FormattedLogProvider.toOutputStream( System.out );
try
{
consistencyCheckService.runFullConsistencyCheck( storeDir, tuningConfiguration,
return consistencyCheckService.runFullConsistencyCheck( storeDir, tuningConfiguration,
ProgressMonitorFactory.textual( System.err ), logProvider, fs, verbose );
}
catch ( ConsistencyCheckIncompleteException e )
Expand All @@ -103,18 +109,16 @@ private boolean isVerbose( Args arguments )
return arguments.getBoolean( VERBOSE, false, true );
}

private void checkDbState( File storeDir, Config tuningConfiguration )
private void checkDbState( File storeDir, Config tuningConfiguration ) throws ToolFailureException
{
try ( PageCache pageCache = StandalonePageCacheFactory.createPageCache( fs, tuningConfiguration ) )
{
if ( new RecoveryRequiredChecker( fs, pageCache ).isRecoveryRequiredAt( storeDir ) )
{
systemError.print( Strings.joinAsLines(
throw new ToolFailureException( Strings.joinAsLines(
"Active logical log detected, this might be a source of inconsistencies.",
"Please recover database before running the consistency check.",
"To perform recovery please start database and perform clean shutdown." ) );

exit();
}
}
catch ( IOException e )
Expand Down Expand Up @@ -172,7 +176,7 @@ private String usage()
);
}

class ToolFailureException extends Exception
static class ToolFailureException extends Exception
{
ToolFailureException( String message )
{
Expand All @@ -185,14 +189,18 @@ class ToolFailureException extends Exception
}

void exitTool()
{
printMessage();
exit();
}

void printMessage()
{
System.err.println( getMessage() );
if ( getCause() != null )
{
getCause().printStackTrace( System.err );
}

exit();
}
}

Expand Down

0 comments on commit adb5cd2

Please sign in to comment.