Skip to content

Commit

Permalink
Include log entries that outside of any transaction into dump created…
Browse files Browse the repository at this point in the history
… by DumpLogicalLog tool

Dump records that can be outside of any transaction as part of dump produced by logical log tool.
  • Loading branch information
MishaDemianenko committed Mar 28, 2017
1 parent ba9b655 commit 0f7d623
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
Expand Up @@ -49,7 +49,6 @@
import org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel;
import org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel;
import org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge;
import org.neo4j.kernel.impl.transaction.log.TransactionLogEntryCursor;
import org.neo4j.kernel.impl.transaction.log.entry.InvalidLogEntryHandler;
import org.neo4j.kernel.impl.transaction.log.entry.LogEntry;
import org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand;
Expand All @@ -58,6 +57,7 @@
import org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader;
import org.neo4j.storageengine.api.StorageCommand;
import org.neo4j.tools.dump.inconsistency.ReportInconsistencies;
import org.neo4j.tools.dump.log.TransactionLogEntryCursor;

import static java.util.TimeZone.getTimeZone;
import static org.neo4j.helpers.Format.DEFAULT_TIME_ZONE;
Expand Down
Expand Up @@ -5,19 +5,19 @@
* 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.
* 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 General Public License for more details.
* GNU Affero 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/>.
* 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.kernel.impl.transaction.log;
package org.neo4j.tools.dump.log;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -60,7 +60,7 @@ public boolean next() throws IOException
return true;
}
}
return false;
return !transaction.isEmpty();
}

private boolean isBreakPoint( LogEntry entry )
Expand Down
Expand Up @@ -5,33 +5,39 @@
* 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.
* 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 General Public License for more details.
* GNU Affero 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/>.
* 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.kernel.impl.transaction.log;
package org.neo4j.tools.dump.log;

import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

import org.neo4j.kernel.impl.transaction.log.ArrayIOCursor;
import org.neo4j.kernel.impl.transaction.log.entry.LogEntry;

import static junit.framework.TestCase.assertFalse;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.neo4j.kernel.impl.transaction.log.entry.LogEntryByteCodes.CHECK_POINT;
import static org.neo4j.kernel.impl.transaction.log.entry.LogEntryByteCodes.COMMAND;
import static org.neo4j.kernel.impl.transaction.log.entry.LogEntryByteCodes.TX_1P_COMMIT;
import static org.neo4j.kernel.impl.transaction.log.entry.LogEntryByteCodes.TX_START;
Expand All @@ -51,8 +57,7 @@ public void shouldDeliverIntactTransactions() throws IOException
// All transactions

// The cursor
TransactionLogEntryCursor transactionCursor = new TransactionLogEntryCursor( new ArrayIOCursor(
transactionsAsArray( tx1, tx2 ) ) );
TransactionLogEntryCursor transactionCursor = getTransactionLogEntryCursor( tx1, tx2 );

// THEN
// tx1
Expand All @@ -68,7 +73,7 @@ public void shouldDeliverIntactTransactions() throws IOException
}

@Test
public void shouldNotDeliverTransactionsWithoutEnd() throws IOException
public void deliverTransactionsWithoutEnd() throws IOException
{
// GIVEN
// tx 1
Expand All @@ -77,24 +82,34 @@ public void shouldNotDeliverTransactionsWithoutEnd() throws IOException
// tx 2
List<LogEntry> tx2 = makeTransaction( TX_START, COMMAND, COMMAND );

TransactionLogEntryCursor transactionCursor = new TransactionLogEntryCursor( new ArrayIOCursor(
transactionsAsArray( tx1, tx2 ) ) );
TransactionLogEntryCursor transactionCursor = getTransactionLogEntryCursor( tx1, tx2 );

// THEN
assertTrue( transactionCursor.next() );
assertTx( tx1, transactionCursor.get() );

assertFalse( transactionCursor.next() );
assertTrue( transactionCursor.next() );
}

@Test
public void readNonTransactionalEntries() throws IOException
{
List<LogEntry> recordSet1 = makeTransaction( CHECK_POINT, CHECK_POINT, CHECK_POINT );
List<LogEntry> recordSet2 = makeTransaction( CHECK_POINT );
TransactionLogEntryCursor transactionCursor = getTransactionLogEntryCursor( recordSet1, recordSet2 );

assertTrue( transactionCursor.next() );
assertThat( "All 4 checkpoints should be provided.", transactionCursor.get(), arrayWithSize( 4 ) );
}

private TransactionLogEntryCursor getTransactionLogEntryCursor( List<LogEntry>...txEntries )
{
return new TransactionLogEntryCursor( new ArrayIOCursor( transactionsAsArray( txEntries ) ) );
}

private LogEntry[] transactionsAsArray( List<LogEntry>... transactions )
{
List<LogEntry> allTransactions = new ArrayList<>();
for ( List<LogEntry> tx : transactions )
{
allTransactions.addAll( tx );
}
return allTransactions.toArray( new LogEntry[allTransactions.size()] );
return Stream.of( transactions ).flatMap( Collection::stream ).toArray( LogEntry[]::new );
}

private void assertTx( List<LogEntry> expected, LogEntry[] actual )
Expand All @@ -112,7 +127,7 @@ private List<LogEntry> makeTransaction( byte... types )
return transaction;
}

private LogEntry mockedLogEntry( byte type )
private static LogEntry mockedLogEntry( byte type )
{
LogEntry logEntry = mock( LogEntry.class );
when( logEntry.getType() ).thenReturn( type );
Expand Down

0 comments on commit 0f7d623

Please sign in to comment.