Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2002-2014 "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 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 package recovery;
 
 import java.io.File;
 
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 // TODO These tests need review. Don't work after refactoring
 
 @SuppressWarnings"serial" )
 {
     private static final byte[] NEOKERNL = { 'N''E''O''K''E''R''N''L''\0' };
     private final CountDownLatch afterWrite = new CountDownLatch( 1 ), afterCrash = new CountDownLatch( 1 );
 
     //@Test
     {
         for ( BreakPoint bp :  )
             bp.enable();
         runInThreadnew TwoWriteTransactions() );
         .await();
         startSubprocesses();
         runnew Verification() );
     }
 
     //@Test
     {
         for ( BreakPoint bp :  )
             bp.enable();
         runInThreadnew SingleWriteTransaction() );
         .await();
         startSubprocesses();
         runnew Verification() );
     }
 
     //@Test
     {
         stopSubprocesses();
         startSubprocesses();
         for ( BreakPoint bp :  )
             bp.enable();
         runInThreadnew TwoWriteTransactions() );
         .await();
         startSubprocesses();
         runInThreadnew Crash() );
         .await();
         startSubprocesses();
         runnew Verification() );
     }
 
     static class TwoWriteTransactions implements Task
     {
         @Override
         public void runGraphDatabaseAPI graphdb )
        {
            Node node;
            try(Transaction tx = graphdb.beginTx())
            {
                node = graphdb.createNode();
                tx.success();
            }
            try(Transaction tx = graphdb.beginTx())
            {
                node.setProperty"correct""yes" );
                graphdb.index().forNodes"nodes" ).addnode"name""value" );
                tx.success();
            }
        }
    }
    static class SingleWriteTransaction implements Task
    {
        @Override
        public void runGraphDatabaseAPI graphdb )
        {
            try(Transaction tx = graphdb.beginTx())
            {
                Node node = graphdb.createNode();
                node.setProperty"correct""yes" );
                graphdb.index().forNodes"nodes" ).addnode"name""value" );
                tx.success();
            }
        }
    }
    static class Crash implements Task
    {
        @Override
        public void runGraphDatabaseAPI graphdb )
        {
            throw new AssertionError"Should not reach here - the breakpoint should avoid it" );
        }
    }
    static class Verification implements Task
    {
        @Override
        public void runGraphDatabaseAPI graphdb )
        {
            assertNotNull"No graph database"graphdb );
            Index<Nodeindex = graphdb.index().forNodes"nodes" );
            assertNotNull"No index"index );
            Node node = index.get"name""value" ).getSingle();
            assertNotNull"could not get the node"node );
            assertEquals"yes"node.getProperty"correct" ) );
        }
    }
    private final BreakPoint[] breakpoints = new BreakPoint[] {
            new BreakPointXaResourceHelpImpl.class"commit"Xid.classboolean.class )
            {
                @Override
                protected void callbackDebugInterface debug ) throws KillSubProcess
                {
                    if ( twoPhaseCommitIndebug.thread() ) )
                    {
                        debug.thread().suspendnull );
                        this.disable();
                        .countDown();
                        throw KillSubProcess.withExitCode( -1 );
                    }
                }
                private boolean twoPhaseCommitInDebuggedThread thread )
                {
                    return !Boolean.parseBooleanthread.getLocal( 1, "onePhase" ) );
                }
            }, new BreakPointCrash.class"run"InternalAbstractGraphDatabase.class )
            {
                @Override
                protected void callbackDebugInterface debug ) throws KillSubProcess
                {
                    .countDown();
                    throw KillSubProcess.withExitCode( -1 );
                }
            }, };
    @Override
    protected BreakPoint[] breakpointsint id )
    {
        return ;
    }
    private final Bootstrapper bootstrap = getBootstrapperInstancethis );
    @Override
    protected Bootstrapper bootstrapint id ) throws IOException
    {
        return ;
    }
    private static Bootstrapper getBootstrapperInstanceTestRecoveryIssues test )
    {
        try
        {
            return new Bootstrappertest, 0 )
            {
                @Override
                protected void shutdownGraphDatabaseService graphdbboolean normal )
                {
                    if ( normal ) super.shutdowngraphdbnormal );
                };
            };
        }
        catch ( IOException e )
        {
            throw new RuntimeExceptione );
        }
    }

    
Create a log file that fixes a store that has been subject to this issue. Parameters: [filename] [globalId.time] [globalId.sequence] Example: TestDoubleRecovery tm_tx_log.1 661819753510181175 3826
    public static void mainString... args ) throws Exception
    {
        TxLog log = new TxLognew File(args[0]), new DefaultFileSystemAbstraction(), new Monitors() );
        byte globalId[] = new byte[. + 16];
        System.arraycopy, 0, globalId, 0, . );
        ByteBuffer byteBuf = ByteBuffer.wrapglobalId );
        byteBuf.position. );
        byteBuf.putLong( Long.parseLongargs[1] ) ).putLong( Long.parseLongargs[2] ) );
        log.txStartglobalId );
        log.addBranchglobalId, UTF8.encode"414141" ) );
        log.addBranchglobalId. );
        log.markAsCommittingglobalId. );
        log.force();
        log.close();
    }
New to GrepCode? Check out our FAQ X