From 0f7d6239d0163b3f50b7bc3c2b4e74957809513a Mon Sep 17 00:00:00 2001 From: MishaDemianenko Date: Tue, 28 Mar 2017 14:19:42 +0200 Subject: [PATCH] Include log entries that outside of any transaction into dump created by DumpLogicalLog tool Dump records that can be outside of any transaction as part of dump produced by logical log tool. --- .../org/neo4j/tools/dump/DumpLogicalLog.java | 2 +- .../dump}/log/TransactionLogEntryCursor.java | 16 +++--- .../log/TransactionLogEntryCursorTest.java | 55 ++++++++++++------- 3 files changed, 44 insertions(+), 29 deletions(-) rename {community/kernel/src/main/java/org/neo4j/kernel/impl/transaction => tools/src/main/java/org/neo4j/tools/dump}/log/TransactionLogEntryCursor.java (79%) rename {community/kernel/src/test/java/org/neo4j/kernel/impl/transaction => tools/src/test/java/org/neo4j/tools/dump}/log/TransactionLogEntryCursorTest.java (59%) diff --git a/tools/src/main/java/org/neo4j/tools/dump/DumpLogicalLog.java b/tools/src/main/java/org/neo4j/tools/dump/DumpLogicalLog.java index 479f575571414..664225b9c7fa3 100644 --- a/tools/src/main/java/org/neo4j/tools/dump/DumpLogicalLog.java +++ b/tools/src/main/java/org/neo4j/tools/dump/DumpLogicalLog.java @@ -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; @@ -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; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/log/TransactionLogEntryCursor.java b/tools/src/main/java/org/neo4j/tools/dump/log/TransactionLogEntryCursor.java similarity index 79% rename from community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/log/TransactionLogEntryCursor.java rename to tools/src/main/java/org/neo4j/tools/dump/log/TransactionLogEntryCursor.java index 96fdd4fc39829..79ac2546ec79e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/log/TransactionLogEntryCursor.java +++ b/tools/src/main/java/org/neo4j/tools/dump/log/TransactionLogEntryCursor.java @@ -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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ -package org.neo4j.kernel.impl.transaction.log; +package org.neo4j.tools.dump.log; import java.io.IOException; import java.util.ArrayList; @@ -60,7 +60,7 @@ public boolean next() throws IOException return true; } } - return false; + return !transaction.isEmpty(); } private boolean isBreakPoint( LogEntry entry ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/log/TransactionLogEntryCursorTest.java b/tools/src/test/java/org/neo4j/tools/dump/log/TransactionLogEntryCursorTest.java similarity index 59% rename from community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/log/TransactionLogEntryCursorTest.java rename to tools/src/test/java/org/neo4j/tools/dump/log/TransactionLogEntryCursorTest.java index 181d1341a63f6..18b0ab2d00056 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/log/TransactionLogEntryCursorTest.java +++ b/tools/src/test/java/org/neo4j/tools/dump/log/TransactionLogEntryCursorTest.java @@ -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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ -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; @@ -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 @@ -68,7 +73,7 @@ public void shouldDeliverIntactTransactions() throws IOException } @Test - public void shouldNotDeliverTransactionsWithoutEnd() throws IOException + public void deliverTransactionsWithoutEnd() throws IOException { // GIVEN // tx 1 @@ -77,24 +82,34 @@ public void shouldNotDeliverTransactionsWithoutEnd() throws IOException // tx 2 List 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 recordSet1 = makeTransaction( CHECK_POINT, CHECK_POINT, CHECK_POINT ); + List 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...txEntries ) + { + return new TransactionLogEntryCursor( new ArrayIOCursor( transactionsAsArray( txEntries ) ) ); } private LogEntry[] transactionsAsArray( List... transactions ) { - List allTransactions = new ArrayList<>(); - for ( List 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 expected, LogEntry[] actual ) @@ -112,7 +127,7 @@ private List 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 );