Skip to content

Commit

Permalink
Improve ChecksTxLogs to run on a given set of checks from the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Dec 22, 2015
1 parent 58d6d8a commit a7540da
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
29 changes: 27 additions & 2 deletions tools/src/main/java/org/neo4j/tools/txlog/CheckTxLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.neo4j.helpers.Args;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
Expand Down Expand Up @@ -50,6 +52,8 @@
public class CheckTxLogs
{
private static final String HELP_FLAG = "help";
private static final String CHECKS = "checks";
private static final String SEPARATOR = ",";

private final FileSystemAbstraction fs;

Expand All @@ -65,14 +69,15 @@ public static void main( String[] args ) throws Exception
{
printUsageAndExit();
}
CheckType[] checkTypes = parseChecks( arguments );
File dir = parseDir( arguments );

File[] logs = txLogsIn( dir );
System.out.println( "Found " + logs.length + " log files to verify" );

CheckTxLogs tool = new CheckTxLogs( new DefaultFileSystemAbstraction() );

tool.scan( logs, new PrintingInconsistenciesHandler(), CheckTypes.CHECK_TYPES );
tool.scan( logs, new PrintingInconsistenciesHandler(), checkTypes );
}

void scan( File[] logs, InconsistenciesHandler handler, CheckType<?,?>... checkTypes ) throws IOException
Expand Down Expand Up @@ -133,6 +138,19 @@ private <C extends Command, R extends Abstract64BitRecord> void process( C comma
state.put( after, logVersion );
}

private static CheckType[] parseChecks( Args arguments )
{
String checks = arguments.get( CHECKS );
if ( checks == null )
{
return CheckTypes.CHECK_TYPES;
}

return Stream.of( checks.split( SEPARATOR ) )
.map( CheckTypes::fromName )
.toArray( CheckType<?,?>[]::new );
}

private static File parseDir( Args args )
{
if ( args.orphans().size() != 1 )
Expand Down Expand Up @@ -162,7 +180,14 @@ private static File[] txLogsIn( File dir )
private static void printUsageAndExit()
{
System.out.println( "Tool expects single argument - directory with tx logs" );
System.out.println( "Example:\n\t./checkTxLogs <directory containing neostore.transaction.db files>" );
System.out.println( "Usage:" );
System.out.println( "\t./checkTxLogs [options] <directory>" );
System.out.println( "Options:" );
System.out.println( "\t--help\t\tprints this description" );
System.out.println( "\t--checks='checkname[,...]'\t\tthe list of checks to perform. Checks available: " +
Arrays.stream( CheckTypes.CHECK_TYPES )
.map( CheckType::name )
.collect( Collectors.joining( SEPARATOR ) ) );
System.exit( 1 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,18 @@ public class CheckTypes

@SuppressWarnings( "unchecked" )
public static final CheckType<? extends Command, ? extends Abstract64BitRecord>[] CHECK_TYPES =
new CheckType[]{NODE, PROPERTY, RELATIONSHIP};
new CheckType[]{NODE, PROPERTY, RELATIONSHIP, RELATIONSHIP_GROUP};

public static <C extends Command,R extends Abstract64BitRecord> CheckType<C,R> fromName( String name )
{
for ( CheckType<?,?> checkType : CHECK_TYPES )
{
if ( checkType.name().equals( name ) )
{
//noinspection unchecked
return (CheckType<C,R>) checkType;
}
}
throw new IllegalArgumentException( "Unknown check named " + name );
}
}

0 comments on commit a7540da

Please sign in to comment.