Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DumpLogicalLog can dump transactions relevant to cc report
after a consisistency checker has run a report is made, potentially including incosistencies. DumpLogicalLog can be given a --ccfilter which should point to such a report file. DumpLogicalLog will then only include transactions which touches any of the records in the cc report and mark the records it matched with a `<----` arrow to easier navigate.
- Loading branch information
Showing
3 changed files
with
401 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
tools/src/main/java/org/neo4j/tools/dump/InconsistencyReportReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.tools.dump; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.Reader; | ||
|
||
/** | ||
* Reads CC inconsistency reports. Example of entry: | ||
* | ||
* <pre> | ||
* ERROR: The referenced relationship record is not in use. | ||
* Node[3496089,used=true,rel=14833798,prop=13305361,labels=Inline(0x1000000006:[6]),light,secondaryUnitId=-1] | ||
* Inconsistent with: Relationship[14833798,used=false,source=0,target=0,type=0,sPrev=0,sNext=0,tPrev=0,tNext=0,prop=0,secondaryUnitId=-1,!sFirst,!tFirst] | ||
* </pre> | ||
*/ | ||
public class InconsistencyReportReader | ||
{ | ||
private final Inconsistencies inconsistencies; | ||
|
||
public interface Inconsistencies | ||
{ | ||
void node( long id ); | ||
|
||
void relationship( long id ); | ||
|
||
void property( long id ); | ||
|
||
void relationshipGroup( long id ); | ||
|
||
// TODO: incomplete list/arguments, driven by actual need a.t.m. | ||
} | ||
|
||
public InconsistencyReportReader( Inconsistencies inconsistencies ) | ||
{ | ||
this.inconsistencies = inconsistencies; | ||
} | ||
|
||
public void read( File file ) throws IOException | ||
{ | ||
try ( Reader reader = new FileReader( file ) ) | ||
{ | ||
read( reader ); | ||
} | ||
} | ||
|
||
public void read( Reader reader ) throws IOException | ||
{ | ||
int state = 0; // 0:inconsistency description, 1:entity, 2:inconsistent with | ||
BufferedReader bufferedReader = new BufferedReader( reader ); | ||
String line; | ||
while ( (line = bufferedReader.readLine()) != null ) | ||
{ | ||
line = line.trim(); | ||
if ( state == 0 ) | ||
{ | ||
if ( !line.contains( "ERROR" ) && !line.contains( "WARNING" ) ) | ||
{ | ||
break; | ||
} | ||
} | ||
else if ( state == 1 ) | ||
{ | ||
String entityType = entityType( line ); | ||
long id = id( line ); | ||
if ( entityType != null && id != -1 ) | ||
{ | ||
propagate( entityType, id ); | ||
} | ||
} | ||
else if ( state == 1 || state == 2 ) | ||
{ | ||
if ( line.startsWith( "Inconsistent with: " ) ) | ||
{ | ||
line = line.substring( "Inconsistent with: ".length() ); | ||
} | ||
|
||
String entityType = entityType( line ); | ||
long id = id( line ); | ||
if ( entityType != null && id != -1 ) | ||
{ | ||
propagate( entityType, id ); | ||
} | ||
} | ||
state = (state + 1) % 3; | ||
} | ||
} | ||
|
||
private void propagate( String entityType, long id ) | ||
{ | ||
switch ( entityType ) | ||
{ | ||
case "Relationship": | ||
inconsistencies.relationship( id ); | ||
break; | ||
case "Node": | ||
inconsistencies.node( id ); | ||
break; | ||
case "Property": | ||
inconsistencies.property( id ); | ||
break; | ||
case "RelationshipGroup": | ||
inconsistencies.relationshipGroup( id ); | ||
break; | ||
default: | ||
// it's OK, we just haven't implemented support for this yet | ||
} | ||
} | ||
|
||
private long id( String line ) | ||
{ | ||
int bracket = line.indexOf( '[' ); | ||
if ( bracket > -1 ) | ||
{ | ||
int comma = line.indexOf( ',', bracket ); | ||
if ( comma > -1 ) | ||
{ | ||
return Long.parseLong( line.substring( bracket + 1, comma ) ); | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
private String entityType( String line ) | ||
{ | ||
int bracket = line.indexOf( '[' ); | ||
return bracket == -1 ? null : line.substring( 0, bracket ); | ||
} | ||
} |
Oops, something went wrong.