Skip to content

Commit

Permalink
Move all index to atomic files.
Browse files Browse the repository at this point in the history
Index ids will for the time being always be an empty set in prepare
store copy request.
  • Loading branch information
RagnarW committed May 3, 2018
1 parent 76bf9e2 commit 4a39caa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Expand Up @@ -25,14 +25,13 @@
import java.util.function.Predicate;
import java.util.stream.Stream;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.NeoStoreDataSource;
import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.transaction.state.NeoStoreFileIndexListing;
import org.neo4j.kernel.impl.transaction.state.NeoStoreFileListing;
import org.neo4j.storageengine.api.StoreFileMetadata;

import static org.neo4j.io.fs.FileUtils.relativePath;
Expand All @@ -51,21 +50,26 @@ public class PrepareStoreCopyFiles implements AutoCloseable
this.fileSystemAbstraction = fileSystemAbstraction;
}

PrimitiveLongSet getIndexIds()
PrimitiveLongSet getNonAtomicIndexIds()
{
NeoStoreFileListing neoStoreFileListing = neoStoreDataSource.getNeoStoreFileListing();
NeoStoreFileIndexListing indexListing = neoStoreFileListing.getNeoStoreFileIndexListing();
return indexListing.getIndexIds();
return Primitive.longSet();
}

StoreResource[] getAtomicFilesSnapshot() throws IOException
{
ResourceIterator<StoreFileMetadata> neoStoreFilesIterator =
closeablesListener.add( neoStoreDataSource.getNeoStoreFileListing().builder().excludeAll().includeNeoStoreFiles().build() );
ResourceIterator<StoreFileMetadata> explicitIndexIterator = closeablesListener.add(
neoStoreDataSource.getNeoStoreFileListing().builder().excludeAll().includeExplicitIndexStoreStoreFiles().includeAdditionalProviders().build() );
ResourceIterator<StoreFileMetadata> indexIterator = closeablesListener.add( neoStoreDataSource
.getNeoStoreFileListing()
.builder()
.excludeAll()
.includeExplicitIndexStoreStoreFiles()
.includeAdditionalProviders()
.includeLabelScanStoreFiles()
.includeSchemaIndexStoreFiles()
.build() );

return Stream.concat( neoStoreFilesIterator.stream().filter( isCountFile() ), explicitIndexIterator.stream() ).map( mapToStoreResource() ).toArray(
return Stream.concat( neoStoreFilesIterator.stream().filter( isCountFile() ), indexIterator.stream() ).map( mapToStoreResource() ).toArray(
StoreResource[]::new );
}

Expand Down
Expand Up @@ -95,7 +95,7 @@ protected void channelRead0( ChannelHandlerContext channelHandlerContext, Prepar

private PrepareStoreCopyResponse createSuccessfulResponse( CheckPointer checkPointer, PrepareStoreCopyFiles prepareStoreCopyFiles ) throws IOException
{
PrimitiveLongSet indexIds = prepareStoreCopyFiles.getIndexIds();
PrimitiveLongSet indexIds = prepareStoreCopyFiles.getNonAtomicIndexIds();
File[] files = prepareStoreCopyFiles.listReplayableFiles();
long lastCommittedTxId = checkPointer.lastCheckPointedTransactionId();
return PrepareStoreCopyResponse.success( files, indexIds, lastCommittedTxId );
Expand Down
Expand Up @@ -58,11 +58,11 @@

import static java.util.stream.Collectors.toList;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.io.fs.FileUtils.relativePath;

Expand Down Expand Up @@ -148,7 +148,7 @@ public void shouldListExpectedFilesCorrectly() throws Exception
assertTransactionIdMatches( prepareStoreCopyResponse.lastTransactionId() );

//and
assertIndexIdsMatch( prepareStoreCopyResponse.getIndexIds(), neoStoreDataSource );
assertIndexIdsAreEmpty( prepareStoreCopyResponse.getIndexIds() );
}

@Test
Expand Down Expand Up @@ -277,10 +277,9 @@ private void listOfDownloadedFilesMatchesServer( NeoStoreDataSource neoStoreData
assertThat( givenFile, containsInAnyOrder( expectedStoreFiles.toArray( new String[givenFile.size()] ) ) );
}

private void assertIndexIdsMatch( PrimitiveLongSet indexIds, NeoStoreDataSource neoStoreDataSource )
private void assertIndexIdsAreEmpty( PrimitiveLongSet indexIds )
{
PrimitiveLongSet expectedIndexIds = getExpectedIndexIds( neoStoreDataSource );
assertThat( expectedIndexIds, equalTo( indexIds ) );
assertTrue( indexIds.isEmpty() );
}

private PrimitiveLongSet getExpectedIndexIds( NeoStoreDataSource neoStoreDataSource )
Expand Down
Expand Up @@ -42,6 +42,7 @@

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -122,21 +123,21 @@ public void shouldReturnExpectedListOfFileNamesForEachType() throws Exception
@Test
public void shouldHandleEmptyDescriptors()
{
PrimitiveLongSet indexIds = prepareStoreCopyFiles.getIndexIds();
PrimitiveLongSet indexIds = prepareStoreCopyFiles.getNonAtomicIndexIds();

assertEquals( 0, indexIds.size() );
}

@Test
public void shouldReturnExpectedDescriptors()
public void shouldReturnEmptySetOfIds()
{
PrimitiveLongSet expectedIndexIds = Primitive.longSet();
expectedIndexIds.add( 42 );
when( indexListingMock.getIndexIds() ).thenReturn( expectedIndexIds );

PrimitiveLongSet actualIndexIndexIds = prepareStoreCopyFiles.getIndexIds();
PrimitiveLongSet actualIndexIndexIds = prepareStoreCopyFiles.getNonAtomicIndexIds();

assertEquals( expectedIndexIds, actualIndexIndexIds );
assertTrue( actualIndexIndexIds.isEmpty() );
}

private String getRelativePath( StoreFileMetadata f )
Expand Down
Expand Up @@ -155,7 +155,7 @@ private void configureProvidedStoreCopyFiles( StoreResource[] atomicFiles, File[
throws IOException
{
when( prepareStoreCopyFiles.getAtomicFilesSnapshot() ).thenReturn( atomicFiles );
when( prepareStoreCopyFiles.getIndexIds() ).thenReturn( indexIds );
when( prepareStoreCopyFiles.getNonAtomicIndexIds() ).thenReturn( indexIds );
when( prepareStoreCopyFiles.listReplayableFiles() ).thenReturn( files );
when( checkPointer.lastCheckPointedTransactionId() ).thenReturn( lastCommitedTx );
}
Expand Down

0 comments on commit 4a39caa

Please sign in to comment.