private void run ( ) throws IOException , RepositoryException { // UUIDs of multiple nodes in the index Set < String > multipleEntries = new HashSet < String > ( ) ; // collect all documents UUIDs documentUUIDs = new HashSet < String > ( ) ; CachingMultiIndexReader reader = index . getIndexReader ( ) ; try { for ( int i = 0 ; i < reader . maxDoc ( ) ; i ++ ) { if ( i > 10 && i % ( reader . maxDoc ( ) / 5 ) == 0 ) { long progress = Math . round ( ( 100.0 * i ) / ( reader . maxDoc ( ) * 2f ) ) ; log . info ( "progress: " + progress + "%" ) ; } if ( reader . isDeleted ( i ) ) { continue ; } final int currentIndex = i ; Document d = reader . document ( currentIndex , FieldSelectors . UUID ) ; String uuid = d . get ( FieldNames . UUID ) ; if ( stateMgr . getItemData ( uuid ) != null ) { if ( ! documentUUIDs . add ( uuid ) ) { multipleEntries . add ( uuid ) ; } } else { errors . add ( new NodeDeleted ( uuid ) ) ; } } } finally { reader . release ( ) ; } // create multiple entries errors for ( Iterator < String > it = multipleEntries . iterator ( ) ; it . hasNext ( ) ; ) { errors . add ( new MultipleEntries ( it . next ( ) ) ) ; } reader = index . getIndexReader ( ) ; try { // run through documents again and check parent for ( int i = 0 ; i < reader . maxDoc ( ) ; i ++ ) { if ( i > 10 && i % ( reader . maxDoc ( ) / 5 ) == 0 ) { long progress = Math . round ( ( 100.0 * i ) / ( reader . maxDoc ( ) * 2f ) ) ; log . info ( "progress: " + ( progress + 50 ) + "%" ) ; } if ( reader . isDeleted ( i ) ) { continue ; } final int currentIndex = i ; Document d = reader . document ( currentIndex , FieldSelectors . UUID_AND_PARENT ) ; String uuid = d . get ( FieldNames . UUID ) ; String parentUUIDString = d . get ( FieldNames . PARENT ) ; if ( parentUUIDString == null || documentUUIDs . contains ( parentUUIDString ) ) { continue ; } // parent is missing //NodeId parentId = new NodeId(parentUUID); if ( stateMgr . getItemData ( parentUUIDString ) != null ) { errors . add ( new MissingAncestor ( uuid , parentUUIDString ) ) ; } else { errors . add ( new UnknownParent ( uuid , parentUUIDString ) ) ; } } } finally { reader . release ( ) ; } }
Runs the consistency check .